Files
ember-market-frontend/Dockerfile
g cdf1dd187c Update Dockerfile for Next.js 16 and Node 20 compatibility
Switches base image to node:20-alpine for both build and production stages to ensure compatibility with Next.js 16 and Turbopack. Installs git earlier, improves commit hash retrieval with a fallback, increases memory for builds, and updates comments for clarity. GIT_COMMIT_SHA is now read from a file at runtime instead of being set as an environment variable.
2025-12-31 07:14:20 +00:00

60 lines
1.9 KiB
Docker

# Use official Node.js image as base
# Next.js 16 requires Node 18.17+ or Node 20+
# Using node:20-alpine for better compatibility with Next.js 16 and Turbopack
FROM node:20-alpine AS builder
WORKDIR /app
# Install git early for commit hash
RUN apk add --no-cache git
COPY package.json package-lock.json ./
# Install dependencies with increased memory limit for Next.js 16
RUN npm install --force
COPY . .
# Get commit hash (fallback to "unknown" if not in git repo)
RUN git rev-parse --short HEAD > /app/git_commit_sha 2>/dev/null || echo "unknown" > /app/git_commit_sha
ENV NEXT_PUBLIC_API_URL=/api
ENV SERVER_API_URL=https://internal-api.inboxi.ng/api
ENV API_BASE_URL=https://internal-api.inboxi.ng
ENV API_HOSTNAME=internal-api.inboxi.ng
# Build the Next.js application with increased memory for Turbopack
# Next.js 16 uses Turbopack by default which may need more memory
RUN echo "Building with GIT_COMMIT_SHA=$(cat /app/git_commit_sha)" && \
NODE_OPTIONS='--max_old_space_size=4096' NEXT_TELEMETRY_DISABLED=1 npm run build
# ---- Production Stage ----
# Use Node 20 for production as well to match builder
FROM node:20-alpine AS runner
# Set working directory inside the container
WORKDIR /app
RUN mkdir -p /app/public
# Copy only necessary files from builder
COPY --from=builder /app/package.json /app/package-lock.json ./
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/public ./public
# Copy commit hash file from builder stage
COPY --from=builder /app/git_commit_sha /app/git_commit_sha
EXPOSE 3000
ENV NODE_ENV=production
ENV NEXT_PUBLIC_API_URL=/api
ENV SERVER_API_URL=https://internal-api.inboxi.ng/api
ENV API_BASE_URL=https://internal-api.inboxi.ng
ENV API_HOSTNAME=internal-api.inboxi.ng
# Note: GIT_COMMIT_SHA will be read at runtime, not set as ENV
# The file is available at /app/git_commit_sha if needed
# Start Next.js server
CMD ["npm", "run", "start"]