# syntax=docker/dockerfile:1
# Needs `ryuk` from a registry or git. An app scaffolded with RYUK_PATH (a local path dependency)
# cannot build here: the path is outside the build context (vendor it into the context to try).
# Verified by hand (SQLite): builds, non-root uid 10001, HEALTHCHECK healthy, SIGTERM exits 0 in ~0.2 s.
FROM node:22-slim AS client
WORKDIR /client
# The lockfile pins every transitive dependency: `npm ci` builds exactly what was reviewed.
COPY client/package.json client/package-lock.json ./
RUN npm ci
COPY client/ ./
RUN npm run build
FROM rust:1-bookworm AS build
WORKDIR /src
COPY . .
RUN cargo build --release
FROM debian:bookworm-slim
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates curl \
&& rm -rf /var/lib/apt/lists/* \
&& useradd --system --create-home --uid 10001 app
WORKDIR /app
COPY --from=build /src/target/release/{{name}} /usr/local/bin/{{name}}
COPY --from=client /client/dist ./client/dist
# A sqlite DATABASE_URL should live here (sqlite:///app/data/db.sqlite?mode=rwc); mount a volume on it.
RUN mkdir data && chown app:app data
USER app
ENV APP_ENV=production HOST=0.0.0.0 PORT=3000 LOG_FORMAT=json
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=3s --start-period=20s --retries=3 \
CMD curl -fsS http://127.0.0.1:${PORT}/healthz || exit 1
STOPSIGNAL SIGTERM
CMD ["{{name}}"]