# Synapse server: one image that serves the API and the built web app. # # docker build -t synapse . # docker build --target plus -t synapse:plus . # docker run -p 3000:3000 -v synapse-data:/app/apps/api/data \ # -v synapse-uploads:/app/apps/api/uploads synapse # # Migrations run automatically at boot. Seed demo courses once with: # docker exec node dist/scripts/seed.js # # The default image converts nothing beyond PDF, keeping it small. The `plus` # target adds the conversion tools (LibreOffice for office formats, pandoc # with weasyprint for markup formats) for uploads beyond PDF. FROM node:22-bookworm-slim AS build RUN apt-get update \ && apt-get install -y --no-install-recommends python3 build-essential ca-certificates \ && rm -rf /var/lib/apt/lists/* RUN corepack enable WORKDIR /app COPY . . # The workspace allowBuilds list (pnpm-workspace.yaml) approves the native # build scripts (better-sqlite3, bcrypt, esbuild, swc, nest). RUN pnpm install --frozen-lockfile RUN pnpm build # A self-contained production bundle of the API (its dist, its prod deps, # the workspace packages it uses), without any dev dependency. RUN pnpm --filter @synapse/api deploy --prod --legacy /deploy/api FROM node:22-bookworm-slim AS runtime ENV NODE_ENV=production # In a container the loopback-only default would make the service # unreachable; publish the port deliberately and front it with TLS. ENV HOST=0.0.0.0 ENV PORT=3000 COPY --from=build /deploy/api /app/apps/api COPY --from=build /app/apps/web/dist /app/apps/web/dist WORKDIR /app/apps/api RUN mkdir -p data uploads && chown -R node:node /app/apps/api/data /app/apps/api/uploads USER node EXPOSE 3000 VOLUME ["/app/apps/api/data", "/app/apps/api/uploads"] CMD ["node", "dist/main.js"] FROM runtime AS plus USER root RUN apt-get update \ && apt-get install -y --no-install-recommends \ pandoc weasyprint fonts-liberation \ libreoffice-writer libreoffice-impress libreoffice-calc \ && rm -rf /var/lib/apt/lists/* USER node # Last stage, so a bare `docker build` produces the small image. FROM runtime