This repository has been archived by the owner on Jul 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Use cargo chef to speed up docker build [load test: warn] (#561)
- Loading branch information
Showing
1 changed file
with
22 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |