# syntax=docker/dockerfile:1
# Build stage: regenerate the static site from source data.
FROM python:3.12-slim AS build
WORKDIR /app
COPY . .
RUN python3 generate_dashboard.py

# Serve stage: nginx serves the generated static files.
FROM nginx:alpine
# Replace the default nginx server block so root redirects to the dashboard
RUN printf '%s\n' \
    'server {' \
    '    listen 80;' \
    '    server_name _;' \
    '    root /usr/share/nginx/html;' \
    '    index dashboard.html;' \
    '    location = / { return 302 /dashboard.html; }' \
    '}' > /etc/nginx/conf.d/default.conf
COPY --from=build /app/dashboard.html /usr/share/nginx/html/dashboard.html
COPY --from=build /app/pages         /usr/share/nginx/html/pages
EXPOSE 80
