FROM python:3.10-slim

WORKDIR /app

# Install postgresql-client for pg_isready
RUN apt-get update && apt-get install -y \
    postgresql-client \
    && rm -rf /var/lib/apt/lists/*

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

# Copy the startup script and your application code
COPY . .

# Make the script executable
RUN chmod +x wait-for-postgres.sh

# Use the script as the entrypoint
ENTRYPOINT ["/app/wait-for-postgres.sh"]

# This is your application's original startup command
CMD ["python", "main.py"]