hezarfen_backend
Clone
https://git.tahinli.com/archive/hezarfen_backend.git
0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits
| 1 | # Build stage. Edition 2024 needs Rust >= 1.85; pinned to the current stable. |
| 2 | FROM docker.io/library/rust:1.97-slim AS builder |
| 3 | |
| 4 | # utoipa-swagger-ui's build script downloads the Swagger UI bundle with curl. |
| 5 | RUN apt-get update && \ |
| 6 | apt-get install -y --no-install-recommends curl ca-certificates && \ |
| 7 | rm -rf /var/lib/apt/lists/* |
| 8 | |
| 9 | WORKDIR /app |
| 10 | COPY Cargo.toml Cargo.lock ./ |
| 11 | COPY 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. |
| 14 | ENV SQLX_OFFLINE=true |
| 15 | COPY .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). |
| 18 | COPY 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. |
| 23 | RUN --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. |
| 29 | FROM docker.io/library/debian:trixie-slim |
| 30 | |
| 31 | RUN 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 | |
| 37 | COPY --from=builder /usr/local/bin/hezarfen_backend /usr/local/bin/hezarfen_backend |
| 38 | COPY --from=builder /app/migrations /app/migrations |
| 39 | |
| 40 | USER 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. |
| 44 | ENV HOST=0.0.0.0 \ |
| 45 | PORT=7656 \ |
| 46 | DATABASE_URL=postgres://hezarfen:hezarfen@postgres:5432/hezarfen_control |
| 47 | |
| 48 | EXPOSE 7656 |
| 49 | |
| 50 | ENTRYPOINT ["/usr/local/bin/hezarfen_backend"] |