Three root causes resolved: 1. .woodpecker/web.yml: build-shared step was missing @mosaic/ui build, causing 10 test suite failures + 20 typecheck errors (TS2307) 2. apps/orchestrator/Dockerfile: find -o without parentheses only deleted last pattern's matches, leaving spec files with test fixture secrets that triggered 5 Trivy false positives (3 CRITICAL, 2 HIGH) 3. 9 web files had untyped event handler parameters (e) causing 49 lint errors and 19 typecheck errors — added React.ChangeEvent<T> types Verification: lint 0 errors, typecheck 0 errors, tests 73/73 suites pass Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
111 lines
3.8 KiB
Docker
111 lines
3.8 KiB
Docker
# syntax=docker/dockerfile:1
|
|
# Enable BuildKit features for cache mounts
|
|
|
|
# Base image for all stages
|
|
FROM node:20-alpine AS base
|
|
|
|
# Install pnpm globally
|
|
RUN corepack enable && corepack prepare pnpm@10.27.0 --activate
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy monorepo configuration files
|
|
COPY pnpm-workspace.yaml package.json pnpm-lock.yaml ./
|
|
COPY turbo.json ./
|
|
|
|
# ======================
|
|
# Dependencies stage
|
|
# ======================
|
|
FROM base AS deps
|
|
|
|
# Copy all package.json files for workspace resolution
|
|
COPY packages/shared/package.json ./packages/shared/
|
|
COPY packages/config/package.json ./packages/config/
|
|
COPY apps/orchestrator/package.json ./apps/orchestrator/
|
|
|
|
# Install ALL dependencies (not just production)
|
|
# This ensures NestJS packages and other required deps are available
|
|
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
|
pnpm install --frozen-lockfile
|
|
|
|
# ======================
|
|
# Builder stage
|
|
# ======================
|
|
FROM base AS builder
|
|
|
|
# Copy root node_modules from deps
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
|
|
# Copy all source code
|
|
COPY packages ./packages
|
|
COPY apps/orchestrator ./apps/orchestrator
|
|
|
|
# Copy workspace node_modules from deps
|
|
COPY --from=deps /app/packages/shared/node_modules ./packages/shared/node_modules
|
|
COPY --from=deps /app/packages/config/node_modules ./packages/config/node_modules
|
|
COPY --from=deps /app/apps/orchestrator/node_modules ./apps/orchestrator/node_modules
|
|
|
|
# Build the orchestrator app using TurboRepo
|
|
RUN pnpm turbo build --filter=@mosaic/orchestrator
|
|
|
|
# ======================
|
|
# Production stage
|
|
# ======================
|
|
FROM node:20-alpine AS production
|
|
|
|
# Add metadata labels
|
|
LABEL maintainer="mosaic-team@mosaicstack.dev"
|
|
LABEL version="0.0.6"
|
|
LABEL description="Mosaic Orchestrator - Agent orchestration service"
|
|
LABEL org.opencontainers.image.source="https://git.mosaicstack.dev/mosaic/stack"
|
|
LABEL org.opencontainers.image.vendor="Mosaic Stack"
|
|
LABEL org.opencontainers.image.title="Mosaic Orchestrator"
|
|
LABEL org.opencontainers.image.description="Agent orchestration service for Mosaic Stack"
|
|
|
|
# Remove npm (unused in production — we use pnpm) to eliminate bundled CVEs
|
|
# (cross-spawn CVE-2024-21538, glob CVE-2025-64756, tar CVE-2026-23745/23950/24842)
|
|
RUN rm -rf /usr/local/lib/node_modules/npm /usr/local/bin/npm /usr/local/bin/npx
|
|
|
|
# Install wget and dumb-init
|
|
RUN apk add --no-cache wget dumb-init
|
|
|
|
# Create non-root user
|
|
RUN addgroup -g 1001 -S nodejs && adduser -S nestjs -u 1001
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy node_modules from builder (includes all dependencies)
|
|
COPY --from=builder --chown=nestjs:nodejs /app/node_modules ./node_modules
|
|
|
|
# Copy built packages (includes dist/ directories)
|
|
COPY --from=builder --chown=nestjs:nodejs /app/packages ./packages
|
|
|
|
# Copy built orchestrator application
|
|
COPY --from=builder --chown=nestjs:nodejs /app/apps/orchestrator/dist ./apps/orchestrator/dist
|
|
# Remove compiled test files from production (contain test fixtures that trigger Trivy secret scanning)
|
|
RUN find ./apps/orchestrator/dist \( -name '*.spec.js' -o -name '*.spec.js.map' -o -name '*.test.js' -o -name '*.test.js.map' \) -print | xargs rm -f 2>/dev/null || true
|
|
COPY --from=builder --chown=nestjs:nodejs /app/apps/orchestrator/package.json ./apps/orchestrator/
|
|
|
|
# Copy app's node_modules which contains symlinks to root node_modules
|
|
COPY --from=builder --chown=nestjs:nodejs /app/apps/orchestrator/node_modules ./apps/orchestrator/node_modules
|
|
|
|
# Set working directory to orchestrator app
|
|
WORKDIR /app/apps/orchestrator
|
|
|
|
# Switch to non-root user
|
|
USER nestjs
|
|
|
|
# Expose orchestrator port
|
|
EXPOSE 3001
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:3001/health || exit 1
|
|
|
|
# Use dumb-init to handle signals properly
|
|
ENTRYPOINT ["dumb-init", "--"]
|
|
|
|
# Start the application
|
|
CMD ["node", "dist/main.js"]
|