89 lines
3.2 KiB
Docker
89 lines
3.2 KiB
Docker
# Frontend: built first, it is the part that changes most often
|
|
FROM node:22-slim AS frontend
|
|
WORKDIR /build
|
|
|
|
# Dependencies in their own layer, so a source-only change does not reinstall them
|
|
COPY frontend/package.json frontend/package-lock.json ./
|
|
RUN npm ci
|
|
|
|
COPY frontend/ ./
|
|
# The checks run here rather than in a separate CI job: the build then fails on
|
|
# the runner for the same reason it would fail locally, and there is only one
|
|
# environment to keep working.
|
|
RUN npx eslint . --max-warnings=0
|
|
RUN npm run build # type-check + vite build
|
|
|
|
|
|
# Backend: compiled against the sqlx offline data (`cargo sqlx prepare`), so no
|
|
# database is needed here
|
|
FROM rust:1.97-slim AS backend
|
|
WORKDIR /build
|
|
|
|
ENV SQLX_OFFLINE=true
|
|
# Traceability: `build.rs` falls back on this when there is no git repository
|
|
ARG GIT_HASH=unknown
|
|
ENV GIT_HASH=${GIT_HASH}
|
|
|
|
# Warm the dependency layer with a dummy main, so editing src/ does not rebuild
|
|
# every crate we depend on
|
|
COPY Cargo.toml Cargo.lock build.rs ./
|
|
RUN mkdir src && echo 'fn main() {}' > src/main.rs \
|
|
&& cargo build --release \
|
|
&& rm -rf src
|
|
|
|
COPY .sqlx/ .sqlx/
|
|
COPY src/ src/
|
|
# cargo skips a rebuild when only mtime changed: force it for our own crate
|
|
RUN touch src/main.rs \
|
|
&& cargo build --release --locked \
|
|
&& cargo test --release --locked
|
|
|
|
|
|
# Runtime
|
|
FROM debian:trixie-slim
|
|
LABEL org.opencontainers.image.title="studium"
|
|
|
|
# The lecture notes are rendered by pandoc and pdflatex. latex-extra holds tcolorbox,
|
|
# sectsty and pmboxdraw, used by the template. curl serves the healthcheck, and
|
|
# fetches pandoc below.
|
|
RUN apt-get update \
|
|
&& apt-get install -y --no-install-recommends \
|
|
curl ca-certificates \
|
|
texlive-latex-base texlive-latex-recommended texlive-latex-extra \
|
|
texlive-fonts-recommended texlive-pictures lmodern \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# The pandoc of Debian is too old for `--syntax-highlighting` (3.8+): the release of
|
|
# pandoc itself, the same version as in development
|
|
ARG PANDOC_VERSION=3.11
|
|
RUN arch="$(dpkg --print-architecture)" \
|
|
&& curl -fsSL -o /tmp/pandoc.deb \
|
|
"https://github.com/jgm/pandoc/releases/download/${PANDOC_VERSION}/pandoc-${PANDOC_VERSION}-1-${arch}.deb" \
|
|
&& dpkg -i /tmp/pandoc.deb \
|
|
&& rm /tmp/pandoc.deb
|
|
|
|
# The migrations travel with the image, so the stack needs nothing from the
|
|
# repository: the `migrate` service runs this same image with another entrypoint.
|
|
COPY --from=ghcr.io/amacneil/dbmate:2 /usr/local/bin/dbmate /usr/local/bin/dbmate
|
|
COPY db/migrations/ /app/db/migrations/
|
|
|
|
# Not root: the app only needs to write in its storage. The folder mounted there must
|
|
# belong to this uid (`chown -R 1000:1000` on the host).
|
|
RUN useradd --uid 1000 --create-home studium \
|
|
&& mkdir -p /data/storage \
|
|
&& chown studium:studium /data/storage
|
|
|
|
WORKDIR /app
|
|
COPY --from=backend /build/target/release/studium /usr/local/bin/studium
|
|
COPY --from=frontend /build/dist/ /app/frontend/
|
|
COPY LaTeX_pdf/ /app/LaTeX_pdf/
|
|
COPY docker/config.yml /etc/studium/config.yml
|
|
|
|
USER studium
|
|
EXPOSE 3000
|
|
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
|
CMD curl -fsS http://localhost:3000/api/version || exit 1
|
|
|
|
# No shell: signals reach the binary directly, so the graceful shutdown works
|
|
ENTRYPOINT ["/usr/local/bin/studium"]
|