This repository has been archived on 2026-11-17. You can view files and clone it, but cannot push or open issues or pull requests.
caelum0x 2bbcceb77b fix(docker): run the full stack in compose — gitgram backend+web healthy
The whole stack now comes up healthy under one `docker compose` run (gitgram
backend+web + Postgres/Redis + aitm-api/mcp/website + gitnexus); only the
optional tools-profile context7 remains (pre-existing workspace-build issue).

gitgram/backend/Dockerfile: move to a glibc base (node:20-bookworm-slim). Alpine
musl lacks the glibc loader that @tensorflow/tfjs-node's native libtensorflow
needs (ERR_DLOPEN_FAILED), so NSFW detection now runs for real (no stubbing).
Full install WITH lifecycle scripts in the builder (downloads libtensorflow),
node_modules reused in the runtime stage so devDeps like swagger-ui-express are
present for the NODE_ENV=development compose run; openssl + ffmpeg + libgomp1
runtime libs; create writable /app/logs + /app/uploads for the non-root user.
prisma schema: binaryTargets -> debian/arm64 openssl-3 for the glibc runtime.
nsfwDetectionService: lazy-load tf + nsfwjs so a genuinely-unavailable native
lib degrades gracefully instead of crashing at import (still uses real tfjs).

gitgram/web/Dockerfile: npm ci -> npm install (workspace member's standalone
lockfile drifts after dependency additions).

Verified end-to-end through containers: register/login/post/feed 201/200,
web homepage + GitHub->Gitgram /caelum0x both 200.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-29 04:04:38 +03:00

65 lines
2.6 KiB
Docker

# syntax=docker/dockerfile:1
#
# gitgram backend — production image on a glibc (Debian) base.
#
# A glibc base (not Alpine/musl) is required because @tensorflow/tfjs-node ships
# prebuilt native binaries that link the glibc dynamic loader (ld-linux) and
# libtensorflow; on Alpine they fail to dlopen. node:20-bookworm-slim provides
# the loader + shared libs, so NSFW detection runs for real (no stubbing).
# ── Build stage ──────────────────────────────────────────────────────────────
FROM node:20-bookworm-slim AS builder
WORKDIR /app
# Toolchain for native modules + Prisma/openssl + tfjs postinstall (curl/ca-certs
# to download libtensorflow, python3/make/g++ for node-gyp builds).
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates curl openssl python3 make g++ \
&& rm -rf /var/lib/apt/lists/*
COPY package.json package-lock.json* tsconfig.json ./
# Full install WITH lifecycle scripts so @tensorflow/tfjs-node downloads its
# native libtensorflow binary for this platform.
RUN npm install --no-audit --no-fund
COPY . .
RUN npx prisma generate
RUN npm run build
# ── Production stage ─────────────────────────────────────────────────────────
FROM node:20-bookworm-slim AS runner
WORKDIR /app
# Runtime libs: ffmpeg/ffprobe for video thumbnails, openssl for Prisma,
# libgomp1 for tfjs-node's OpenMP runtime.
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates ffmpeg openssl libgomp1 \
&& rm -rf /var/lib/apt/lists/*
ENV NODE_ENV=production
ENV PORT=4000
# Reuse the builder's fully-installed node_modules (tfjs native binary + devDeps
# such as swagger-ui-express that the NODE_ENV=development compose run enables),
# plus the compiled output and Prisma client/schema.
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/package.json ./package.json
# Non-root user + writable runtime dirs (winston file transport writes /app/logs).
RUN groupadd -g 1001 nodejs && useradd -u 1001 -g nodejs -m nodejs \
&& mkdir -p /app/logs /app/uploads && chown -R nodejs:nodejs /app
USER nodejs
EXPOSE 4000
HEALTHCHECK --interval=30s --timeout=3s --start-period=15s --retries=3 \
CMD node -e "require('http').get('http://localhost:' + (process.env.PORT || 4000) + '/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
CMD ["node", "dist/index.js"]