Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ RUN set -ex; \
; \
rm -rf /var/lib/apt/lists/*

ENV ALL_DOCKER_VERSIONS 1.3.3 1.4.1 1.5.0

RUN set -ex; \
for v in ${ALL_DOCKER_VERSIONS}; do \
curl https://get.docker.com/builds/Linux/x86_64/docker-$v -o /usr/local/bin/docker-$v; \
chmod +x /usr/local/bin/docker-$v; \
done
# ENV ALL_DOCKER_VERSIONS 1.6.0

# RUN set -ex; \
# for v in ${ALL_DOCKER_VERSIONS}; do \
# curl https://get.docker.com/builds/Linux/x86_64/docker-$v -o /usr/local/bin/docker-$v; \
# chmod +x /usr/local/bin/docker-$v; \
# done

# Temporarily use dev version of Docker
ENV ALL_DOCKER_VERSIONS dev
ADD ./docker-dev /usr/local/bin/docker-dev
RUN chmod +x /usr/local/bin/docker-dev

RUN useradd -d /home/user -m -s /bin/bash user
WORKDIR /code/
Expand Down
2 changes: 1 addition & 1 deletion compose/cli/docker_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ def docker_client():
)

timeout = int(os.environ.get('DOCKER_CLIENT_TIMEOUT', 60))
return Client(base_url=base_url, tls=tls_config, version='1.15', timeout=timeout)
return Client(base_url=base_url, tls=tls_config, version='1.18', timeout=timeout)
27 changes: 27 additions & 0 deletions compose/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'environment',
'hostname',
'image',
'labels',
'links',
'mem_limit',
'net',
Expand Down Expand Up @@ -171,6 +172,9 @@ def process_container_options(service_dict, working_dir=None):
if 'volumes' in service_dict:
service_dict['volumes'] = resolve_host_paths(service_dict['volumes'], working_dir=working_dir)

if 'labels' in service_dict:
service_dict['labels'] = parse_labels(service_dict['labels'])

return service_dict


Expand Down Expand Up @@ -332,6 +336,29 @@ def volumes_from_dict(d):
return ["%s:%s" % (host_path, container_path) for (container_path, host_path) in d.items()]


def parse_labels(labels):
if not labels:
return {}

if isinstance(labels, list):
return dict(split_label(e) for e in labels)

if isinstance(labels, dict):
return labels

raise ConfigurationError(
"labels \"%s\" must be a list or mapping" %
labels
)


def split_label(label):
if '=' in label:
return label.split('=', 1)
else:
return label, ''


def expand_path(working_dir, path):
return os.path.abspath(os.path.join(working_dir, path))

Expand Down
Binary file added docker-dev
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Compose with a `curl` command.

### Install Docker

First, install Docker version 1.3 or greater:
First, install Docker version 1.6 or greater:

- [Instructions for Mac OS X](http://docs.docker.com/installation/mac/)
- [Instructions for Ubuntu](http://docs.docker.com/installation/ubuntulinux/)
Expand Down
18 changes: 18 additions & 0 deletions docs/yml.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,24 @@ db:
> configuration options are **not** inherited - you will have to define
> those manually each time you extend it.

### labels

Add metadata to containers using [Docker labels](http://docs.docker.com/userguide/labels-custom-metadata/). You can use either an array or a dictionary.

It's recommended that you use reverse-DNS notation to prevent your labels from conflicting with those used by other software.

```
labels:
com.example.description: "Accounting webapp"
com.example.department: "Finance"
com.example.label-with-empty-value: ""

labels:
- "com.example.description=Accounting webapp"
- "com.example.department=Finance"
- "com.example.label-with-empty-value"
```

### net

Networking mode. Use the same values as the docker client `--net` parameter.
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PyYAML==3.10
docker-py==1.1.0
-e git+https://github.com/docker/docker-py.git@70ce156e26d283d181e6ec10bd1309ddc1da1bbd#egg=docker-py
dockerpty==0.3.2
docopt==0.6.1
requests==2.5.3
Expand Down
4 changes: 2 additions & 2 deletions script/test-versions
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ script/validate-dco
flake8 compose

if [ "$DOCKER_VERSIONS" == "" ]; then
DOCKER_VERSIONS="1.5.0"
DOCKER_VERSIONS="dev"
elif [ "$DOCKER_VERSIONS" == "all" ]; then
DOCKER_VERSIONS="$ALL_DOCKER_VERSIONS"
fi

for version in $DOCKER_VERSIONS; do
>&2 echo "Running tests against Docker $version"
docker-1.5.0 run \
docker-$version run \
--rm \
--privileged \
--volume="/var/lib/docker" \
Expand Down
27 changes: 27 additions & 0 deletions tests/integration/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,30 @@ def test_resolve_env(self):
env = create_and_start_container(service).environment
for k,v in {'FILE_DEF': 'F1', 'FILE_DEF_EMPTY': '', 'ENV_DEF': 'E3', 'NO_DEF': ''}.items():
self.assertEqual(env[k], v)

def test_labels(self):
labels_dict = {
'com.example.description': "Accounting webapp",
'com.example.department': "Finance",
'com.example.label-with-empty-value': "",
}

service = self.create_service('web', labels=labels_dict)
labels = create_and_start_container(service).get('Config.Labels').items()
for pair in labels_dict.items():
self.assertIn(pair, labels)

labels_list = ["%s=%s" % pair for pair in labels_dict.items()]

service = self.create_service('web', labels=labels_list)
labels = create_and_start_container(service).get('Config.Labels').items()
for pair in labels_dict.items():
self.assertIn(pair, labels)

def test_empty_labels(self):
labels_list = ['foo', 'bar']

service = self.create_service('web', labels=labels_list)
labels = create_and_start_container(service).get('Config.Labels').items()
for name in labels_list:
self.assertIn((name, ''), labels)