Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Commit

Permalink
chore: Use cargo chef to speed up docker build [load test: warn] (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncloudioj authored May 23, 2023
1 parent 96070f5 commit 92e57d1
Showing 1 changed file with 22 additions and 32 deletions.
54 changes: 22 additions & 32 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,51 +1,41 @@
# Docker 17.05 or higher required for multi-stage builds
# !!!NOTE!!!: Ensure Rust version matches CI's in .circleci/config.yml
FROM lukemathwalker/cargo-chef:latest-rust-1.68-bullseye AS chef
WORKDIR /app

FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --recipe-path recipe.json

# Change this to be your application's name
ARG APPNAME=contile
# Build application
COPY . .
# This build arg is used to pass the version (e.g. the commit SHA1 hash) from CI
# when building the application.
# when building the application. Bring it into scope here for better caching for
# Cargo Chef.
ARG VERSION=unset
RUN CONTILE_VERSION=${VERSION} cargo build --release

# NOTE: Ensure builder's Rust version matches CI's in .circleci/config.yml
FROM rust:1.68-slim-bullseye as builder
ARG APPNAME
ARG VERSION
ADD . /app
FROM debian:bullseye-slim AS runtime
WORKDIR /app

# Make sure that this matches in .travis.yml
# ARG RUST_TOOLCHAIN=nightly
RUN \
apt-get -qq update && \
apt-get install libssl-dev pkg-config -y && \
\
rustup default ${RUST_TOOLCHAIN} && \
cargo --version && \
rustc --version && \
mkdir -m 755 bin && \
CONTILE_VERSION=${VERSION} cargo build --release && \
cp /app/target/release/${APPNAME} /app/bin


FROM debian:bullseye-slim
ARG APPNAME

# FROM debian:buster # for debugging docker build
RUN \
groupadd --gid 10001 app && \
useradd --uid 10001 --gid 10001 --home /app --create-home app && \
\
apt-get -qq update && \
apt-get -qq install -y libssl-dev pkg-config ca-certificates && \
rm -rf /var/lib/apt/lists
rm -rf /var/lib/apt/lists && \
mkdir -m 755 bin

COPY --from=builder /app/bin /app/bin
COPY --from=builder /app/target/release/contile /app/bin
COPY --from=builder /app/version.json /app
COPY --from=builder /app/entrypoint.sh /app

WORKDIR /app
USER app

# ARG variables aren't available at runtime
ENV BINARY=/app/bin/${APPNAME}
ENV BINARY=/app/bin/contile
ENTRYPOINT ["/app/entrypoint.sh"]

0 comments on commit 92e57d1

Please sign in to comment.