FROM node:6.9
MAINTAINER Dorian Pula <dorian.pula@amber-penguin-software.ca>

RUN wget https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb \
    && dpkg -i dumb-init_*.deb
RUN npm install --global --quiet \
    browserify \
    less \
    mocha \
    babel-cli \
    nightwatch

COPY package.json /app/rookeries/
WORKDIR /app/rookeries
RUN npm install --quiet

RUN mkdir -p /app/rookeries/dist/ \
    && mkdir -p /app/rookeries/static/js/
COPY static/ /app/rookeries/static/
COPY templates/ /app/rookeries/templates/
COPY src/ /app/rookeries/src/
COPY tests/ /app/rookeries/tests/
COPY .eslintrc.json /app/rookeries/
COPY nightwatch.conf.js /app/rookeries/
COPY nightwatch.json /app/rookeries/
COPY custom_commands/ /app/rookeries/custom_commands/

RUN chown www-data . --recursive \
    && chgrp www-data . --recursive \
    && chmod g+rw . --recursive

RUN npm run build
USER www-data
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["npm", "run", "start"]
EXPOSE 3000
