FROM node:25-alpine3.22 AS frontend-build
WORKDIR /app

COPY src/frontend/family-tree-ui/package*.json ./
RUN npm ci

COPY src/frontend/family-tree-ui/ ./
RUN npm run build -- --configuration production

FROM nginx:1.29.6-alpine AS runtime

RUN apk add --no-cache gettext

COPY deploy/nginx/default.conf /etc/nginx/conf.d/default.conf
COPY deploy/nginx/env-config.js.template /etc/family-tree/env-config.js.template
COPY --from=frontend-build /app/dist/family-tree-ui/browser /usr/share/nginx/html

EXPOSE 8080

CMD ["/bin/sh", "-c", "envsubst '$APP_API_BASE_URL' < /etc/family-tree/env-config.js.template > /usr/share/nginx/html/env-config.js && exec nginx -g 'daemon off;'"]
