FROM python:3.12-slim-bookworm

RUN apt-get update && apt-get -y install cron wget
RUN pip install --upgrade pip setuptools wheel

# For frontend CDN information
COPY ./frontend/package.json /root/frontend/package.json
COPY ./frontend/cdn-packages.json /root/frontend/cdn-packages.json

# Backend
COPY ./internal /root/internal
RUN pip install -r /root/internal/requirements.txt

# Download and chmod +x the executable
COPY ./tools/pull-executable.sh /root/tools/pull-executable.sh
RUN bash /root/tools/pull-executable.sh

# Set up script to clean up temporary and unused files everyday
RUN (crontab -l ; echo "0 0 * * * wget -O /root/cron.txt http://localhost:5000/cleanup") | crontab

EXPOSE 5000
WORKDIR /root/internal

# Set the entrypoint that will always be executed when the container starts
COPY ./tools/entrypoint.sh /root/tools/entrypoint.sh
RUN chmod +x /root/tools/entrypoint.sh
ENTRYPOINT ["/root/tools/entrypoint.sh"]