# Use the official Python 3.11 image from the Docker Hub
FROM python:3.11-slim

# Set the working directory inside the container
WORKDIR /app

# Copy the requirements file into the container
COPY ./requirements.txt .

# Install the required Python packages
RUN pip install --no-cache-dir -r requirements.txt

# Copy the .env file into the /app directory
# COPY ./.env /app/.env

# Copy the rest of the application code into the container
COPY . .

RUN chmod +x /app/cron_launch.sh

# Install cron
RUN apt-get update && apt-get install -y cron

# Add the cron job
# evry 10 min
# RUN echo "*/10 * * * * /usr/local/bin/python /app/main.py >> /var/log/cron.log 2>&1" > /etc/cron.d/your_cron_job
# 1 AM 
RUN echo "0 1 * * * /bin/bash /app/cron_launch.sh >> /var/log/cron.log 2>&1" > /etc/cron.d/your_cron_job

# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/your_cron_job

# Apply the cron job
RUN crontab /etc/cron.d/your_cron_job

# Create the log file to be able to run tail
RUN touch /var/log/cron.log

# Run the command on container startup
CMD cron && tail -f /var/log/cron.log