FROM node:22-alpine AS build
WORKDIR /app

COPY package.json package-lock.json ./
RUN npm ci

COPY . .
# NEXT_PUBLIC_ variables are inlined into the client bundle at build time,
# so the API base URL is provided as a build argument.
ARG NEXT_PUBLIC_API_BASE=http://localhost:8000
ENV NEXT_PUBLIC_API_BASE=$NEXT_PUBLIC_API_BASE

RUN npm run build

FROM node:22-alpine
WORKDIR /app
ENV NODE_ENV=production

COPY --from=build /app/.next/standalone ./
COPY --from=build /app/.next/static ./.next/static
COPY --from=build /app/public ./public

# Next.js standalone ships a stock `node` user (uid 1000); the server binds
# 3000 and writes nothing at runtime.
USER node

EXPOSE 3000

CMD ["node", "server.js"]
