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.yamlimage_name: <your dockerhub username>/httpd:latest registry_server: docker.io -
Describe test code in
tests/config.yamlschemaVersion: '2.0.0' commandTests: - name: "check httpd pkg" command: "rpm" args: - "-qa" expectedOutput: - "httpd-.*" metadataTest: exposedPorts: - "80" cmd: - "httpd" - "-DFOREGROUND" -
Describe mock in
DockerfileFROM docker.io/centos:latest -
Run develop subcommand and confirm test fails
$ d4 develop -
Describe implementation in
DockerfileFROM 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
Dockerfileandbuild.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
Dockerfileandbuild.yaml. Inbuild.yaml, The arguments inARGstatements ofDockerfileshould 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 ofDockerfileis 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.
Metadata
Release files for d4 0.1.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| d4-0.1.10.tar.gz | 10.5 kB | Without provenance | Details for d4-0.1.10.tar.gz |
Release files / d4-0.1.10.tar.gz
| Download URL | d4-0.1.10.tar.gz |
|---|---|
| Size | 10.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2c899bcab60a763915a17765e970956456a34d374e926fbddb4a65ce42965762
|
|
BLAKE2b-256 checksum How to use checksums |
4d389cbad70c1ccfa0156b514dcd03f0b5df9263ff1face3d1902e1558e7ee74
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for d4 0.1.10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.