# Multi-stage Dockerfile for building and running the Carbon Next.js app
# Stage 1: build
FROM node:18 AS builder
WORKDIR /app
ENV NODE_OPTIONS=--max_old_space_size=4096
# Enable Corepack and pin Yarn 1.x for deterministic builds
RUN corepack enable
RUN corepack prepare yarn@1.22.19 --activate
# Install dependencies using Yarn (lockfile-based)
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
# Copy the rest of the repository and build the project
COPY . .
RUN yarn build
# Stage 2: runtime
FROM node:18 AS runtime
WORKDIR /app
ENV NODE_ENV=production
# Copy built assets from builder
COPY --from=builder /app/.next /app/.next
COPY --from=builder /app/public /app/public
COPY --from=builder /app/next.config.js /app/next.config.js
COPY --from=builder /app/package.json /app/package.json
COPY --from=builder /app/yarn.lock /app/yarn.lock
# Install production dependencies only
RUN corepack enable
RUN corepack prepare yarn@1.22.19 --activate
RUN yarn install --frozen-lockfile --production
EXPOSE 3000
CMD ["yarn", "start"]