#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 
# build/llo-base-images/asciidoctor-alpine/docker-asciidoctor
RUN apk add --no-cache \
    bash \
    curl \
    nginx \
    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

# # Copy hello-cron file to the cron.d directory
COPY bootstrap-cron.sh  /etc/cron.d/playground-cron

# Give execution rights on the cron job
RUN chmod 0744 /etc/cron.d/playground-cron

# Apply cron job
RUN crontab /etc/cron.d/playground-cron


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
ADD mpi_bootstrap /usr/local/bin
ADD startup.sh /home/node

ADD ttyd /usr/bin
ADD ssl-ttyd /home/node/ssl-ttyd

RUN mkdir -p /home/node/log \
&& mkdir -p  /home/node/crond \
&& mkdir -p  /home/node/run \
&& mkdir -p /run/nginx \
&& npm install pm2@latest -g  \
&& chmod -R 755 /home/node \
&& chmod +x /usr/local/bin/mpi_bootstrap \
&& chmod +x /home/node/startup.sh \
&& chown -R node.node /home/node 

WORKDIR /home/node
VOLUME  /home/node

EXPOSE 443 8088 3000

CMD ["/usr/bin/supervisord", "-c", "/home/node/startup.sh"]