# Dockerfile
FROM python:3.9-slim

# Set the working directory
WORKDIR /app

# Install git and clean up
RUN apt-get update -q && \
    apt-get install -y git && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Create data directory with proper permissions
RUN mkdir -p /app/data && chmod 755 /app/data

# Set safe directory
RUN RUN git config --global --add safe.directory '*'

# Clone the repository
RUN git init /app && git remote add origin https://git.epicsparrow.com/Anselme/perefouras.git && git fetch --depth 1 origin master && git reset --hard FETCH_HEAD

# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt

# give exec permissions to main
RUN chmod +x main.py

# Set data directory as volume mount point
VOLUME /app/data

# Command to update the repo and run the script
CMD ["sh", "-c", "cd /app && git fetch --depth 1 origin master && git reset --hard FETCH_HEAD && python main.py"]