Files
GMW/infra/docker/Dockerfile.backend
T
Developer 0c6e18db77
Build & Deploy / build-and-push (backend) (push) Failing after 1m25s
Build & Deploy / build-and-push (discord-gateway) (push) Failing after 26s
Build & Deploy / build-and-push (proxy) (push) Failing after 25s
perf: optimize Docker images - backend 294MB, gateway 1.89GB
Backend:
- node:22-alpine runtime (from 1.82GB to 294MB, 84% reduction)
- COPY --chown instead of chown -R layer
- pnpm install --prod after build for clean .pnpm store
- Pinned pnpm@10 to avoid v11 build-script lockout

Gateway:
- Fixed TypeScript errors (missing table defs in shared schema)
- Restored node-crc Rust patch for native compilation
- Multi-stage build with COPY --chown
- pnpm install --prod after build
- ffmpeg with --no-install-recommends

Proxy:
- Restructured for standalone build (build errors are pre-existing)

General:
- pnpm@10 in all builds (avoids ERR_PNPM_IGNORED_BUILDS)
- Clean .dockerignore (excludes docs/design/scripts)
2026-07-30 13:18:44 +07:00

42 lines
1.2 KiB
Docker

# ---- Builder stage ----
FROM node:22-slim AS builder
WORKDIR /build
RUN npm install -g pnpm@10
# Build tools for native addons (discordjs/voice may need node-gyp)
RUN apt-get update -qq && apt-get install -y -qq --no-install-recommends \
python3 make g++ \
&& rm -rf /var/lib/apt/lists/*
# Copy source + manifests
COPY services/backend/ ./
# Install ALL deps (devDeps needed for TypeScript build)
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
pnpm install --no-frozen-lockfile
# Build TypeScript
RUN ./node_modules/.bin/tsc
# Switch to production-only deps (strips devDeps + cleans .pnpm store)
RUN rm -rf node_modules && pnpm install --prod --no-frozen-lockfile
# ---- Runtime stage ----
FROM node:22-alpine
WORKDIR /app
COPY --from=builder --chown=node:node /build/dist ./dist
COPY --from=builder --chown=node:node /build/node_modules ./node_modules
COPY --from=builder --chown=node:node /build/package.json ./
USER node
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000/api/health',r=>process.exit(r.statusCode===200?0:1))"
CMD ["node", "dist/index.js"]