62 lines
3.4 KiB
Docker
62 lines
3.4 KiB
Docker
FROM node:22-alpine AS base
|
|
ENV PNPM_HOME="/pnpm"
|
|
ENV PATH="$PNPM_HOME:$PATH"
|
|
RUN corepack enable
|
|
|
|
FROM base AS builder
|
|
WORKDIR /app
|
|
# Copy workspace manifests first for layer-cached install
|
|
COPY pnpm-workspace.yaml pnpm-lock.yaml package.json ./
|
|
COPY apps/gateway/package.json ./apps/gateway/
|
|
COPY apps/web/package.json ./apps/web/
|
|
COPY packages/ ./packages/
|
|
COPY plugins/ ./plugins/
|
|
# the root prepare script runs scripts/install-hooks.mjs on install
|
|
COPY scripts/ ./scripts/
|
|
RUN pnpm install --frozen-lockfile
|
|
COPY . .
|
|
# Build gateway, the web SPA bundle it serves (#1444), and all of their
|
|
# workspace dependencies via the turbo dependency graph
|
|
RUN pnpm turbo run build --filter @mosaicstack/gateway... --filter @mosaicstack/web...
|
|
# Produce a self-contained deploy artifact: flat node_modules, no pnpm symlinks
|
|
# --legacy is required for pnpm v10 when inject-workspace-packages is not set
|
|
RUN pnpm --filter @mosaicstack/gateway --prod deploy --legacy /deploy
|
|
|
|
FROM base AS runner
|
|
WORKDIR /app
|
|
ENV NODE_ENV=production
|
|
# WorkspaceService shells out to git at runtime and roots workspaces at
|
|
# $MOSAIC_ROOT/.workspaces (apps/gateway/src/workspace/workspace.service.ts);
|
|
# mount a volume over /opt/mosaic to persist workspaces across container restarts.
|
|
# Intentionally unpinned: Alpine's signed repository is the trust anchor; pinning
|
|
# packages was declined so routine base-image security updates remain maintainable.
|
|
# bash/curl/python3 are runtime dependencies of the provider-neutral Mosaic git
|
|
# wrappers. jq supports wrapper discovery for non-canonical Gitea hosts.
|
|
RUN apk add --no-cache bash curl git jq python3 \
|
|
&& mkdir -p /opt/mosaic/.workspaces \
|
|
&& chown -R node:node /opt/mosaic /app
|
|
ENV MOSAIC_ROOT=/opt/mosaic
|
|
# Dogfood agents use the same fail-closed credential helper and PR-create wrapper
|
|
# as fleet seats. Copy only that operation and its shared dependencies. Unrelated
|
|
# fleet operations, including merge and infrastructure tools, stay out of the image.
|
|
COPY --from=builder /app/packages/mosaic/framework/tools/git/pr-create.sh /opt/mosaic/tools/git/pr-create.sh
|
|
COPY --from=builder /app/packages/mosaic/framework/tools/git/detect-platform.sh /opt/mosaic/tools/git/detect-platform.sh
|
|
COPY --from=builder /app/packages/mosaic/framework/tools/git/repo-decl.sh /opt/mosaic/tools/git/repo-decl.sh
|
|
COPY --from=builder /app/packages/mosaic/framework/tools/git/git-credential-mosaic /opt/mosaic/tools/git/git-credential-mosaic
|
|
COPY --from=builder /app/packages/mosaic/framework/tools/_lib/credentials.sh /opt/mosaic/tools/_lib/credentials.sh
|
|
COPY --from=builder /app/packages/mosaic/framework/tools/structure/validate-repo-json.sh /opt/mosaic/tools/structure/validate-repo-json.sh
|
|
RUN git config --system credential.helper /opt/mosaic/tools/git/git-credential-mosaic
|
|
# Use the pnpm deploy output — resolves all deps into a flat, self-contained node_modules
|
|
COPY --chown=node:node --from=builder /deploy/node_modules ./node_modules
|
|
COPY --chown=node:node --from=builder /deploy/package.json ./package.json
|
|
# dist is declared in package.json "files" so pnpm deploy copies it into /deploy;
|
|
# copy from builder explicitly as belt-and-suspenders
|
|
COPY --chown=node:node --from=builder /app/apps/gateway/dist ./dist
|
|
# The built web SPA bundle; served by the gateway (apps/gateway/src/spa/serve-spa.ts)
|
|
COPY --chown=node:node --from=builder /app/apps/web/dist ./web-dist
|
|
ENV WEB_DIST_DIR=/app/web-dist
|
|
# gateway defaults to port 14242 (apps/gateway/src/main.ts)
|
|
EXPOSE 14242
|
|
USER node
|
|
CMD ["node", "dist/main.js"]
|