FROM node:22.23.4-alpine
RUN apk update && apk upgrade --no-cache && apk add --no-cache libc6-compat openssl
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH

# On copie tout, on installe tout, on build tout au même endroit
COPY . .
RUN npm ci
RUN npx prisma generate
RUN npm run build

EXPOSE 3000

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
RUN chown -R nextjs:nodejs /app

USER nextjs

HEALTHCHECK --interval=15s --timeout=5s --start-period=30s --retries=5 \
  CMD wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1

# On lance directement via npm
CMD ["npm", "start"]
