FROM nginx:1.21.1-alpine

ARG VERSION
ARG GRAPHQL_SERVER

ADD https://git.it-kimmig.de/akimmig/TurnenAufZeit/archive/v${VERSION}.zip /tmp.zip

RUN set -eux; \
    unzip -q /tmp.zip -d /; \
    rm -f /tmp.zip;

WORKDIR /turnenaufzeit/client

RUN apk update; \
    apk add nodejs; \
    apk add npm;

COPY ./.npmrc* /turnenaufzeit/client/

RUN if [[ -f "./.npmrc" ]]; then \
    echo "OK" > /dev/null; \
    else \
    sed -i 's/fontawesome-pro/fontawesome-free/g' ./src/main.js; \
    sed -i 's/fontawesome-pro/fontawesome-free/g' ./package.json; \
    fi;

RUN echo "export const GRAPHQLserver = '${GRAPHQL_SERVER}'" > ./src/env.js

RUN npm install; \
    npm run build;

RUN sed -i 's#root   /usr/share/nginx/html;#root   /turnenaufzeit/client/dist;#g' /etc/nginx/conf.d/default.conf; \
    sed -i 's#index  index.html index.htm;#try_files  $uri $uri/ /index.html;#g' /etc/nginx/conf.d/default.conf;

EXPOSE 80

#CMD [ "nginx", "-g", "daemon off;" ]