Skip to content
Closed
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
23 changes: 14 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
sudo: false
language: python
cache: pip
python:
- "3.5"
env:
- TOX_ENV=py27
- TOX_ENV=py33
- TOX_ENV=py34
- TOX_ENV=py35
- TOX_ENV=flake8
- 2.7
- 3.3
- 3.4
- 3.5
- 3.6
- pypy
- pypy3
matrix:
allow_failures:
- python: pypy
- python: pypy3
install:
- pip install tox
- travis_retry pip install tox-travis
script:
- tox -e $TOX_ENV
- tox
14 changes: 14 additions & 0 deletions Dockerfile-pypy
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM pypy:2
MAINTAINER Joffrey F <joffrey@docker.com>

RUN mkdir /home/docker-py
WORKDIR /home/docker-py

ADD requirements.txt /home/docker-py/requirements.txt
RUN pip install -r requirements.txt

ADD test-requirements.txt /home/docker-py/test-requirements.txt
RUN pip install -r test-requirements.txt

ADD . /home/docker-py
RUN pip install .
14 changes: 14 additions & 0 deletions Dockerfile-pypy3
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM pypy:3
MAINTAINER Joffrey F <joffrey@docker.com>

RUN mkdir /home/docker-py
WORKDIR /home/docker-py

ADD requirements.txt /home/docker-py/requirements.txt
RUN pip install -r requirements.txt

ADD test-requirements.txt /home/docker-py/test-requirements.txt
RUN pip install -r test-requirements.txt

ADD . /home/docker-py
RUN pip install .
26 changes: 25 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ build:
build-py3:
docker build -t docker-sdk-python3 -f Dockerfile-py3 .

.PHONY: build-pypy
build-pypy:
docker build -t docker-sdk-pypy -f Dockerfile-pypy .

.PHONY: build-pypy3
build-pypy3:
docker build -t docker-sdk-pypy3 -f Dockerfile-pypy3 .

.PHONY: build-docs
build-docs:
docker build -t docker-sdk-python-docs -f Dockerfile-docs .
Expand All @@ -23,7 +31,7 @@ build-dind-certs:
docker build -t dpy-dind-certs -f tests/Dockerfile-dind-certs .

.PHONY: test
test: flake8 unit-test unit-test-py3 integration-dind integration-dind-ssl
test: flake8 unit-test unit-test-py3 unit-test-pypy unit-test-pypy3 integration-dind integration-dind-ssl

.PHONY: unit-test
unit-test: build
Expand All @@ -33,6 +41,14 @@ unit-test: build
unit-test-py3: build-py3
docker run --rm docker-sdk-python3 py.test tests/unit

.PHONY: unit-test-pypy
unit-test-pypy: build-pypy
docker run docker-sdk-pypy py.test tests/unit

.PHONY: unit-test-pypy3
unit-test-pypy3: build-pypy3
docker run docker-sdk-pypy3 py.test tests/unit

.PHONY: integration-test
integration-test: build
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock docker-sdk-python py.test tests/integration/${file}
Expand All @@ -41,6 +57,14 @@ integration-test: build
integration-test-py3: build-py3
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock docker-sdk-python3 py.test tests/integration/${file}

.PHONY: integration-test-pypy
integration-test-pypy: build-pypy
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock docker-sdk-pypy py.test tests/integration/${file}

.PHONY: integration-test-pypy3
integration-test-pypy3: build-pypy3
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock docker-sdk-pypy3 py.test tests/integration/${file}

.PHONY: integration-dind
integration-dind: build build-py3
docker rm -vf dpy-dind || :
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![Build Status](https://travis-ci.org/docker/docker-py.svg?branch=master)](https://travis-ci.org/docker/docker-py)

A Python library for the Docker Engine API. It lets you do anything the `docker` command does, but from within Python apps – run containers, manage containers, manage Swarms, etc.
It supports Python 2 and Python 3 implemented by CPython and PyPy.

## Installation

Expand Down
2 changes: 2 additions & 0 deletions docker/utils/ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def split_port(port):

if len(parts) == 1:
internal_port, = parts
if not internal_port:
_raise_invalid_port(port)
return to_port_range(internal_port), None
if len(parts) == 2:
external_port, internal_port = parts
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Utilities',
'License :: OSI Approved :: Apache Software License',
],
Expand Down
44 changes: 1 addition & 43 deletions tests/integration/api_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import docker
from docker.utils import kwargs_from_env

