4 releases

0.2.1 Dec 10, 2018
0.2.0 Dec 9, 2018
0.1.1 Dec 9, 2018
0.1.0 Dec 9, 2018

#1202 in Development tools

Download history 954/week @ 2023-12-18 983/week @ 2023-12-25 932/week @ 2024-01-01 954/week @ 2024-01-08 999/week @ 2024-01-15 1026/week @ 2024-01-22 1597/week @ 2024-01-29 1183/week @ 2024-02-05 1201/week @ 2024-02-12 1118/week @ 2024-02-19 1084/week @ 2024-02-26 1001/week @ 2024-03-04 874/week @ 2024-03-11 993/week @ 2024-03-18 876/week @ 2024-03-25 1045/week @ 2024-04-01

3,926 downloads per month
Used in pwnenv

Apache-2.0

31KB
688 lines

dockerfile

Build Status Crates.io docs.rs License Crates.io Crates.io

A Rust library for dynamically generating Dockerfiles.

The use case this crate was originally built for was to build Docker images from a worker service running in Kubernetes for client workloads. This is definitely not the only pattern that is supported. The generated Dockerfiles could be persisted somewhere or discarded immediately after use. The containers generated are standard containers, built according to the Dockerfiles you generated.

All of the Dockerfile instructions are supported in raw form as of 2018.12.09. There is an issue open to add more structured and type-safe interfaces for the instructions which need it.

get started

First you will need to add this to your Cargo.toml dependencies.

dockerfile = "0.2"

Now you can start building Dockerfiles.

use dockerfile::{
    Dockerfile,
    Arg,
    Copy,
    Cmd,
};

fn main() {
    // Build up a new Dockerfile.
    let dockerfile = Dockerfile::base("rust:${RUST_VERSION}-slim")
        .push_initial_arg(Arg::new("RUST_VERSION=1.31"))
        .push(Copy::new("/static ./static"))
        .push(Cmd::new("echo 'Hello. Goodbye.'"))
        .finish();

    // Write it out as a string.
    let output = dockerfile.to_string();
    assert_eq!(output,
r##"ARG RUST_VERSION=1.31
FROM rust:${RUST_VERSION}-slim
COPY /static ./static
CMD echo 'Hello. Goodbye.'
"##)
}

development

I would like to have this crate offer a type-safe interface for constructing the various Dockerfile instructions. This will help reduce bugs which could only be found once you actually attempt to invoke the docker build. I would like to experiment with adding constructors for the various forms of instructions; EG, offer a constructor for CMD which takes an impl Iterator<Item=AsRef<str>> for building the form CMD ["arg0", "arg1"] &c.

No runtime deps

Features