-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
51 lines (38 loc) · 1.09 KB
/
Dockerfile
File metadata and controls
51 lines (38 loc) · 1.09 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 1. Build rust
FROM lukemathwalker/cargo-chef:0.1.77-rust-1-slim-bookworm AS chef
RUN update-ca-certificates
# Create appuser
ENV USER=hsdocker
ENV UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
WORKDIR /httpserve
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
COPY --from=planner /httpserve/recipe.json recipe.json
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --recipe-path recipe.json
# Build application
COPY . .
RUN cargo build --release --bin httpserve
# 2. Package in a small production image
FROM gcr.io/distroless/cc-debian13
# Import user from builder.
COPY --from=chef /etc/passwd /etc/passwd
COPY --from=chef /etc/group /etc/group
WORKDIR /web
# copy the build artifact from the build stage
COPY --from=builder /httpserve/target/release/httpserve ./httpserve
EXPOSE 80
# Use an unprivileged user.
USER hsdocker:hsdocker
# Run the binary
CMD ["./httpserve"]