from .base import BaseAPIIntegrationTest, BUSYBOX
from .base import BaseAPIIntegrationTest


class InformationTest(BaseAPIIntegrationTest):
Expand All @@ -25,48 +25,6 @@ def test_info(self):
self.assertIn('Debug', res)


class LinkTest(BaseAPIIntegrationTest):
def test_remove_link(self):
# Create containers
container1 = self.client.create_container(
BUSYBOX, 'cat', detach=True, stdin_open=True
)
container1_id = container1['Id']
self.tmp_containers.append(container1_id)
self.client.start(container1_id)

# Create Link
# we don't want the first /
link_path = self.client.inspect_container(container1_id)['Name'][1:]
link_alias = 'mylink'

container2 = self.client.create_container(
BUSYBOX, 'cat', host_config=self.client.create_host_config(
links={link_path: link_alias}
)
)
container2_id = container2['Id']
self.tmp_containers.append(container2_id)
self.client.start(container2_id)

# Remove link
linked_name = self.client.inspect_container(container2_id)['Name'][1:]
link_name = '%s/%s' % (linked_name, link_alias)
self.client.remove_container(link_name, link=True)

# Link is gone
containers = self.client.containers(all=True)
retrieved = [x for x in containers if link_name in x['Names']]
self.assertEqual(len(retrieved), 0)

# Containers are still there
retrieved = [
x for x in containers if x['Id'].startswith(container1_id) or
x['Id'].startswith(container2_id)
]
self.assertEqual(len(retrieved), 2)


class LoadConfigTest(BaseAPIIntegrationTest):
def test_load_legacy_config(self):
folder = tempfile.mkdtemp()
Expand Down
42 changes: 42 additions & 0 deletions tests/integration/api_container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,3 +1253,45 @@ def test_container_cpuset(self):
self.client.start(container)
inspect_data = self.client.inspect_container(container)
self.assertEqual(inspect_data['HostConfig']['CpusetCpus'], cpuset_cpus)


class LinkTest(BaseAPIIntegrationTest):
def test_remove_link(self):
# Create containers
container1 = self.client.create_container(
BUSYBOX, 'cat', detach=True, stdin_open=True
)
container1_id = container1['Id']
self.tmp_containers.append(container1_id)
self.client.start(container1_id)

# Create Link
# we don't want the first /
link_path = self.client.inspect_container(container1_id)['Name'][1:]
link_alias = 'mylink'

container2 = self.client.create_container(
BUSYBOX, 'cat', host_config=self.client.create_host_config(
links={link_path: link_alias}
)
)
container2_id = container2['Id']
self.tmp_containers.append(container2_id)
self.client.start(container2_id)

# Remove link
linked_name = self.client.inspect_container(container2_id)['Name'][1:]
link_name = '%s/%s' % (linked_name, link_alias)
self.client.remove_container(link_name, link=True)

# Link is gone
containers = self.client.containers(all=True)
retrieved = [x for x in containers if link_name in x['Names']]
self.assertEqual(len(retrieved), 0)

# Containers are still there
retrieved = [
x for x in containers if x['Id'].startswith(container1_id) or
x['Id'].startswith(container2_id)
]
self.assertEqual(len(retrieved), 2)
3 changes: 3 additions & 0 deletions tests/unit/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,9 @@ def test_with_no_container_port(self):
self.assertRaises(ValueError,
lambda: split_port("localhost:80:"))

def test_split_port_empty_string(self):
self.assertRaises(ValueError, lambda: split_port(""))

def test_build_port_bindings_with_one_port(self):
port_bindings = build_port_bindings(["127.0.0.1:1000:1000"])
self.assertEqual(port_bindings["1000"], [("127.0.0.1", "1000")])
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[tox]
envlist = py27, py33, py34, py35, flake8
skipsdist=True
envlist = py27, py33, py34, py35, py36, pypy, pypy3, flake8
skipsdist = True

[testenv]
usedevelop=True
usedevelop = True
commands =
py.test --cov=docker {posargs:tests/unit}
deps =
Expand Down