build: add caching for container image creation
This commit is contained in:
parent
a25cb5a7ef
commit
e1c775066b
1 changed files with 22 additions and 9 deletions
31
Dockerfile
31
Dockerfile
|
|
@ -1,20 +1,33 @@
|
||||||
# Builder stage
|
# Builder stage
|
||||||
FROM rust:1.75.0 AS builder
|
FROM docker.io/lukemathwalker/cargo-chef:latest-rust-1.75.0 as chef
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN apt update && apt install lld clang -y
|
RUN apt update && apt install lld clang -y
|
||||||
|
|
||||||
|
FROM chef as planner
|
||||||
|
COPY . .
|
||||||
|
# Compute a lock-like file for our project
|
||||||
|
RUN cargo chef prepare --recipe-path recipe.json
|
||||||
|
|
||||||
|
FROM chef as builder
|
||||||
|
COPY --from=planner /app/recipe.json recipe.json
|
||||||
|
# Build our project dependencies, not our application!
|
||||||
|
RUN cargo chef cook --release --recipe-path recipe.json
|
||||||
|
# Up to this point, if our dependency tree stays the same,
|
||||||
|
# all layers should be cached.
|
||||||
COPY . .
|
COPY . .
|
||||||
ENV SQLX_OFFLINE true
|
ENV SQLX_OFFLINE true
|
||||||
RUN cargo build --release
|
# Build our project
|
||||||
|
RUN cargo build --release --bin zero2prod
|
||||||
# Runtime stage
|
|
||||||
FROM rust:1.75.0-slim AS runtime
|
|
||||||
|
|
||||||
|
FROM docker.io/debian:bullseye-slim AS runtime
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
# Copy the compiled binary from the builder environment
|
RUN apt-get update -y \
|
||||||
# to our runtime environment
|
&& apt-get install -y --no-install-recommends openssl ca-certificates \
|
||||||
|
# Clean up
|
||||||
|
&& apt-get autoremove -y \
|
||||||
|
&& apt-get clean -y \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
COPY --from=builder /app/target/release/learn_axum zero2prod
|
COPY --from=builder /app/target/release/learn_axum zero2prod
|
||||||
# We need the configuration file at runtime!
|
|
||||||
COPY configuration configuration
|
COPY configuration configuration
|
||||||
ENV APP_ENVIRONMENT production
|
ENV APP_ENVIRONMENT production
|
||||||
ENTRYPOINT ["./zero2prod"]
|
ENTRYPOINT ["./zero2prod"]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue