Files
butcem/Dockerfile
T
suphicakir 7d7dd61c60 feat(deploy): konteyner başlatma adımı ve sağlık kontrolünde replica set
- scripts/bootstrap.ts: replica set/PRIMARY kontrolü, migration'lar, production'da ilk admin
- esbuild ile tek dosya (dist/bootstrap.mjs), docker-entrypoint.sh ile uygulamadan önce
- /api/health yanıtında replicaSet alanı; healthcheck başlangıç payı 60 sn

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 02:13:10 +03:00

60 lines
2.3 KiB
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# syntax=docker/dockerfile:1
# BÜTÇEM — çok aşamalı üretim imajı (Next.js standalone çıktı).
# Build: docker build --build-arg APP_COMMIT=$(git rev-parse --short HEAD) -t butcem .
# Çalıştır: docker run -p 3000:3000 --env-file .env.production -v butcem-uploads:/app/uploads butcem
# Başlarken: replica set kontrolü, bekleyen migration'lar, ilk admin (docker-entrypoint.sh).
ARG NODE_VERSION=26
# 1) Bağımlılıklar — yalnızca lock dosyası değişince yeniden çalışır.
FROM node:${NODE_VERSION}-alpine AS deps
WORKDIR /app
RUN apk add --no-cache libc6-compat
COPY package.json package-lock.json ./
RUN npm ci --no-audit --no-fund
# 2) Build
FROM node:${NODE_VERSION}-alpine AS builder
WORKDIR /app
ARG APP_VERSION=""
ARG APP_COMMIT="unknown"
ENV NEXT_TELEMETRY_DISABLED=1 \
APP_VERSION=${APP_VERSION} \
APP_COMMIT=${APP_COMMIT}
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Uygulama + başlatma betiği (migration ve ilk admin; tek dosya, tsx gerekmez).
RUN npm run build && npm run build:scripts
# 3) Çalışma zamanı — yalnızca standalone çıktı, root olmayan kullanıcı.
FROM node:${NODE_VERSION}-alpine AS runner
WORKDIR /app
ARG APP_VERSION=""
ARG APP_COMMIT="unknown"
ENV NODE_ENV=production \
NEXT_TELEMETRY_DISABLED=1 \
PORT=3000 \
HOSTNAME=0.0.0.0 \
UPLOAD_DIR=/app/uploads \
APP_VERSION=${APP_VERSION} \
APP_COMMIT=${APP_COMMIT}
RUN addgroup -S -g 1001 nodejs && adduser -S -u 1001 -G nodejs nextjs \
&& mkdir -p /app/uploads && chown nextjs:nodejs /app/uploads
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/dist/bootstrap.mjs ./scripts/bootstrap.mjs
COPY --chown=nextjs:nodejs --chmod=755 docker-entrypoint.sh ./docker-entrypoint.sh
USER nextjs
VOLUME ["/app/uploads"]
EXPOSE 3000
# start-period: ilk deploy'da migration'lar için pay.
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
CMD node -e "fetch('http://127.0.0.1:'+(process.env.PORT||3000)+'/api/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
ENTRYPOINT ["/app/docker-entrypoint.sh"]