#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 \
    jq \
    nginx \
&& apk add -U wireguard-tools

# 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/ecosystem.config.js /home/node/swarmlab-app/ecosystem.config.js

#COPY src-local/llo /home/node/swarmlab-app/llo
#COPY src-local/package.json /home/node/swarmlab-app/package.json
#COPY src-local/hybrid /home/node/swarmlab-app/hybrid
#COPY src-local/instance /home/node/swarmlab-app/instance
#COPY src-local/logs /home/node/swarmlab-app/logs
#COPY src-local/myconfig /home/node/swarmlab-app/myconfig
#COPY src-local/start-server.sh /home/node/swarmlab-app/start-server.sh
#COPY src-local/stop-server.sh /home/node/swarmlab-app/stop-server.sh


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/swarmlab-app
#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 simple-git  --save \
#    npm audit fix; \
#    npm cache clean --force;
#
WORKDIR /home/node/swarmlab-app
VOLUME  /home/node/swarmlab-app

EXPOSE 80 443 8080 3000 3080

CMD ["pm2-runtime", "/home/node/swarmlab-app/ecosystem.config.js"]