73 lines
2.0 KiB
Docker
73 lines
2.0 KiB
Docker
# ============================================
|
|
# Nele & Till Wedding Gallery
|
|
# Multi-stage Docker build
|
|
# ============================================
|
|
|
|
# --- Stage 1: Dependencies ---
|
|
FROM node:20.18-alpine AS deps
|
|
RUN apk add --no-cache libc6-compat python3 make g++
|
|
WORKDIR /app
|
|
|
|
COPY package.json package-lock.json ./
|
|
RUN npm ci
|
|
|
|
# --- Stage 2: Build ---
|
|
FROM node:20.18-alpine AS builder
|
|
WORKDIR /app
|
|
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
COPY . .
|
|
|
|
# Generate Prisma client
|
|
RUN npx prisma generate
|
|
|
|
# Build Next.js
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
RUN npm run build
|
|
|
|
# --- Stage 3: Production ---
|
|
FROM node:20.18-alpine AS runner
|
|
WORKDIR /app
|
|
|
|
ENV NODE_ENV=production
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
# Install runtime dependencies (ffmpeg for video, vips for sharp)
|
|
RUN apk add --no-cache \
|
|
ffmpeg \
|
|
vips-dev \
|
|
wget \
|
|
&& addgroup --system --gid 1001 nodejs \
|
|
&& adduser --system --uid 1001 nextjs
|
|
|
|
# Copy built application (standalone output)
|
|
COPY --from=builder /app/public ./public
|
|
COPY --from=builder /app/.next/standalone ./
|
|
COPY --from=builder /app/.next/static ./.next/static
|
|
COPY --from=builder /app/prisma ./prisma
|
|
|
|
# Copy additional node_modules needed at runtime (not bundled by standalone)
|
|
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
|
|
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
|
|
COPY --from=builder /app/node_modules/bullmq ./node_modules/bullmq
|
|
COPY --from=builder /app/node_modules/ioredis ./node_modules/ioredis
|
|
COPY --from=builder /app/node_modules/archiver ./node_modules/archiver
|
|
COPY --from=builder /app/node_modules/bcrypt ./node_modules/bcrypt
|
|
COPY --from=builder /app/node_modules/sharp ./node_modules/sharp
|
|
|
|
# Create directories for media and cache
|
|
RUN mkdir -p /media /cache/thumbnails /cache/previews /cache/download \
|
|
&& chown -R nextjs:nodejs /cache
|
|
|
|
USER nextjs
|
|
|
|
EXPOSE 3000
|
|
|
|
ENV PORT=3000
|
|
ENV HOSTNAME="0.0.0.0"
|
|
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
|
|
CMD wget -qO- http://localhost:3000/api/health || exit 1
|
|
|
|
CMD ["node", "server.js"]
|