2024-05-28 09:59:00 +03:00
|
|
|
# This should match the Rust version in rust-toolchain.yaml and the other Dockerfiles.
|
2024-05-16 18:06:16 +03:00
|
|
|
FROM rust:1.78.0 as chef
|
2023-12-19 12:04:02 +03:00
|
|
|
|
|
|
|
WORKDIR app
|
|
|
|
|
2024-04-22 16:42:32 +03:00
|
|
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
|
|
|
|
|
|
RUN set -ex;\
|
|
|
|
apt-get update; \
|
2023-12-19 12:04:02 +03:00
|
|
|
apt-get install --no-install-recommends --assume-yes \
|
2024-04-22 16:42:32 +03:00
|
|
|
curl git jq pkg-config ssh \
|
|
|
|
libssl-dev lld protobuf-compiler
|
2023-12-19 12:04:02 +03:00
|
|
|
|
2024-04-22 16:42:32 +03:00
|
|
|
# Set up a directory to store Cargo files.
|
2023-12-19 12:04:02 +03:00
|
|
|
ENV CARGO_HOME=/app/.cargo
|
2024-04-22 16:42:32 +03:00
|
|
|
ENV PATH="$PATH:$CARGO_HOME/bin"
|
|
|
|
# Switch to `lld` as the linker.
|
|
|
|
ENV RUSTFLAGS="-C link-arg=-fuse-ld=lld"
|
2024-04-23 12:18:22 +03:00
|
|
|
# Building with build.rs requires the Git context to be available across volumes.
|
2024-01-25 11:53:24 +03:00
|
|
|
ENV GIT_DISCOVERY_ACROSS_FILESYSTEM=1
|
|
|
|
|
2024-04-23 12:18:22 +03:00
|
|
|
# Install Rust tools.
|
2024-03-28 11:52:02 +03:00
|
|
|
COPY rust-toolchain.toml .
|
|
|
|
RUN rustup show
|
2024-05-28 09:59:00 +03:00
|
|
|
RUN cargo install cargo-chef
|
2024-03-28 11:52:02 +03:00
|
|
|
|
2023-12-19 12:04:02 +03:00
|
|
|
###
|
|
|
|
# Plan recipe
|
|
|
|
FROM chef AS planner
|
|
|
|
|
2024-04-22 16:42:32 +03:00
|
|
|
# Copy files
|
|
|
|
COPY .cargo ./.cargo
|
|
|
|
COPY Cargo.toml Cargo.lock ./
|
|
|
|
COPY crates ./crates
|
2023-12-19 12:04:02 +03:00
|
|
|
|
2024-04-22 16:42:32 +03:00
|
|
|
# Prepare the recipe
|
2024-01-30 16:02:19 +03:00
|
|
|
RUN cargo chef prepare --recipe-path recipe.json
|
2023-12-19 12:04:02 +03:00
|
|
|
|
|
|
|
###
|
|
|
|
# Build recipe
|
|
|
|
FROM chef AS builder
|
|
|
|
|
|
|
|
COPY --from=planner /app/recipe.json recipe.json
|
|
|
|
COPY --from=planner /app/.cargo/config.toml /app/.cargo/config.toml
|
|
|
|
|
|
|
|
# Build dependencies - this is the caching Docker layer!
|
2024-01-30 16:02:19 +03:00
|
|
|
RUN cargo chef cook --release --all-targets --recipe-path recipe.json
|
2023-12-19 12:04:02 +03:00
|
|
|
|
|
|
|
###
|
|
|
|
# Builds the application
|
|
|
|
FROM builder AS built
|
2024-04-22 16:42:32 +03:00
|
|
|
|
|
|
|
# Copy files
|
|
|
|
COPY .cargo ./.cargo
|
|
|
|
COPY Cargo.toml Cargo.lock ./
|
|
|
|
COPY crates ./crates
|
|
|
|
COPY .git ./.git
|
|
|
|
|
2023-12-19 12:04:02 +03:00
|
|
|
# Build the app
|
2024-03-18 14:20:33 +03:00
|
|
|
RUN cargo build --release --all-targets
|
2023-12-19 12:04:02 +03:00
|
|
|
|
|
|
|
###
|
|
|
|
# Ship the app in an image with `curl` and very little else
|
|
|
|
FROM ubuntu:jammy
|
|
|
|
|
|
|
|
# Install `curl` for health checks
|
|
|
|
RUN set -ex; \
|
2024-04-22 16:42:32 +03:00
|
|
|
apt-get update; \
|
|
|
|
apt-get install --assume-yes curl
|
2023-12-19 12:04:02 +03:00
|
|
|
|
|
|
|
# Install the engine
|
|
|
|
COPY --from=built /app/target/release/engine /usr/local/bin
|
|
|
|
ENTRYPOINT ["engine"]
|