# ----Multistage build [1] build [2] Copy -----
FROM node:lts-alpine3.14 as build
RUN apk update && \
apk upgrade && \
apk add --no-cache bash git openssh
RUN mkdir /app
WORKDIR /app
COPY package.json .
# installs npm,yarn
RUN npm install -g --force npm@latest yarn@latest
# creates node modules
RUN yarn install
# copy source files
COPY . .
# run build for production
RUN yarn build
# --------STAGE 2 - Server via NGINX-------
# nginx state for serving content
FROM nginx:alpine
# Set working directory to nginx asset directory
WORKDIR /usr/share/nginx/html
# Remove default nginx static assets
RUN rm -rf ./*
# Copy static assets over
COPY --from=build /app/build .
# Containers run nginx with global directives and daemon off
ENTRYPOINT ["nginx", "-g", "daemon off;"]