FROM python:3.10-slim

# Change the working directory to the root of the project
WORKDIR /srv/flask_app

# Install dependencies
RUN apt update && apt install -y python3 python3-pip curl nginx && rm -rf /var/lib/apt/lists/*

# Install the dependencies
COPY api/requirements.txt /srv/flask_app/
RUN pip install -r requirements.txt --src /usr/local/src --no-warn-script-location

# Copy the source code to the working directory
COPY api /srv/flask_app
COPY api/deploy/nginx.conf /etc/nginx

# Change file permissions
RUN chmod +x ./deploy/start.sh
RUN chmod +x ./deploy/healthcheck.sh

# Set healthcheck
HEALTHCHECK --interval=15s --timeout=2s CMD ["./deploy/healthcheck.sh"]

# Expose webserver port
EXPOSE 80

# Run the app
CMD ["./deploy/start.sh"]
