Skip to content

Commit

Permalink
Use Travis' Docker directly and... (#79)
Browse files Browse the repository at this point in the history
* Use Travis' Docker directly and...

This commit does the following changes:

1.  It removes Docker Compose entirely from the CI
2.  It adds tox to run all the tests more easily on CI and
    locally
3.  The dependencies of the tests are now all located in
    requirements files
4.  All the tests in tests/test_images.py can now be run independently
    from each other

* fixup! Use Travis' Docker directly and...

* fixup! Use Travis' Docker directly and...

* fixup! Use Travis' Docker directly and...

* fixup! Use Travis' Docker directly and...

* fixup! Use Travis' Docker directly and...

* fixup! Use Travis' Docker directly and...

* fixup! Use Travis' Docker directly and...

* fixup! Use Travis' Docker directly and...
  • Loading branch information
cecton authored and asvetlov committed Jul 29, 2017
1 parent c8a172b commit 3671141
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 89 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ venv
.coverage
coverage.xml
docs/_build
.tox
23 changes: 7 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,23 @@ language: python

python:
- "3.5"
- "3.5.2"
- "3.6"

services:
- docker

env:
DOCKER_COMPOSE_VERSION: 1.14.0

install:
- pip install codecov
# NOTE: upgrade Docker to the latest because version 17.03 has a problem
# with the test tests/test_images.py::test_build_from_remote_file:
# 500: 'Unknown instruction: \x00\x00\x00\x00\x00\x00\x00...'
- sudo apt-get update
- sudo apt-get install -o Dpkg::Options::="--force-confold" --force-yes -y docker-ce
- sudo rm /usr/local/bin/docker-compose
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin
- docker-compose build
- pip install flake8
- pip install docutils
- pip install pygments
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
- docker run -d --name registry -p 5000:5000 registry
- pip install -r requirements/ci.txt

script:
- flake8 aiodocker tests
- python setup.py check -rms
- docker-compose run aiodocker
- tox

after_success:
- codecov
22 changes: 0 additions & 22 deletions docker-compose.yml

This file was deleted.

2 changes: 2 additions & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
aiohttp>=2.0
yarl>=0.10
8 changes: 5 additions & 3 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
setuptools==36.2.3
aiohttp==2.2.3
yarl>=0.10
codecov
docutils
tox
tox-travis
pygments
1 change: 1 addition & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-r test.txt
-r ci.txt
-r doc.txt
towncrier==17.4.0
4 changes: 4 additions & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pytest
pytest-cov==2.5.1
pytest-asyncio==0.6.0
flake8==3.3.0
8 changes: 0 additions & 8 deletions run-ci-tests.sh

This file was deleted.

19 changes: 11 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
long_description = open('README.rst').read() + open('CHANGES.rst').read()


with open('./requirements/base.txt') as test_reqs_txt:
requirements = list(iter(test_reqs_txt))


with open('./requirements/test.txt') as test_reqs_txt:
test_requirements = list(iter(test_reqs_txt))


setup(
name="aiodocker",
version=version,
Expand All @@ -42,12 +50,7 @@
'aiodocker',
],
python_requires='>=3.5',
install_requires=[
'setuptools==36.2.0',
'aiohttp==2.2.3',
'yarl>=0.10',
],
extras_require={
'test': ['pytest', 'pytest-asyncio', 'flake8'],
}
install_requires=requirements,
tests_require=test_requirements,
test_suite="tests",
)
70 changes: 38 additions & 32 deletions tests/test_images.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import pytest
import uuid
from io import BytesIO

import pytest
from aiodocker import utils
from aiodocker.exceptions import DockerError


def _random_name():
return "aiodocker-" + uuid.uuid4().hex[:7]


@pytest.mark.asyncio
async def test_build_from_remote_file(docker):
remote = ("https://raw.githubusercontent.com/aio-libs/"
"aiodocker/master/tests/docker/Dockerfile")

tag = "image:1.0"
params = {'tag': tag, 'remote': remote, 'stream': True}
stream = await docker.images.build(**params)

async for output in stream:
if "Successfully tagged image:1.0\n" in output:
break
tag = "{}:1.0".format(_random_name())
params = {'tag': tag, 'remote': remote}
await docker.images.build(**params)

