FROM python:3.12-slim AS base

COPY --from=ghcr.io/astral-sh/uv:0.7 /uv /usr/local/bin/uv

WORKDIR /app

# Install dependencies first for layer caching.
COPY github-app/pyproject.toml github-app/uv.lock ./
RUN uv sync --system --frozen --no-cache

# Application code.
COPY github-app/github_app/ ./github_app/

# Template and plugin directories used at runtime.
COPY languages/ /languages/
COPY plugin/ /plugin/

ENV LANGUAGES_DIR=/languages
ENV PLUGIN_DIR=/plugin

# Run as non-root user.
RUN useradd --create-home --shell /bin/bash appuser \
    && mkdir -p /tmp/codeflash-workspaces \
    && chown appuser:appuser /tmp/codeflash-workspaces
USER appuser

EXPOSE 8000

CMD ["codeflash-service"]
