FROM node:12.4.0

# Update Sources, Install Nginx, Remove Default Page
RUN apt-get update
RUN apt-get install -y nginx
RUN rm -rf /var/www/html/index.nginx-debian.html

# Make Directory To Store Files
RUN mkdir -p /build
WORKDIR /build

# Install Packages
# This is done first so that it gets cached if package.json doesn't change
COPY package.json /build/package.json
RUN npm install
# TODO: Change from NPM to Yarn. For some reason it's erroring when building prod
# RUN yarn install

# Build Production Files
COPY . /build
RUN npm run deploy:prod

# # Copy the contents of the dist directory over to the nginx web root
RUN mv /build/dist/* /var/www/html/

# Expose the web port
EXPOSE 80

# Run Nginx
CMD ["nginx", "-g", "daemon off;"]
