#FROM alpine:3.11
FROM node:alpine

LABEL MAINTAINERS="Guillaume Scheibel <guillaume.scheibel@gmail.com>, Damien DUPORTAL <damien.duportal@gmail.com>"

# Installing package required for the runtime 
RUN apk add --no-cache \
    bash \
    curl \
    ca-certificates \
    findutils \
    font-bakoma-ttf \
    git \
    graphviz \
    inotify-tools \
    make \
    python3 \
    py3-pillow \
    py3-setuptools \
    tzdata \
    unzip \
    build-base \
    libxml2-dev \
    which \
    nginx

# Installing Python dependencies for additional
# functionnalities
RUN apk add --no-cache --virtual .pythonmakedepends \
    build-base \
    python3-dev \
    py3-pip \
  && pip3 install --no-cache-dir \
    actdiag \
    pip install supervisor supervisor-stdout \
    'blockdiag[pdf]' \
    nwdiag \
    seqdiag \
  && apk del -r --no-cache .pythonmakedepends


COPY dist /home/node/swarmlab-app
COPY src-local/llo /home/node/server/llo
COPY src-local/package.json /home/node/server/package.json

RUN mkdir -p /home/node/run \ 
&&   mkdir -p /home/node/logs \ 
&&   chown -R node.node /home/node \
&& chmod -R 755 /home/node \
&& ln -s /usr/local/bin/node /usr/bin/node \
&&   mkdir -p /run/nginx \ 
&& npm install pm2@latest -g


USER node

WORKDIR /home/node/server
RUN set -uex; \
    #   npm run build no need it!
    npm install; \
    npm i async chokidar url-exist-sync axios socketio-auth socket.io-client https socket.io bufferutil utf-8-validate  --save \
    npm audit fix; \
    npm cache clean --force;

WORKDIR /home/node/swarmlab-app
VOLUME  /home/node/swarmlab-app

EXPOSE 443 8080 3000

CMD ["pm2-runtime", "ecosystem.config.js"]