-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdockerfile
More file actions
63 lines (51 loc) · 2.21 KB
/
dockerfile
File metadata and controls
63 lines (51 loc) · 2.21 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
59
60
61
62
63
###############################################################################
# 1. Planner stage: generate the dependency recipe (with C++ compiler)
###############################################################################
FROM rustlang/rust:nightly-bullseye-slim AS chef
# Install system deps including C++ compiler
RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
pkg-config \
libssl-dev \
git \
ca-certificates && \
rm -rf /var/lib/apt/lists/*
# Install cargo-chef and sccache
RUN cargo install --locked cargo-chef sccache
ENV RUSTC_WRAPPER="sccache" \
SCCACHE_DIR="/sccache"
WORKDIR /app
# Copy manifests and dummy main for cargo-chef
COPY Cargo.toml Cargo.lock ./
RUN mkdir src && echo 'fn main() {}' > src/main.rs && \
cargo chef prepare --recipe-path recipe.json
###############################################################################
# 2. Builder stage: compile dependencies & your code
###############################################################################
FROM chef AS builder
WORKDIR /app
# Rehydrate dependencies
COPY --from=chef /app/recipe.json recipe.json
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=$SCCACHE_DIR,sharing=locked \
cargo chef cook --release --recipe-path recipe.json
# Build the full application
COPY . .
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=$SCCACHE_DIR,sharing=locked \
cargo build --release
###############################################################################
# 3. Runtime stage: minimal Debian image
###############################################################################
FROM debian:bullseye-slim AS runtime
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates && \
rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/target/release/db2vec /usr/local/bin/db2vec
# Drop privileges: non-root user
RUN useradd --system --uid 10001 --shell /usr/sbin/nologin appuser
USER appuser
ENTRYPOINT ["/usr/local/bin/db2vec"]