dimorinny / dockerfile-testing

Test your docker files in docker container

Home Page:https://hub.docker.com/r/dimorinny/testinfra/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dockerfile testing

This repo was created to explain how to use this image to test an environment of your dockerfiles.

It may be useful if you use continuous integration for docker containers and want to be sure that your images work properly.

Why is it better to do it in docker container?

Perhaps you are going to use this method with some CI servers such as TeamCity or Travis CI. And you don't want to install required dependencies on build agents.

How does it work?

To test the environment of docker container testinfra is used, which allows you to check infrastructure environment on both local and remote hosts. To build docker images and running containers the pytest built-in fixture mechanism is used. For every package docker client from testinfra container builds an image from package’s Dockerfile and runs container. After that, user’s tests from this package runs.

Usage

To test your Dockerfiles you should create Python package with both Dockerfiles and your tests for every image that you have (see check commands and file examples). Then, you should run this container with your tests and docker.sock as volumes (-v option). For example:

docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd)/sample/:/test dimorinny/testinfra

Sample output:

============================= test session starts ==============================
platform linux -- Python 3.6.0b2, pytest-3.0.3, py-1.4.31, pluggy-0.4.0 -- /usr/local/bin/python3.6
cachedir: .cache
rootdir: /test, inifile:
plugins: testinfra-1.4.2
collecting ... collected 4 items

commands/test_image.py::TestAlpainEnvironmentTest::test_curl_exists[commands] PASSED
commands/test_image.py::TestAlpainEnvironmentTest::test_docker_exists[commands] PASSED
copy/test_image.py::TestAlpainEnvironmentTest::test_copied_file_exists[copy/docker] PASSED
copy/test_image.py::TestAlpainEnvironmentTest::test_copied_file_content[copy/docker] PASSED
=========================== 4 passed in 0.88 seconds ===========================

For sample, how to use it with CI, look it this repo, that use Travis CI for testing image environment.

About

Test your docker files in docker container

https://hub.docker.com/r/dimorinny/testinfra/


Languages

Language:Python 82.6%Language:Dockerfile 17.4%