# ~~ Generated by cdk-nextjs ~~
# Modified from: https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile

# Production image, copy all the files and run next
FROM public.ecr.aws/docker/library/node:24-alpine AS runner
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app

ENV NODE_ENV=production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

ARG RELATIVE_PATH_TO_PACKAGE
# Copy from local build output instead of builder image
COPY --chown=nextjs:nodejs .next/standalone ./
# Copy public directory for image optimization (Next.js needs source images)
COPY --chown=nextjs:nodejs public ./$RELATIVE_PATH_TO_PACKAGE/public

USER nextjs

EXPOSE 3000

ENV PORT=3000

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
# CMD will be overwritten by ECS Task Definition
ENV HOSTNAME="0.0.0.0"
CMD ["node" "server.js"]