56 lines
1.5 KiB
Docker
56 lines
1.5 KiB
Docker
FROM node:22-alpine AS base
|
|
|
|
# Dipendenze necessarie per Alpine (Prisma richiede OpenSSL)
|
|
RUN apk add --no-cache libc6-compat openssl
|
|
|
|
WORKDIR /app
|
|
|
|
# --- STAGE 1: Installazione Dipendenze ---
|
|
FROM base AS deps
|
|
# Copia solo i file dei pacchetti per sfruttare la cache di Docker
|
|
COPY package.json ./
|
|
# Usa 'npm ci' invece di 'install' per build riproducibili e più veloci
|
|
RUN npm install
|
|
|
|
# --- STAGE 2: Build dell'applicazione ---
|
|
FROM base AS builder
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
COPY . .
|
|
|
|
# Genera il client Prisma PRIMA del build
|
|
RUN npx prisma generate
|
|
|
|
# Disabilita la telemetria di Next.js durante il build
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
# Esegue il build (che userà output: standalone)
|
|
RUN npm run build
|
|
|
|
# --- STAGE 3: Immagine di Produzione (Runner) ---
|
|
FROM base AS runner
|
|
WORKDIR /app
|
|
|
|
ENV NODE_ENV=production
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
ENV PORT=3000
|
|
ENV HOSTNAME="0.0.0.0"
|
|
|
|
# Crea un utente non-root per sicurezza
|
|
RUN addgroup --system --gid 1001 nodejs
|
|
RUN adduser --system --uid 1001 nextjs
|
|
|
|
# Copia la cartella public (immagini, favicon, ecc.)
|
|
COPY --from=builder /app/public ./public
|
|
|
|
# --- GESTIONE PRISMA E STANDALONE ---
|
|
# Copia la cartella .next/standalone (il server ridotto)
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
|
# Copia gli asset statici (.next/static) nella posizione corretta
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
|
|
|
# Passa all'utente limitato
|
|
USER nextjs
|
|
|
|
EXPOSE 3000
|
|
|
|
CMD ["node", "server.js"]
|