44 lines
1.2 KiB
Docker
44 lines
1.2 KiB
Docker
|
|
# Stage 1: Base image
|
||
|
|
FROM node:22-alpine AS base
|
||
|
|
WORKDIR /app
|
||
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||
|
|
ARG NEXT_SERVER_ACTIONS_ENCRYPTION_KEY
|
||
|
|
ENV NEXT_SERVER_ACTIONS_ENCRYPTION_KEY=$NEXT_SERVER_ACTIONS_ENCRYPTION_KEY
|
||
|
|
|
||
|
|
# Stage 2: Install dependencies
|
||
|
|
FROM base AS deps
|
||
|
|
# Check if libc6-compat is needed for Alpine
|
||
|
|
RUN apk add --no-cache libc6-compat
|
||
|
|
COPY package.json package-lock.json ./
|
||
|
|
# Clean install exact production and dev dependencies required for the build
|
||
|
|
RUN npm ci
|
||
|
|
|
||
|
|
# Stage 3: Build the application
|
||
|
|
FROM base AS builder
|
||
|
|
# Copy node_modules from the deps stage
|
||
|
|
COPY --from=deps /app/node_modules ./node_modules
|
||
|
|
# Copy all project source code ( Tailwind v4 scans these files )
|
||
|
|
COPY . .
|
||
|
|
# Execute the production Next.js build
|
||
|
|
RUN npm run build
|
||
|
|
|
||
|
|
# Stage 4: Production runner
|
||
|
|
FROM base AS runner
|
||
|
|
ENV NODE_ENV=production
|
||
|
|
ENV PORT=3001
|
||
|
|
ENV HOSTNAME="0.0.0.0"
|
||
|
|
|
||
|
|
# Create a non-root system user for security
|
||
|
|
RUN addgroup -g 1001 -S nodejs
|
||
|
|
RUN adduser -S nextjs -u 1001
|
||
|
|
|
||
|
|
# Copy standalone build assets and public files
|
||
|
|
COPY --from=builder /app/public ./public
|
||
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||
|
|
|
||
|
|
USER nextjs
|
||
|
|
EXPOSE 3001
|
||
|
|
|
||
|
|
CMD ["node", "server.js"]
|