FROM docker.io/node:16 AS builder

ENV SAFETWITCH_BACKEND_DOMAIN SAFETWITCH_BACKEND_DOMAIN_PLACEHOLDER
ENV SAFETWITCH_INSTANCE_DOMAIN SAFETWITCH_INSTANCE_DOMAIN_PLACEHOLDER
ENV SAFETWITCH_HTTPS SAFETWITCH_HTTPS_PLACEHOLDER
ENV SAFETWITCH_DEFAULT_LOCALE SAFETWITCH_DEFAULT_LOCALE_PLACEHOLDER
ENV SAFETWITCH_FALLBACK_LOCALE SAFETWITCH_FALLBACK_LOCALE_PLACEHOLDER
ENV SAFETWITCH_DEFAULT_THEME SAFETWITCH_DEFAULT_THEME_PLACEHOLDER

WORKDIR /app

COPY ./ .
RUN npm i
RUN npm run build

FROM docker.io/nginx:alpine

COPY ./docker/nginx.conf /etc/nginx/nginx.conf

WORKDIR /app
COPY --from=builder /app/dist ./

COPY ./docker/init.sh /init.sh
RUN chmod +x /init.sh

ENTRYPOINT ["/init.sh"]
