Dock to Develop Dynamic Dockerfile
Project description
D4: Dock to Develop Dynamic Dockerfile
abstract
D4 is the tool to develop generic Dockerfile. D4 will provide the easier method to build container image from Dockerfile and test the Dockerfile. By this method, you can realize TDD(Test Driven Development) of Dockerfile easily.
requirements
D4 requires the following software.
- docker
- container-structure-test
- python 3.4+
- python packages
- docker
- pyyaml
install
$ pip install d4
quick start
-
Create project
httpd
$ d4 init httpd $ cd httpd
-
Describe image name and registry server in
common.yaml
image_name: <your dockerhub username>/httpd:latest registry_server: docker.io
-
Describe test code in
tests/config.yaml
schemaVersion: '2.0.0' commandTests: - name: "check httpd pkg" command: "rpm" args: - "-qa" expectedOutput: - "httpd-.*" metadataTest: exposedPorts: - "80" cmd: - "httpd" - "-DFOREGROUND"
-
Describe mock in
Dockerfile
FROM docker.io/centos:latest
-
Run develop subcommand and confirm test fails
$ d4 develop
-
Describe implementation in
Dockerfile
FROM docker.io/centos:latest RUN yum install -y httpd EXPOSE 80 CMD ["httpd", "-DFOREGROUND"]
-
Run develop subcommand and confirm test succeeds
$ d4 develop
-
Release image to your repository of dockerhub
$ d4 release -u <your dockerhub username> -p <your dockerhub password>
usage
project directory architecture
d4 project need to have the following directory architecture;
(project name)
|-- Dockerfile
|-- build.yaml
|-- common.yaml
`-- tests
|-- config_1.yaml
|-- ...
`-- config_N.yaml
-
Dockerfile
The Dockerfile which belongs to the project. For this Dockerfile, container image will be built and test will be executed. -
build.yaml
The yaml file which has arguments to be used by building image. All arguments of the Dockerfile should be described in this file. for example;args: ARG_1: "VALUE_1" ARG_2: "VALUE_2" ARG_3: "VALUE_3"
-
common.yaml
The yaml file which has parameters to be used by both building image and testing image. for example;image_name: bbrfkr0129/httpd:latest registry_server: docker.io
-
tests/<yaml config file>
The yaml files which has tests to be used by testing image. These tests in the yaml files need to be written as container-structure-test can be processed.
TDD method with D4
-
Create project with subcommand
init
. By this subcommand, basis directory architecture and sample files are created.$ d4 init tdd_project $ cd tdd_project $ tree . --charset=C . |-- Dockerfile |-- build.yaml |-- common.yaml `-- tests `-- config.yaml
-
Specify developed image name and registry server pushed developed image in
common.yaml
;$ cat <<EOF > common.yaml image_name: <your dockerhub username>/tdd_image:latest registry_server: docker.io EOF
-
Write mock in
Dockerfile
andbuild.yaml
. Implementation is not done yet.$ cat <<EOF > Dockerfile FROM <base image name>:<tag> EOF $ cat <<EOF > build.yaml args: EOF
-
Write test code according to the syntax of container-structure-test in
tests/config.yaml
. In TDD, test code is written before writingDockerfile
. -
Execute test with subcommand
develop
. By this subcommand, mock container image is built and tested. Then tests should be failed.$ d4 develop
-
Write implementation of
Dockerfile
andbuild.yaml
. Inbuild.yaml
, The arguments inARG
statements ofDockerfile
should be written;args: ARG_1: "VALUE_1" ARG_2: "VALUE_2" ARG_3: "VALUE_3"
-
Execute build and test with subcommand
develop
. By this subcommand, implementation ofDockerfile
is applied, and then generated container image is tested. All tests should be passed.$ d4 develop
-
Repeat procedures 4.-7.. until required container image is got.
-
Release got container image to registry server with subcommand
release
. By this subcommand, final build and test will be processed, then pushed to registry server specified incommon.yaml
.$ d4 release
-
Run container from pushed container image!
$ docker run <your dockerhub username>/tdd_image:latest
valid subcommands
-
d4 init
Create and initialize project. -
d4 build
Only build process runs. -
d4 test
Only test process runs. -
d4 login
Only login into registry server specified incommon.yaml
. -
d4 push
Only push container image specified incommon.yaml
. -
d4 develop
build and test processes run. -
d4 release
build, test, login and push processes run.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file d4-0.1.10.tar.gz
.
File metadata
- Download URL: d4-0.1.10.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c899bcab60a763915a17765e970956456a34d374e926fbddb4a65ce42965762 |
|
MD5 | 30d0989514717566e33220469613391d |
|
BLAKE2b-256 | 4d389cbad70c1ccfa0156b514dcd03f0b5df9263ff1face3d1902e1558e7ee74 |