FROM node:18-alpine as react-build

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
COPY package*.json ./

# Bundle app source
COPY . .

# Install dependencies
RUN yarn

# Build
RUN yarn build

# Environment
FROM nginx:alpine
COPY nginx.conf /etc/nginx/conf.d/configfile.template
COPY --from=react-build /usr/src/app/build /usr/share/nginx/html

ENV PORT 3000
ENV HOST 0.0.0.0


# Expose port 3000
EXPOSE 3000

# Run the app
# CMD [ "npm", "start" ]
CMD sh -c "envsubst '\$PORT' < /etc/nginx/conf.d/configfile.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"