Repository navigation
Expand file tree
/
Copy pathDockerfile.api
More file actions
99 lines (98 loc) · 5.25 KB
/
Copy pathDockerfile.api
File metadata and controls
99 lines (98 loc) · 5.25 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# syntax=docker/dockerfile:1
# Multi-stage build for jmodguard-api.
# Pins Rust 1.100 (lockfile MSRV; edition 2024). JSON API + OAuth only: do not
# embed frontend/ (Bunny serves that from Storage/CDN). linux/amd64 manifest
# digest for rust:1.100.0-trixie (must match the FROM line below).
# Local: docker build --secret id=github_token,env=GITHUB_TOKEN -f Dockerfile.api .
FROM rust:1.100.0-trixie@sha256:ebc54bef33ec8f9a5cd05799366010f35efbb73b354fb4f2cb086ec6b9460ef5 AS builder
WORKDIR /app
# git and the rust-toolchain.toml toolchain are installed before source COPY
# so those layers stay cached when only application source changes.
RUN apt-get update \
&& apt-get install -y --no-install-recommends git \
&& rm -rf /var/lib/apt/lists/*
COPY rust-toolchain.toml ./
RUN rustup show
# Copy workspace manifests and vendored crates before application source so
# dependency fetch and third-party compilation stay cached until manifests,
# Cargo.lock, or vendor/ change.
COPY Cargo.toml Cargo.lock ./
COPY crates/runtime/Cargo.toml ./crates/runtime/Cargo.toml
COPY crates/bot/Cargo.toml ./crates/bot/Cargo.toml
COPY crates/api/Cargo.toml ./crates/api/Cargo.toml
COPY crates/updater/Cargo.toml ./crates/updater/Cargo.toml
COPY crates/integration-tests/Cargo.toml ./crates/integration-tests/Cargo.toml
COPY vendor ./vendor
RUN mkdir -p src crates/runtime/src crates/bot/src crates/api/src crates/updater/src crates/integration-tests/src \
&& printf '' > src/lib.rs \
&& printf '' > crates/runtime/src/lib.rs \
&& printf '' > crates/bot/src/lib.rs \
&& printf 'fn main() {}\n' > crates/bot/src/main.rs \
&& printf '' > crates/api/src/lib.rs \
&& printf 'fn main() {}\n' > crates/api/src/main.rs \
&& printf '' > crates/updater/src/lib.rs \
&& printf 'fn main() {}\n' > crates/updater/src/main.rs \
&& printf '' > crates/integration-tests/src/lib.rs
RUN --mount=type=secret,id=github_token,required=true \
GIT_CONFIG_COUNT=1 \
GIT_CONFIG_KEY_0=credential.helper \
GIT_CONFIG_VALUE_0='!f() { echo username=x-access-token; echo password=$(cat /run/secrets/github_token); }; f' \
CARGO_NET_GIT_FETCH_WITH_CLI=true \
cargo fetch --locked
# Precompile third-party dependencies using the exact package and feature set
# of the final build so feature unification stays identical across layers.
RUN cargo build --locked --offline --release -p jmodguard-api -p jmodguard-updater --no-default-features \
&& cargo clean --release -p jmodguard-runtime -p jmodguard -p jmodguard-updater -p jmodguard-api
# Compile workspace crates in dependency order so unchanged lower crates reuse
# cached layers when only higher crates or SOURCE_SHA change.
COPY crates/runtime/src ./crates/runtime/src
RUN cargo build --locked --offline --release -p jmodguard-api -p jmodguard-updater --no-default-features \
&& cargo clean --release -p jmodguard -p jmodguard-updater -p jmodguard-api
COPY src ./src
COPY migrations ./migrations
RUN cargo build --locked --offline --release -p jmodguard-api -p jmodguard-updater --no-default-features \
&& cargo clean --release -p jmodguard-updater -p jmodguard-api
COPY deploy/update-signing.pub ./deploy/update-signing.pub
COPY crates/updater/src ./crates/updater/src
RUN cargo build --locked --offline --release -p jmodguard-api -p jmodguard-updater --no-default-features \
&& cargo clean --release -p jmodguard-api
COPY crates/api/src ./crates/api/src
RUN cargo build --locked --offline --release -p jmodguard-api -p jmodguard-updater --no-default-features --lib
ARG SOURCE_SHA=unknown
COPY LICENSE.md ./
COPY scripts/bootstrap-container.sh ./scripts/bootstrap-container.sh
RUN JMODGUARD_BUILD_SHA=${SOURCE_SHA} \
cargo build --locked --offline --release -p jmodguard-api -p jmodguard-updater --no-default-features --bins \
&& mkdir -p /app/release/bin /app/release/share/jmodguard \
&& cp target/release/jmodguard-api target/release/jmodguard-launcher /app/release/bin/ \
&& cp scripts/bootstrap-container.sh /app/release/bin/jmodguard-bootstrap \
&& cp LICENSE.md /app/release/share/jmodguard/LICENSE.md \
&& cd /app/release \
&& sha256sum bin/jmodguard-api bin/jmodguard-launcher > share/jmodguard/files.sha256 \
&& mkdir -p /app/oci-layer/usr/local/bin /app/oci-layer/usr/local/share/jmodguard \
&& cp -a bin/. /app/oci-layer/usr/local/bin/ \
&& cp -a share/jmodguard/. /app/oci-layer/usr/local/share/jmodguard/
FROM debian:trixie-slim@sha256:7378260c0a098d27ac206225db5e7d92b8c7c84ea7afccc86eeb513756bbd392
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates \
&& rm -rf /var/lib/apt/lists/* \
&& useradd --system --uid 10001 --home /data --shell /usr/sbin/nologin jmodguard \
&& mkdir -p /data \
&& chown jmodguard:jmodguard /data
WORKDIR /data
COPY --from=builder /app/oci-layer/ /
ARG SOURCE_SHA=unknown
VOLUME ["/data"]
USER 10001
ENV JMODGUARD_DB_PATH=/data/jmodguard.db
ENV JMODGUARD_CONFIG=/data/config.toml
ENV JMODGUARD_WEB_BIND=0.0.0.0:8080
ENV JMODGUARD_LOG_DIRECTORY=""
# Fail closed unless Bunny/portable remote credentials are present.
ENV JMODGUARD_REQUIRE_REMOTE_DB=1
ENV JMODGUARD_BASE_SHA=${SOURCE_SHA}
ENV JMODGUARD_BASE_ABI=debian-trixie-amd64
ENV JMODGUARD_ROLE=api
ENV JMODGUARD_SELF_UPDATE=0
EXPOSE 8080
ENTRYPOINT ["/bin/sh", "/usr/local/bin/jmodguard-bootstrap"]