FROM alpine:3.24 AS pages
COPY captionninja/ /pages/
RUN cd /pages && rm -rf .git .gitignore .github relay scripts models *.md test-security-warning.html

FROM nginx:1.31.7-alpine
RUN apk add --no-cache bash curl jq \
    && mkdir -p /usr/share/nginx/models
COPY --from=pages /pages/ /usr/share/nginx/html/
COPY --chmod=0755 captionninja/scripts/download-bergamot-models.sh /usr/local/bin/download-bergamot-models
COPY --chmod=0755 web/40-translation-models.sh /docker-entrypoint.d/40-translation-models.sh
COPY web/default.conf.template /etc/nginx/templates/default.conf.template
ENV RELAY_UPSTREAM=captionninja-relay:8787 \
    CAPTION_UPSTREAM=caption-local:8765 \
    RELAY_URL= \
    CAPTURE_URL= \
    TRANSLATION_MODELS=all \
    MODELS_VERSION=0.3.4 \
    NGINX_ENVSUBST_FILTER=^(RELAY_|CAPTURE_|CAPTION_)
