Last updated:
0 purchases
d4 0.1.10
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 and build.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 writing Dockerfile.
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 and build.yaml. In build.yaml, The arguments in ARG statements of Dockerfileshould 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 of Dockerfile 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 in common.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 in common.yaml.
d4 push
Only push container image specified in common.yaml.
d4 develop
build and test processes run.
d4 release
build, test, login and push processes run.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.