diff --git a/Dockerfile b/Dockerfile index 43872c1..68c6d05 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,28 +1,35 @@ # Use official Node.js image as base -FROM node:18-alpine AS builder +# 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 . . -# Install git, get commit hash -RUN apk add --no-cache git \ - && git rev-parse --short HEAD > /app/git_commit_sha +# 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 -# The environment variable will be available during build if needed -# ENV GIT_COMMIT_SHA=$(cat /app/git_commit_sha) -RUN echo "Building with GIT_COMMIT_SHA=$(cat /app/git_commit_sha)" && npm run build +# 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 ---- -FROM node:18-alpine AS runner +# Use Node 20 for production as well to match builder +FROM node:20-alpine AS runner # Set working directory inside the container WORKDIR /app @@ -46,9 +53,8 @@ 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 -# Set GIT_COMMIT_SHA environment variable in the final image by reading the file -ENV GIT_COMMIT_SHA="$(cat /app/git_commit_sha)" - +# 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"] \ No newline at end of file