# ==== CONFIGURE =====
# Use a Node 16 base image
FROM node:18.16-alpine as builder
# Set the working directory to /app inside the container

# Declare build argument
ARG REACT_APP_ENV=production

WORKDIR /app
# Copy app files
COPY frontend .

RUN mv .eslintrc_docker .eslintrc
RUN mv tsconfig.json_docker tsconfig.json

# COPY frontend/.eslintrc_docker .eslintrc
# COPY frontend/tsconfig.json_docker tsconfig.json

# Set environment variable based on build argument
ENV REACT_APP_ENV=${REACT_APP_ENV}

# ==== BUILD =====
# Install dependencies (npm ci makes sure the exact versions in the lockfile gets installed)
RUN npm ci 
# Build the app
# RUN npm run build
RUN SKIP_PREFLIGHT_CHECK=true DISABLE_TSC_COMPILE_ON_ERROR=true npm run build
# ==== RUN =======
# # Set the env to "staging"
# ENV NODE_ENV staging
# ENV REACT_APP_ENV=production
# # Expose the port on which the app will be running (3000 is the default that `serve` uses)
# EXPOSE 3000
# # Start the app
# CMD [ "npx", "serve", "build" ]

# ==== RUN WITH nginx ====
FROM nginx:1.19-alpine AS server
COPY ./frontend/etc/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=builder ./app/build /usr/share/nginx/html