Files
pi-agent 0098d9ca4a
Deploy Staging / build (push) Failing after 14m49s
feat: auto-healing system — HEALTHCHECK, rate-limiter cleanup, auto-rollback CI, watchdog
- Dockerfile: add HEALTHCHECK (30s interval, 10s timeout, 3 retries)
- rate-limit.ts: auto-cleanup stale entries every 5 min (prevents memory leak)
- scripts/auto-heal.sh: watchdog for Synology cron — auto-restarts container,
  reloads nginx gateway, escalates on excessive failures
- CI workflow: auto-rollback on deploy failure (tags :rollback image,
  reverts if health check fails after deploy)
2026-06-28 02:52:11 +08:00

57 lines
2.2 KiB
Docker

# ── Falah Mobile — Production Dockerfile ──────────────────────────────
# Requires npm run build to be run first on the host (Next.js standalone)
# Build sequence:
# cd /app && npm ci && npm run build
# docker build -t falah-mobile:latest .
FROM node:20-alpine
RUN apk add --no-cache openssl ca-certificates curl
WORKDIR /app
RUN addgroup --system --gid 1001 nodejs && adduser --system --uid 1001 nextjs
# Copy standalone build (pre-built outside Docker)
COPY .next/standalone/ ./
COPY .next/static ./.next/static
COPY public ./public
# Copy all production node_modules from build context
# (pre-installed via npm ci --omit=dev before docker build)
COPY node_modules ./node_modules
COPY prisma ./prisma
# Fix Turbopack's hashed Prisma client path (if .next inside standalone)
RUN if [ -d "/app/.next/node_modules/@prisma" ]; then \
for d in /app/.next/node_modules/@prisma/client-*; do \
name=$(basename "$d"); \
rm -f "/app/node_modules/@prisma/$name" 2>/dev/null; \
cp -r /app/node_modules/@prisma/client "/app/node_modules/@prisma/$name"; \
done; \
fi
RUN mkdir -p /app/data && chown nextjs:nodejs /app/data
# Fix permissions so nextjs user can run prisma CLI and read schema
RUN chown -R nextjs:nodejs /app/node_modules/@prisma /app/node_modules/prisma /app/node_modules/.prisma /app/prisma 2>/dev/null || true
# Startup script — migrate volumes DB then launch server
RUN printf '#!/bin/sh\n\
cd /app\n\
node ./node_modules/prisma/build/index.js db push --skip-generate --accept-data-loss 2>&1\n\
# Force 0.0.0.0 binding (Docker sets HOSTNAME to container ID)\nexport HOSTNAME=0.0.0.0\nexec node server.js\n' > /app/start.sh && chmod +x /app/start.sh
# ── Docker HEALTHCHECK ──────────────────────────────────────────
# Auto-restarts container if health endpoint fails 3 times (30s interval, 10s timeout)
HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
CMD curl -sf http://localhost:3000/mobile/api/health || exit 1
USER nextjs
EXPOSE 3000
ENV NODE_ENV=production
ENV DATABASE_URL="file:/app/data/dev.db"
CMD ["/app/start.sh"]