# Dockerfile for Dereth Tracker application
# Base image: lightweight Python runtime
FROM python:3.12-slim

## Set application working directory
WORKDIR /app

# Upgrade pip and install required Python packages without caching
RUN python -m pip install --upgrade pip && \
    pip install --no-cache-dir \
        fastapi \
        uvicorn \
        pydantic \
        websockets \
        databases[postgresql] \
        sqlalchemy \
        alembic \
        psycopg2-binary

## Copy application source code and migration scripts into container
COPY static/ /app/static/
COPY main.py /app/main.py
COPY db.py /app/db.py
COPY db_async.py /app/db_async.py
COPY alembic.ini /app/alembic.ini
COPY alembic/ /app/alembic/
COPY Dockerfile /Dockerfile
## Expose the application port to host
EXPOSE 8765

## Default environment variables for application configuration
ENV DATABASE_URL=postgresql://postgres:password@db:5432/dereth \
    DB_MAX_SIZE_MB=2048 \
    DB_RETENTION_DAYS=7 \
    DB_MAX_SQL_LENGTH=1000000000 \
    DB_MAX_SQL_VARIABLES=32766 \
    DB_WAL_AUTOCHECKPOINT_PAGES=1000 \
    SHARED_SECRET=your_shared_secret

## Launch the FastAPI app using Uvicorn
CMD ["uvicorn","main:app","--host","0.0.0.0","--port","8765","--reload","--workers","1"]
