forge
Explore
Log in

Don't you dare go Hollow

hezarfen_backend

Clone
★ 0

0 watching0 forksRust8.3 MiBaf331ecAhmet Kaan Gümüş2 months ago451 commits

Containerfile46 lines, 1.7 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
17# Cache mounts keep the registry and incremental build artifacts between
18# builds. The binary must be copied out of /app/target inside the same RUN,
19# because cache mounts are not part of the image layers.
20RUN --mount=type=cache,target=/usr/local/cargo/registry \
21 --mount=type=cache,target=/app/target \
22 cargo build --release --locked && \
23 cp target/release/hezarfen_backend /usr/local/bin/hezarfen_backend
24
25# Runtime stage. curl is included for the compose healthcheck.
26FROM docker.io/library/debian:trixie-slim
27
28RUN apt-get update && \
29 apt-get install -y --no-install-recommends curl ca-certificates && \
30 rm -rf /var/lib/apt/lists/* && \
31 useradd --system --uid 10001 hezarfen && \
32 mkdir /data && chown hezarfen:hezarfen /data
33
34COPY --from=builder /usr/local/bin/hezarfen_backend /usr/local/bin/hezarfen_backend
35
36USER hezarfen
37
38# HOST must be 0.0.0.0 so the port mapping can reach the listener. DATABASE_URL
39# points at the compose Postgres (the control database); /data holds uploads.
40ENV HOST=0.0.0.0 \
41 PORT=8080 \
42 DATABASE_URL=postgres://hezarfen:hezarfen@postgres:5432/hezarfen_control
43
44EXPOSE 8080
45
46ENTRYPOINT ["/usr/local/bin/hezarfen_backend"]