FROM node:lts-alpine

# Pull in noonian tgz (built from "npm pack" command) and install globally

RUN mkdir /install
COPY noonian*.tgz /install/

RUN npm install -g bower 
RUN npm install --unsafe-perm -g /install/noonian*.tgz

RUN rm -rf /install/


# /instances holds all noonian instances;
#  running container should bind it to host filesystem

RUN mkdir /instances
RUN chown node:node /instances

VOLUME /instances


# Install git (dependency of bower; can remove this line when noonian no longer uses bower)
RUN apk update && apk add git


# container-startup.sh runs as node user; can run as root when bower goes away
# (bower requirement - needs to run as non-root)

COPY container-startup.sh /
RUN chmod +x /container-startup.sh

CMD ["su", "node", "-c", "/container-startup.sh"]