# Mr. Drew's Assignment Creator — production image.
# Build context is the repository root:  docker build -f docker/Dockerfile .
# (docker-compose.yml in this folder does that for you.)

FROM node:20-alpine AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci

FROM node:20-alpine AS build
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build

FROM node:20-alpine AS run
WORKDIR /app
ENV NODE_ENV=production HOSTNAME=0.0.0.0 PORT=3000
# Next.js "standalone" output: a self-contained server, no node_modules needed.
COPY --from=build /app/.next/standalone ./
COPY --from=build /app/.next/static ./.next/static
# The single-file database lives here — mounted as a volume by compose.
RUN mkdir -p /app/data && chown -R node:node /app
USER node
EXPOSE 3000
CMD ["node", "server.js"]
