# Install dependencies only when needed
FROM node:16-alpine
RUN apk add --no-cache libc6-compat

WORKDIR /app

ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1

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

RUN ls -a

COPY .next/ .next/
COPY public/ public/
COPY node_modules/ node_modules/
COPY package.json package.json

RUN ls -a
RUN ls -a .next

RUN chown -R nextjs:nodejs .next

USER nextjs

EXPOSE 3000

ENV PORT 3000

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