FROM node:10-alpine

# Create app directory
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
WORKDIR /home/node/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
# Why this? --> take advantage of Docker’s caching and image layering by separating
# the copy of package.json and package-lock.json, containing the project’s listed
# dependencies, from the copy of the rest of the application code.
COPY package*.json ./

RUN npm install
# If you are building your code for production
# RUN npm ci --only=production

# Bundle app source
# Why this? --> run as the non-root node user with the appropriate permissions set
# on the application code and node_modules directories.
COPY --chown=node:node . .

EXPOSE 80 443

ENV WITHOUT_SSL FALSE
CMD ["sh", "-c", "node server.js WITHOUT_SSL=${WITHOUT_SSL}"]
