FROM python:3.9-slim

WORKDIR /app

# Copy requirements file if you have one
COPY requirements.txt .

RUN pip install --upgrade packaging
RUN pip install -r requirements.txt
# Install poetry
RUN pip install  --no-cache-dir "poetry<2.0.0"


# Copy .env file
COPY .env ./


# Copy only pyproject.toml and poetry.lock (if exists) first
COPY pyproject.toml ./
COPY poetry.lock* ./

# Configure poetry to not create a virtual environment inside the container
RUN poetry config virtualenvs.create false

# Install dependencies
RUN poetry install --no-dev --no-interaction --no-ansi

# Copy your project files
COPY . .

# Make the entrypoint script executable
COPY entrypoint.sh .
RUN chmod +x entrypoint.sh

RUN sed -i 's/\r$//' /app/entrypoint.sh
ENTRYPOINT ["/app/entrypoint.sh"]