#dockerfile #json-format #yaml #generator #json #docker-build #generate-json

bin+lib dofigen

A Dockerfile generator using a simplified description in YAML or JSON format create

30 releases (10 stable)

new 2.1.1-beta.1 Nov 6, 2024
2.1.0-rc.2 Sep 25, 2024
2.0.0-beta.6 Jul 10, 2024
1.4.1 Jun 24, 2024
0.0.0 Sep 14, 2022

#157 in Development tools

Download history 1/week @ 2024-07-18 95/week @ 2024-07-25 26/week @ 2024-08-01 105/week @ 2024-08-15 92/week @ 2024-08-22 430/week @ 2024-08-29 241/week @ 2024-09-05 141/week @ 2024-09-12 214/week @ 2024-09-19 305/week @ 2024-09-26 107/week @ 2024-10-03 22/week @ 2024-10-10 3/week @ 2024-10-17 52/week @ 2024-10-31

89 downloads per month
Used in lenra_cli

MIT license

265KB
6.5K SLoC

Contributors Forks Stargazers Issues MIT License Crates.io

Dofigen logo

Dofigen

Dofigen is a Dockerfile generator using a simplified description in YAML or JSON format. It defines default values and behaviors that simplify the creation of Dockerfiles.

Dofigen is also made to use the Buildkit optimizations that speed-up the Docker image build by parallelizing the layer builds. It uses the --link option when adding files and the --mount=type=cache option when running scripts (when you define caches attribute). You can use Buildkit with the docker buildx build subcommand like this:

docker buildx build --cache-to=type=local,dest=.dockercache --cache-from=type=local,src=.dockercache -t my-app:latest --load .

A french DevOps said about it:

C'est une bouffée, Dofigen, dans ce monde de con...teneurs.

Report Bug · Request Feature

Getting Started

Prerequisites

Install Dofigen using one of the following options.

Cargo install

First install Cargo, the Rust package manager: https://doc.rust-lang.org/cargo/getting-started/installation.html

Then use the following command to install dofigen:

cargo install dofigen

Download the binary

You can download the Dofigen binary from the release page and add it to your path environment variable.

Use it with Docker

You can run Dofigen directly from its Docker image with the following command:

docker run --rm -it -v $(pwd):/app lenra/dofigen

(back to top)

How to use it

To generate a Dockerfile, you need to create a Dofigen file dofigen.yml and run the next command:

dofigen gen

Use the help options to understand how to override default behaviors:

$ dofigen gen --help
Generate the Dockerfile and .dockerignore files

Usage: dofigen generate [OPTIONS]

Options:
  -f, --file <FILE>      The input Dofigen file. Default search for the next files: dofigen.yml, dofigen.yaml, dofigen.json Use "-" to read from stdin
      --offline          The command won't load data from any URL. This disables extending file from URL and loading image tag
  -o, --output <OUTPUT>  The output Dockerfile file Define to - to write to stdout [default: Dockerfile]
  -l, --locked           Locked version of the dofigen definition
  -h, --help             Print help

To look further use the help command:

dofigen --help

Dofigen descriptor

The structure of the Dofigen descriptor was created to be simpler than the Dockerfile.

The JSON Schema of the Dofigen descriptor is available here.

Here is an example to generate the Dofigen Dockerfile:

builders:
  muslrust:
    fromImage: clux/muslrust:stable
    workdir: /app
    bind:
      - Cargo.toml
      - Cargo.lock
      - src/
    run:
      # Build with musl to work with scratch
      - cargo build --release
      # copy the generated binary outside of the target directory. If not the other stages won't be able to find it since it's in a cache volume
      - mv target/x86_64-unknown-linux-musl/release/dofigen /tmp/
    cache:
      # Cargo cache
      - /home/rust/.cargo
      # build cache
      - /app/target

# Runtime
workdir: /app
copy:
  - fromBuilder: muslrust
    paths: "/tmp/dofigen"
    target: "/bin/"
entrypoint: dofigen
cmd: --help
context:
  - "/src"
  - "/Cargo.*"

Extending external files

You can extend the Dofigen file with external files using the extend attribute. You can find some Dofigen templates on the Dofigen Hub repository. Here is an example of extending a Dofigen file:

extend:
  - https://raw.githubusercontent.com/lenra-io/dofigen/main/dofigen.yml

You can also override or merge the structure of the extended files:

extend:
  - https://raw.githubusercontent.com/lenra-io/dofigen/main/dofigen.yml
user: 1001

The lock file

Dofigen generates a lock file to keep the version of the Dofigen descriptor used to generate the Dockerfile. The lock file also keep the loaded resources and images tags to rebuild the Dockerfile with the same versions. To update the images and resources, you can use the dofigen update command. To regenerate the Dockerfile with the same versions, you can use the dofigen gen --locked command.

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please open an issue with the tag "enhancement" or "bug". Don't forget to give the project a star! Thanks again!

Tests

To run the tests, use the following command:

cargo test --all-features

Generate the JSON Schema

To generate the JSON schema of the Dofigen file structure, use the following command:

cargo run -F json_schema -- schema

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Contact

Lenra - @lenra_dev - contact@lenra.io

Project Link: https://github.com/lenra-io/dofigen

(back to top)

Dependencies

~9–27MB
~368K SLoC