Repository navigation
Expand file tree
/
Copy pathDockerfile.postgres
More file actions
64 lines (51 loc) · 3 KB
/
Copy pathDockerfile.postgres
File metadata and controls
64 lines (51 loc) · 3 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
64
FROM rust:bookworm AS chef
RUN cargo install cargo-chef --locked
RUN apt-get update \
&& apt-get install -y cmake libmariadb-dev libssl-dev clang \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /open_router
ENV CARGO_NET_RETRY=10
ENV RUSTUP_MAX_RETRIES=10
# ── Stage 1: compute the dependency recipe ───────────────────────────────────
# Only Cargo.toml / Cargo.lock files are needed here. Source files are not
# copied, so this layer is invalidated only when dependencies change.
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
# ── Stage 2: build dependencies only ─────────────────────────────────────────
# This is the slow step (~15-30 min). It is cached as a Docker layer and
# only re-runs when recipe.json changes (i.e. Cargo.toml / Cargo.lock changed).
# A source-only change never reaches this stage.
#
# BUILD_MODE=release → production binary with LTO + codegen-units=1 (default)
# BUILD_MODE=release-fast → fast-compile variant (~2 min); same opt-level, no LTO.
# Use for local iteration and ablation tests.
# BUILD_MODE=debug → unoptimised binary; skips LLVM passes, ~30s compile.
# Adequate for E2E / Cypress test runs where throughput
# doesn't matter.
FROM chef AS builder
ARG BUILD_MODE=release
ARG EXTRA_FEATURES=""
COPY --from=planner /open_router/recipe.json recipe.json
# debug has no --profile flag (it is the implicit default); all others use --profile <name>.
RUN PROFILE_FLAG=$([ "$BUILD_MODE" = "debug" ] && echo "" || echo "--profile ${BUILD_MODE}") && \
RUSTFLAGS="-A warnings" cargo chef cook $PROFILE_FLAG --no-default-features --features middleware,kms-aws,postgres ${EXTRA_FEATURES} --recipe-path recipe.json
# ── Stage 3: build the binary ─────────────────────────────────────────────────
# Dependencies are already compiled above. Only changed crates are recompiled.
COPY . .
RUN PROFILE_FLAG=$([ "$BUILD_MODE" = "debug" ] && echo "" || echo "--profile ${BUILD_MODE}") && \
RUSTFLAGS="-A warnings" cargo build $PROFILE_FLAG --no-default-features --features middleware,kms-aws,postgres ${EXTRA_FEATURES}
# ── Runtime image ─────────────────────────────────────────────────────────────
FROM debian:bookworm
ARG BUILD_MODE=release
ARG CONFIG_DIR=/local/config
ARG BIN_DIR=/local
ARG BINARY=open_router
ENV BINARY=${BINARY}
RUN apt-get update \
&& apt-get install -y ca-certificates tzdata libpq-dev curl procps libmariadb3
EXPOSE 8080
RUN mkdir -p ${CONFIG_DIR}
COPY --from=builder /open_router/target/${BUILD_MODE}/${BINARY} ${BIN_DIR}/${BINARY}
WORKDIR ${BIN_DIR}
CMD ["sh", "-c", "./${BINARY}"]