FROM node:20-alpine as nodebuild

WORKDIR /ui

COPY frontend/fic/ .

RUN npm install --network-timeout=100000 && \
    sed -i 's!@popperjs/core/dist/esm/popper!@popperjs/core!' node_modules/sveltestrap/src/*.js node_modules/sveltestrap/src/*.svelte && \
    npm run build


FROM nginx:stable-alpine-slim

ENV FIC_BASEURL=/ \
    HOST_RECEIVER=receiver:8080 HOST_ADMIN=admin:8081 HOST_DASHBOARD=dashboard:8082 HOST_QA=qa:8083 \
    PATH_FILES=/srv/FILES PATH_STARTINGBLOCK=/srv/STARTINGBLOCK PATH_STATIC=/srv/htdocs-frontend PATH_SETTINGS=/srv/SETTINGSDIST PATH_TEAMS=/srv/TEAMS

EXPOSE 80

COPY configs/nginx-chbase.sh /docker-entrypoint.d/40-update-baseurl.sh

COPY configs/nginx/get-team/upstream.conf /etc/nginx/fic-get-team.conf
COPY configs/nginx/auth/none.conf /etc/nginx/fic-auth.conf
COPY configs/nginx/base/docker.conf /etc/nginx/templates/default.conf.template

COPY --from=nodebuild /ui/build/ /srv/htdocs-frontend
