# Step #1: build the React front end FROM node:14-bullseye-slim as build-step WORKDIR /app ENV PATH /app/node_modules/.bin:$PATH RUN mkdir ./frontend COPY ./frontend/package.json ./frontend/package-lock.json ./frontend/ WORKDIR /app/frontend RUN npm install -g npm@8.5.4 # It's OK to have multiple consecutive `RUN` instructions. # hadolint ignore=DL3059 RUN npm install WORKDIR /app COPY ./frontend ./frontend WORKDIR /app/frontend RUN npm run build # Step #2: set up the Python backend and Nginx FROM python:3.10.13-slim-bullseye RUN apt-get update && apt-get install -y nginx procps \ && rm -rf /var/lib/apt/lists/* RUN python3 -m pip install --upgrade pip \ && pip install gunicorn==20.1.0 # Copy backend code and install dependencies COPY ./backend ./backend RUN pip install -r ./backend/requirements.txt # Ensure necessary permissions and create directories RUN mkdir -p /var/log/nginx && \ touch /var/log/nginx/error.log && \ touch /var/log/nginx/access.log && \ chmod -R 777 /var/log/nginx && \ chown -R root:root /var/log/nginx && \ chmod -R 777 /var/lib/nginx && \ chown -R root:root /var/lib/nginx && \ chmod -R 777 /usr/share/nginx/html && \ chown -R root:root /usr/share/nginx/html && \ mkdir -p /run && \ chmod -R 777 /run # Step #3: Configure nginx and flask COPY --from=build-step /app/frontend/build /usr/share/nginx/html COPY deployment/docker/nginx.conf /etc/nginx/nginx.conf COPY deployment/docker/serve.sh /serve.sh RUN chmod a+x /serve.sh # Remove the user directive if present RUN sed -i '/^user /d' /etc/nginx/nginx.conf EXPOSE 80 # Run as root user USER root ENTRYPOINT ["/bin/bash"] CMD ["/serve.sh"]