Until now `docker compose up` built the image on the user's machine: a compiler toolchain, every dev dependency, a few minutes of CPU — on a Raspberry Pi considerably more. The compose files now pull ghcr.io/tillheidrich/klarbild:1, built by .github/workflows/image.yml for linux/amd64 and linux/arm64. `:1` follows every 1.x release, so an update is `docker compose pull && docker compose up -d`. `build: .` is one commented line away for anyone who prefers to build. The Dockerfile has two stages now. The runtime stage carries the built server, production dependencies and the migrations — no compiler, no dev dependencies, no source tree. argon2 and sharp ship prebuilt binaries for both architectures, so python/make/g++ are gone entirely. It runs as the `node` user (uid 1000); a fresh named volume at /data inherits that ownership. Verified locally: image builds, boots against Postgres, applies all 17 migrations, prints the first-run password, passes its healthcheck, accepts an upload as the unprivileged user and returns an A4 sheet that measures 210.00 x 297.00 mm.
37 lines
1.5 KiB
Docker
37 lines
1.5 KiB
Docker
# Klarbild — two stages. The first builds, the second only runs: no compiler,
|
|
# no dev dependencies, no source tree in the image that ends up on your server.
|
|
|
|
FROM node:22-bookworm-slim AS build
|
|
WORKDIR /app
|
|
# The lockfile comes first and `npm ci` honours it, so the image is built from
|
|
# the exact versions CI tested — not from whatever `^` resolved to today.
|
|
# Native modules (argon2, sharp) ship prebuilt binaries for amd64 and arm64,
|
|
# so no compiler is needed in either stage.
|
|
COPY package.json package-lock.json ./
|
|
RUN npm ci --no-audit --no-fund
|
|
COPY . .
|
|
RUN npm run build && npm prune --omit=dev --no-audit --no-fund
|
|
|
|
FROM node:22-bookworm-slim
|
|
WORKDIR /app
|
|
ENV NODE_ENV=production PORT=4321 HOST=0.0.0.0 STORAGE_DIR=/data
|
|
|
|
COPY --from=build --chown=node:node /app/package.json ./
|
|
COPY --from=build --chown=node:node /app/node_modules ./node_modules
|
|
COPY --from=build --chown=node:node /app/dist ./dist
|
|
# Read at runtime, on every boot.
|
|
COPY --from=build --chown=node:node /app/migrations ./migrations
|
|
|
|
# Not root. A fresh named volume mounted at /data takes over this ownership;
|
|
# for a bind mount, give the directory to uid 1000 (`chown 1000:1000 ./data`).
|
|
RUN mkdir -p /data && chown node:node /data
|
|
USER node
|
|
|
|
EXPOSE 4321
|
|
VOLUME ["/data"]
|
|
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=40s --retries=3 \
|
|
CMD node -e "fetch('http://127.0.0.1:'+(process.env.PORT||4321)+'/api/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
|
|
|
|
CMD ["node", "./dist/server/entry.mjs"]
|