-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
35 lines (33 loc) · 1.29 KB
/
Dockerfile
File metadata and controls
35 lines (33 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Using cargo-chef to cache dependencies
# -----------------------------------------------------------------------------
FROM rust:1-alpine3.20 AS chef
RUN apk add --no-cache musl-dev
WORKDIR /app
RUN cargo install cargo-chef
COPY . .
# create a recipe of the dependencies
RUN cargo chef prepare --recipe-path recipe.json
# Build dependencies in a separate layer
# -----------------------------------------------------------------------------
FROM rust:1-alpine3.20 AS builder
RUN apk add --no-cache musl-dev
WORKDIR /app
# copy the cargo-chef binary and the recipe from the chef stage
COPY --from=chef /usr/local/cargo/bin/cargo-chef /usr/local/cargo/bin/
COPY --from=chef /app/recipe.json recipe.json
# cook the dependencies
RUN cargo chef cook --release --recipe-path recipe.json
# copy the source and build the application
COPY . .
RUN cargo build --release
# Create the final small image
# -----------------------------------------------------------------------------
FROM alpine:3.20 AS runner
# create a non-root user to run the app
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
# switch to the non-root user
USER appuser
# copy the binary from the builder
COPY --from=builder /app/target/release/hello-actix /usr/local/bin/
# set the binary as entrypoint
ENTRYPOINT ["/usr/local/bin/hello-actix"]