FROM node:14.17.5-alpine3.14

ARG VERSION
ARG SERVER_PORT

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/server

RUN npm install;

RUN apk update; \
    apk add openssh-keygen; \
    apk add openssl; \
    mkdir -p assets/keys; \
    cd assets/keys; \
    ssh-keygen -t rsa -b 4096 -f ./jwt.key -m pem; \
    openssl rsa -in ./jwt.key -pubout -out ./jwt.key.pub;

EXPOSE ${SERVER_PORT}

ADD ./entry.sh /

ENTRYPOINT [ "/bin/sh", "/entry.sh" ]

CMD npm run start
