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
3 changes: 1 addition & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ html/*
__pycache__

# Compiled Documentation
site/
Makefile
docs/_build
15 changes: 8 additions & 7 deletions Dockerfile-docs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
FROM python:3.5

RUN mkdir /src
WORKDIR /src
ARG uid=1000
ARG gid=1000

COPY requirements.txt /src/requirements.txt
RUN pip install -r requirements.txt
RUN addgroup --gid $gid sphinx \
&& useradd --uid $uid --gid $gid -M sphinx

COPY docs-requirements.txt /src/docs-requirements.txt
RUN pip install -r docs-requirements.txt
WORKDIR /src
COPY requirements.txt docs-requirements.txt ./
RUN pip install -r requirements.txt -r docs-requirements.txt

COPY . /src
USER sphinx
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ build-py3:

.PHONY: build-docs
build-docs:
docker build -t docker-sdk-python-docs -f Dockerfile-docs .
docker build -t docker-sdk-python-docs -f Dockerfile-docs --build-arg uid=$(shell id -u) --build-arg gid=$(shell id -g) .

.PHONY: build-dind-certs
build-dind-certs:
Expand Down Expand Up @@ -77,7 +77,7 @@ flake8: build

.PHONY: docs
docs: build-docs
docker run --rm -it -v `pwd`:/code docker-sdk-python-docs sphinx-build docs ./_build
docker run --rm -it -v `pwd`:/src docker-sdk-python-docs sphinx-build docs docs/_build

.PHONY: shell
shell: build
Expand Down
18 changes: 18 additions & 0 deletions docker/models/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ def name(self):
if self.attrs.get('Name') is not None:
return self.attrs['Name'].lstrip('/')

@property
def image(self):
"""
The image of the container.
"""
image_id = self.attrs['Image']
if image_id is None:
return None
return self.client.images.get(image_id.split(':')[1])

@property
def labels(self):
"""
The labels of a container as dictionary.
"""
result = self.attrs['Config'].get('Labels')
return result or {}

@property
def status(self):
"""
Expand Down
8 changes: 8 additions & 0 deletions docker/models/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ class Image(Model):
def __repr__(self):
return "<%s: '%s'>" % (self.__class__.__name__, "', '".join(self.tags))

@property
def labels(self):
"""
The labels of an image as dictionary.
"""
result = self.attrs['Config'].get('Labels')
return result or {}

@property
def short_id(self):
"""
Expand Down
6 changes: 4 additions & 2 deletions docs/containers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ Container objects

.. autoclass:: Container()

.. py:attribute:: attrs
.. autoattribute:: id
.. autoattribute:: short_id
.. autoattribute:: image
.. autoattribute:: labels
.. autoattribute:: name
.. autoattribute:: short_id
.. autoattribute:: status
.. py:attribute:: attrs

The raw representation of this object from the server.

Expand Down
9 changes: 5 additions & 4 deletions docs/images.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ Image objects

.. autoclass:: Image()

.. autoattribute:: id
.. autoattribute:: short_id
.. autoattribute:: tags
.. py:attribute:: attrs
.. py:attribute:: attrs
.. autoattribute:: id
.. autoattribute:: labels
.. autoattribute:: short_id
.. autoattribute:: tags

The raw representation of this object from the server.

Expand Down
3 changes: 2 additions & 1 deletion tests/unit/fake_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def get_fake_inspect_container(tty=False):
status_code = 200
response = {
'Id': FAKE_CONTAINER_ID,
'Config': {'Privileged': True, 'Tty': tty},
'Config': {'Labels': {'foo': 'bar'}, 'Privileged': True, 'Tty': tty},
'ID': FAKE_CONTAINER_ID,
'Image': 'busybox:latest',
'Name': 'foobar',
Expand All @@ -158,6 +158,7 @@ def get_fake_inspect_image():
'Parent': "27cf784147099545",
'Created': "2013-03-23T22:24:18.818426-07:00",
'Container': FAKE_CONTAINER_ID,
'Config': {'Labels': {'bar': 'foo'}},
'ContainerConfig':
{
"Hostname": "",
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/models_containers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,22 @@ def test_get_archive(self):
container.get_archive('foo')
client.api.get_archive.assert_called_with(FAKE_CONTAINER_ID, 'foo')

def test_image(self):
client = make_fake_client()
container = client.containers.get(FAKE_CONTAINER_ID)
assert container.image.id == FAKE_IMAGE_ID

def test_kill(self):
client = make_fake_client()
container = client.containers.get(FAKE_CONTAINER_ID)
container.kill(signal=5)
client.api.kill.assert_called_with(FAKE_CONTAINER_ID, signal=5)

def test_labels(self):
client = make_fake_client()
container = client.containers.get(FAKE_CONTAINER_ID)
assert container.labels == {'foo': 'bar'}

def test_logs(self):
client = make_fake_client()
container = client.containers.get(FAKE_CONTAINER_ID)
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/models_images_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ def test_get(self):
assert isinstance(image, Image)
assert image.id == FAKE_IMAGE_ID

def test_labels(self):
client = make_fake_client()
image = client.images.get(FAKE_IMAGE_ID)
assert image.labels == {'bar': 'foo'}

def test_list(self):
client = make_fake_client()
images = client.images.list(all=True)
Expand Down