51 lines
1.4 KiB
Docker
51 lines
1.4 KiB
Docker
# Use a multi‑stage build for a Next.js app
|
||
|
||
# ---------- Builder stage ----------
|
||
FROM node:20-alpine AS builder
|
||
|
||
# Set working directory
|
||
WORKDIR /app
|
||
|
||
# Install dependencies (use package lock when present)
|
||
COPY shop/package*.json ./
|
||
RUN npm ci --omit=dev
|
||
# Install nodemailer for email sending
|
||
RUN npm install nodemailer
|
||
|
||
# Copy the source code
|
||
COPY shop/ .
|
||
|
||
# Build the production output
|
||
RUN npm run build
|
||
|
||
# ---------- Runtime stage ----------
|
||
FROM node:20-alpine AS runner
|
||
|
||
WORKDIR /app
|
||
|
||
# Copy only built assets and runtime dependencies
|
||
COPY --from=builder /app/.next ./.next
|
||
# Copy standalone server and static assets
|
||
COPY --from=builder /app/.next/standalone ./
|
||
COPY --from=builder /app/.next/static ./.next/static
|
||
# KORREKTUR: Kopiert den public-Ordner nur, wenn er wirklich existiert
|
||
COPY --from=builder /app/public* ./public
|
||
|
||
COPY --from=builder /app/package*.json ./
|
||
# KORREKTUR: Flexibles Kopieren der Next-Konfiguration (egal ob .js oder .mjs)
|
||
COPY --from=builder /app/next.config.* ./
|
||
# KORREKTUR: Optionale TS-Dateien über den Sternchen-Trick absichern
|
||
COPY --from=builder /app/tsconfig.jso* ./
|
||
COPY --from=builder /app/next-env.d.t* ./
|
||
# Install production dependencies (already installed in builder, but ensure they are present)
|
||
RUN npm ci --omit=dev
|
||
|
||
# Environment variables
|
||
ENV NODE_ENV=production
|
||
ENV PORT=3000
|
||
|
||
EXPOSE 3000
|
||
|
||
# Start the Next.js server (standalone)
|
||
CMD ["node", "server.js"]
|