From b5a1dd4326855a63701ac2720c67f749160d9584 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 7 Apr 2024 16:20:04 +0100 Subject: [PATCH] build(docker): add Dockerfile and builder --- Dockerfile | 33 +++++++++++++++++++++++++++++++++ Dockerfile.builder | 23 +++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 Dockerfile create mode 100644 Dockerfile.builder diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..121f06c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +# Leveraging the pre-built Docker images with +# cargo-chef and the Rust toolchain +FROM git.kemitix.net/kemitix/git-next-builder:latest AS builder +WORKDIR /app + +COPY Cargo.toml Cargo.lock ./ +COPY src src +RUN cargo chef prepare --recipe-path recipe.json + +ARG CARGO_PROFILE +# Build dependencies - this is the caching Docker layer! +RUN cargo chef cook --profile "$CARGO_PROFILE" --recipe-path recipe.json +# Build application +COPY Cargo.toml Cargo.lock ./ +COPY src src +ARG CARGO_PROFILE +RUN cargo build --profile "$CARGO_PROFILE" --bin git-next +RUN if test "$CARGO_PROFILE" == "release" ; then strip target/release/git-next ; fi + +# We do not need the Rust toolchain to run the binary! +FROM docker.io/debian:stable-20240211-slim AS runtime +WORKDIR /app +RUN apt-get update && \ + apt-get install --no-install-recommends -y \ + libssl3=3.0.11-1~deb12u2 \ + ca-certificates=20230311 \ + && \ + rm -rf /var/lib/apt/lists/* +USER 1000 + +ARG CARGO_TARGET +COPY --from=builder /app/target/"$CARGO_TARGET"/git-next /usr/local/bin +ENTRYPOINT [ "/usr/local/bin/git-next" ] diff --git a/Dockerfile.builder b/Dockerfile.builder new file mode 100644 index 0000000..a4eeacf --- /dev/null +++ b/Dockerfile.builder @@ -0,0 +1,23 @@ +FROM docker.io/rust:latest + +RUN apt-get update && \ + apt-get install -y clang-15 mold && \ + curl -L https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz -o cargo-binstall.tgz && \ + tar -xzf cargo-binstall.tgz && \ + rm cargo-binstall.tgz && \ + mv cargo-binstall /usr/local/bin/ && \ + cargo binstall -y cargo-chef && \ + rustup component add rustfmt clippy + +# verify that the binaries are installed +RUN ls -l /usr/local/cargo/bin/ +RUN cargo chef --version +RUN rustfmt --version +RUN cargo fmt --version +RUN cargo clippy --version +RUN mold --version +RUN clang-15 --version +RUN cargo --version +RUN rustc --version +RUN rustup --version +RUN rustup show