#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

# 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

RUN ln -s /usr/local/bin/node /usr/bin/node

ADD supervisord.conf /etc/supervisor/supervisord.conf
ADD supervisord-iot.conf /etc/supervisor/conf.d/node-app.conf


COPY iot-swarm-example /home/node/iot-swarm-example/

RUN chown -R node.node /home/node \
&& chmod -R 755 /home/node

WORKDIR /home/node/iot-swarm-example
VOLUME  /home/node/iot-swarm-example

ENV NODE_PATH=/usr/local/lib/node_modules

USER node

RUN cd /home/node/iot-swarm-example/src/browser-client \
        set -uex; \
 	npm install \
    	npm cache clean --force \
	cd /home/node/iot-swarm-example/src/IoT \
 	npm install \
    	npm cache clean --force;


EXPOSE 8080 8088 8084 3081

CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]