### STAGE 1: Build ###
FROM node:18.17.1 AS build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build --prod

### STAGE 2: Deploy ###
FROM nginx:latest
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install iputils-ping -y
COPY --from=build /app/dist/frontend /usr/share/nginx/html
COPY nginx.conf.template /etc/nginx/nginx.conf.template
COPY docker-entrypoint.sh /app-entrypoint.sh

RUN chmod +x /app-entrypoint.sh

ENTRYPOINT [ "/app-entrypoint.sh" ]

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]