# Compose: static image serving an already-built site (node scripts/assemble-site.mjs -> dist/site).
# SPDX-License-Identifier: GPL-3.0-or-later
#   docker build -t compose .        (the context only needs dist/site and deploy/, see .dockerignore)
FROM docker.io/nginxinc/nginx-unprivileged:1.29-alpine

USER root
RUN rm -rf /usr/share/nginx/html/* /etc/nginx/conf.d/*
COPY deploy/nginx.conf /etc/nginx/nginx.conf
COPY deploy/compose-headers.conf deploy/compose-immutable.conf /etc/nginx/
COPY deploy/compose-start.sh /compose-start.sh
COPY --chown=0:0 dist/site/ /usr/share/nginx/html/
# config.json is generated at start from COMPOSE_ALLOWED_ORIGINS; never ship a build-time (maybe dev) one
RUN rm -f /usr/share/nginx/html/config.json* && rm -rf /usr/share/nginx/html/tmp-test \
 && chmod 0755 /compose-start.sh && chmod -R a+rX /usr/share/nginx/html

USER 101
EXPOSE 8080
ENV COMPOSE_ALLOWED_ORIGINS="https://rehearsalroom.music https://rehearsal.heyludo.casa"
HEALTHCHECK --interval=30s --timeout=3s CMD wget -q -O /dev/null http://127.0.0.1:8080/healthz || exit 1
CMD ["/compose-start.sh"]
