# syntax=docker/dockerfile:1

FROM node:22-alpine AS builder

WORKDIR /app

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

COPY . .
RUN npm run build

FROM nginx:1.27-alpine

RUN apk add --no-cache nodejs

COPY --from=builder /app/dist /usr/share/nginx/html
COPY scripts/generate-config.js /docker/generate-config.js
COPY docker/nginx.conf /etc/nginx/conf.d/default.conf
COPY docker/entrypoint.sh /docker/entrypoint.sh

RUN chmod +x /docker/entrypoint.sh \
  && sed -i 's/\r$//' /docker/entrypoint.sh

EXPOSE 80

ENTRYPOINT ["/docker/entrypoint.sh"]
