### THIS FILE IS A REPLICA FROM ORCHESTRATOR-CORE-GUI WITH SOME ADJUSTMENTS

###############################
### BASE LAYER FOR IMAGES BELOW
FROM node:14.21.1-slim AS base

ENV CI=true
ENV CORE_GUI_TAG=10.7.6

WORKDIR /app
RUN apt update && apt install git -y
RUN git clone --branch 10.7.6 https://github.com/workfloworchestrator/orchestrator-core-gui.git --depth 1

###########################################
### BUILDER LAYER TO PREPARE FOR PRODUCTION
FROM base AS builder

WORKDIR /app/orchestrator-core-gui
RUN yarn --network-concurrency 1 --frozen-lockfile
RUN rm -rf src/custom

# Apply GÉANT customisations
COPY custom src/custom
COPY logo.svg src/images/logo.svg
COPY favicon.ico public/favicon.ico
COPY colors.ts src/stylesheets/emotion/colors.ts
COPY src/utils/policy.ts src/utils/policy.ts

RUN yarn build

########################
### IMAGE FOR PRODUCTION
FROM nginx:alpine

WORKDIR /app
RUN apk update && apk add wget curl
COPY --from=builder /app/orchestrator-core-gui/default.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /app/orchestrator-core-gui/build /usr/share/nginx/html
COPY --from=builder /app/orchestrator-core-gui/src/env.js.template .
COPY --from=builder /app/orchestrator-core-gui/src/custom/custom_env.js.template .

EXPOSE 8080
CMD [ "/bin/ash", "-c", "envsubst < env.js.template > /usr/share/nginx/html/env.js && envsubst < custom_env.js.template >> /usr/share/nginx/html/env.js && exec nginx -g 'daemon off;'"]