FROM nginx:1.27-alpine AS production

RUN apk add --no-cache gettext

# Remove default nginx config
RUN rm /etc/nginx/conf.d/default.conf

# Copy nginx configs from project root
COPY nginx.conf /etc/nginx/nginx.conf
COPY default.conf /etc/nginx/conf.d/default.conf

# Copy static assets
COPY assets/ /usr/share/nginx/html/assets/

# Templates + generator (rendered at container start)
COPY index.html.template site.webmanifest.template generate-from-env.sh /opt/agencja-ai/
RUN chmod +x /opt/agencja-ai/generate-from-env.sh

COPY docker-entrypoint.sh /docker-entrypoint.d/99-generate-from-env.sh
RUN chmod +x /docker-entrypoint.d/99-generate-from-env.sh

EXPOSE 80

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
    CMD wget -qO- http://localhost:80/ || exit 1
