# NOTE: Multi-stage builds require Docker v17.05 or later.

# create the build environment
FROM node:18-alpine3.15 AS build
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
RUN npm install react-scripts@5.0.1 --location=global
COPY package.json /app/package.json
RUN npm install
COPY . /app/
ARG ENABLE_TESTS
COPY docker/env /app/.env
RUN if [ -n "$ENABLE_TESTS" ]; then echo -e "\nREACT_APP_TEST_MODE=1" >>/app/.env ; fi
RUN npm run build

# create the final target image
FROM nginx:1.21.6-alpine
COPY docker/nginx-default.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/build /usr/share/nginx/html
EXPOSE 80
CMD [ "nginx", "-g", "daemon off;" ]
