FROM python:3.12-slim AS base

# System deps for cryptography (rust build) + keyring (dbus)
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        build-essential rustc cargo libffi-dev libssl-dev \
        libdbus-1-dev pkg-config && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Copy project and install from source (includes --unsafe-public CLI flag)
COPY pyproject.toml LICENSE README.md CHANGELOG.md ./
COPY src/ ./src/
RUN pip install --no-cache-dir .

# Viewer binds to 0.0.0.0 inside the container so the host can reach it
ENV GDRIVE_VIEWER_HOST=0.0.0.0
ENV GDRIVE_VIEWER_PORT=8765

# Config + data dirs live on mounted volumes
ENV GDRIVE_CONFIG_DIR=/data/config
ENV GDRIVE_DATA_DIR=/data/state

EXPOSE 8765

# webbrowser.open is a no-op inside the container (harmless)
ENTRYPOINT ["gdrive-organizer"]
CMD ["view", "--port", "8765", "--unsafe-public"]