image = await docker.images.get(tag)
assert image
Expand All @@ -26,52 +28,57 @@ async def test_build_from_remote_tar(docker):
remote = ("https://github.com/aio-libs/aiodocker/"
"raw/master/tests/docker/docker_context.tar")

tag = "image_from_tar:1.0"
params = {'tag': tag, 'remote': remote, 'stream': True}
stream = await docker.images.build(**params)

async for output in stream:
if "Successfully tagged image_from_tar:1.0\n" in output:
break
tag = "{}:1.0".format(_random_name())
params = {'tag': tag, 'remote': remote}
await docker.images.build(**params)

image = await docker.images.get(tag)
assert image


@pytest.mark.asyncio
async def test_history(docker):
name = "image:1.0"
name = "busybox:latest"
await docker.images.pull(from_image=name)
history = await docker.images.history(name=name)
assert history


@pytest.mark.asyncio
async def test_list_images(docker):
images = await docker.images.list()
assert images
name = "busybox:latest"
await docker.images.pull(from_image=name)
images = await docker.images.list(filter=name)
assert len(images) == 1


@pytest.mark.asyncio
async def test_tag_image(docker):
repository = "registry:5000/image"
name = "image:1.0"
name = "busybox:latest"
repository = _random_name()
await docker.images.pull(from_image=name)
await docker.images.tag(name=name, repo=repository, tag="1.0")
await docker.images.tag(name=name, repo=repository, tag="2.0")
image = await docker.images.get(name)
assert len(image['RepoTags']) == 3
assert len([x for x in image['RepoTags'] if x.startswith(repository)]) == 2


@pytest.mark.asyncio
async def test_push_image(docker):
name = "registry:5000/image"
await docker.images.push(name=name)
name = "busybox:latest"
await docker.images.pull(from_image=name)
repository = "localhost:5000/image"
await docker.images.tag(name=name, repo=repository)
await docker.images.push(name=repository)


@pytest.mark.asyncio
async def test_delete_image(docker):
name = "busybox:latest"
await docker.images.pull(from_image=name)
images = await docker.images.list()
origin_count = len(images)
image = await docker.images.get("image:1.0")
image = await docker.images.get(name)
tags = image['RepoTags']
for tag in tags:
await docker.images.delete(name=tag)
Expand All @@ -80,24 +87,24 @@ async def test_delete_image(docker):


@pytest.mark.asyncio
async def test_deleted_image(docker):
name = "registry:5000/image:1.0"
async def test_not_existing_image(docker):
name = "{}:latest".format(_random_name())
with pytest.raises(DockerError) as excinfo:
await docker.images.get(name=name)
assert 'no such image:' in str(excinfo.value)
assert excinfo.value.status == 404


@pytest.mark.asyncio
async def test_pull_image(docker):
name = "registry:5000/image"
name = "busybox:latest"
await docker.images.pull(from_image=name)
name = "registry:5000/image:1.0"
image = await docker.images.get(name=name)
assert image


@pytest.mark.asyncio
async def test_build_from_tar(docker):
name = "{}:latest".format(_random_name())
dockerfile = '''
# Shared Volume
FROM busybox:buildroot-2014.02
Expand All @@ -106,8 +113,7 @@ async def test_build_from_tar(docker):
'''
f = BytesIO(dockerfile.encode('utf-8'))
tar_obj = utils.mktar_from_dockerfile(f)
await docker.images.build(fileobj=tar_obj, encoding="gzip",
tag="fromtar/image:1.0")
await docker.images.build(fileobj=tar_obj, encoding="gzip", tag=name)
tar_obj.close()
image = await docker.images.get(name="fromtar/image:1.0")
image = await docker.images.get(name=name)
assert image
20 changes: 20 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[tox]
envlist = py35, py36, flake8
skipsdist=True

[travis]
python =
3.5: py35, flake8
3.6: py36, flake8

[testenv]
passenv=DOCKER_HOST
usedevelop=True
commands =
py.test --cov=aiodocker {posargs:tests}
deps =
-r{toxinidir}/requirements/test.txt

[testenv:flake8]
commands = flake8 aiodocker tests setup.py
deps = flake8

0 comments on commit 3671141

Please sign in to comment.