Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
58 lines (42 loc) · 1.73 KB
/
Copy pathDockerfile
File metadata and controls
58 lines (42 loc) · 1.73 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
52
53
54
55
56
57
58
# Build stage
FROM rust:1.90 AS chef
WORKDIR /app
# Install cargo-chef deterministically
RUN cargo install --locked cargo-chef
# Stage 1: compute dependency recipe (cacheable)
FROM chef AS planner
# Copy everything so Cargo Chef can correctly resolve the graph
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
# Stage 2: cook dependencies (cacheable)
FROM chef AS deps
COPY --from=planner /app/recipe.json recipe.json
# Use BuildKit cache mounts for registry/git to speed up network & reuse layers
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
cargo chef cook --release --recipe-path recipe.json
# Stage 3: build the actual binary
FROM chef AS builder
# Reuse cooked deps layer
COPY --from=deps /app/target target
COPY --from=deps /usr/local/cargo /usr/local/cargo
# Now copy real source and build
COPY . .
# Cache cargo artifacts across builds; keep target cache for faster incremental rebuilds
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
cargo install --path . --locked --root /app
# Optionally strip symbols to shrink the binary
RUN strip target/release/offline-election-tool || true
# Runtime
FROM debian:bookworm-slim
# Install runtime deps; clean apt lists to keep image slim
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Run as non-root
RUN useradd -u 10001 -r -s /usr/sbin/nologin appuser
COPY --from=builder /app/bin/offline-election-tool /app/offline-election-tool
RUN chmod +x /app/offline-election-tool && chown appuser:appuser /app/offline-election-tool
USER appuser
ENTRYPOINT ["/app/offline-election-tool"]