FROM mhart/alpine-node:8.9.0

# need to install Bash as it doenst port with this image
RUN apk add --no-cache bash

#change to tmp folder this helps caching npm pakages for faster build next time
WORKDIR /tmp
COPY package.json /tmp/
COPY package-lock.json /tmp/
RUN npm config set registry http://registry.npmjs.org/ && npm install

#SET working dir and copy files to it
WORKDIR /usr/src/app
COPY . /usr/src/app/

# LOGS VOLUME 
VOLUME ["/var/log/whatsapp-api/", "/usr/src/whatsapp-api/public"]

#copy node_modules folder from tmp 
RUN cp -a /tmp/node_modules /usr/src/app/

ARG NODE_ENV=staging
ENV NODE_ENV=${NODE_ENV}

#DEFAULT IS SET TO dev url
ARG APP_URL=https://whatsapp-api-staging.eu-staging.kacdn.net
ENV APP_URL=${APP_URL}

RUN echo ${NODE_ENV} ${APP_URL}

#expose port 
EXPOSE 3000

#strat the app
CMD [ "node", "server" ]

