forge
Explore
Log in

Don't you dare go Hollow

hezarfen_backend

Clone
★ 0

0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits

Containerfile50 lines, 1.9 KiBHistoryRawDownload
1# Build stage. Edition 2024 needs Rust >= 1.85; pinned to the current stable.
2FROM docker.io/library/rust:1.97-slim AS builder
3
4# utoipa-swagger-ui's build script downloads the Swagger UI bundle with curl.
5RUN apt-get update && \
6 apt-get install -y --no-install-recommends curl ca-certificates && \
7 rm -rf /var/lib/apt/lists/*
8
9WORKDIR /app
10COPY Cargo.toml Cargo.lock ./
11COPY src ./src
12# sqlx's compile-time macros verify every query against this committed cache,
13# so the build must never reach for a live database.
14ENV SQLX_OFFLINE=true
15COPY .sqlx ./.sqlx
16# The migrators read these at boot/mint (control set on the control pool,
17# school set for the template + every school database).
18COPY migrations ./migrations
19
20# Cache mounts keep the registry and incremental build artifacts between
21# builds. The binary must be copied out of /app/target inside the same RUN,
22# because cache mounts are not part of the image layers.
23RUN --mount=type=cache,target=/usr/local/cargo/registry \
24 --mount=type=cache,target=/app/target \
25 cargo build --release --locked && \
26 cp target/release/hezarfen_backend /usr/local/bin/hezarfen_backend
27
28# Runtime stage. curl is included for the compose healthcheck.
29FROM docker.io/library/debian:trixie-slim
30
31RUN apt-get update && \
32 apt-get install -y --no-install-recommends curl ca-certificates && \
33 rm -rf /var/lib/apt/lists/* && \
34 useradd --system --uid 10001 hezarfen && \
35 mkdir /data && chown hezarfen:hezarfen /data
36
37COPY --from=builder /usr/local/bin/hezarfen_backend /usr/local/bin/hezarfen_backend
38COPY --from=builder /app/migrations /app/migrations
39
40USER hezarfen
41
42# HOST must be 0.0.0.0 so the port mapping can reach the listener. DATABASE_URL
43# points at the compose Postgres (the control database); /data holds uploads.
44ENV HOST=0.0.0.0 \
45 PORT=7656 \
46 DATABASE_URL=postgres://hezarfen:hezarfen@postgres:5432/hezarfen_control
47
48EXPOSE 7656
49
50ENTRYPOINT ["/usr/local/bin/hezarfen_backend"]