# syntax=docker/dockerfile:1.7-labs # 3-stage build: clone source → install deps → runtime # Source is pulled from a private GitHub repo at build time. # Both GITHUB_TOKEN and GIT_REPO are build secrets — neither appears in the image. ARG PYTHON_VERSION=3.11 ARG GIT_REF=main # ── Stage 1: Clone source from private repo ────────────────────────── FROM python:${PYTHON_VERSION}-slim AS source ARG GIT_REF RUN apt-get update && apt-get install -y --no-install-recommends \ ca-certificates \ git \ git-lfs \ && rm -rf /var/lib/apt/lists/* \ && git lfs install WORKDIR /src RUN --mount=type=secret,id=GITHUB_TOKEN,mode=0444,required=true \ --mount=type=secret,id=GIT_REPO,mode=0444,required=true \ token="$(cat /run/secrets/GITHUB_TOKEN)" && \ repo="$(cat /run/secrets/GIT_REPO)" && \ git clone --depth 1 --branch "${GIT_REF}" \ "https://x-access-token:${token}@${repo#https://}" app && \ rm -rf /src/app/.git # ── Stage 2: Runtime ───────────────────────────────────────────────── FROM python:${PYTHON_VERSION}-slim ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ UV_LINK_MODE=copy \ HF_HOME=/data/.cache/huggingface \ SEKAI_HOST=0.0.0.0 \ SEKAI_PORT=7860 \ PGDATA=/data/postgres \ PGHOST=/tmp \ PATH="/usr/lib/postgresql/17/bin:$PATH" # Install PostgreSQL 17 and uv RUN apt-get update && apt-get install -y --no-install-recommends \ ca-certificates \ postgresql-17 \ && rm -rf /var/lib/apt/lists/* \ && pip install --no-cache-dir uv # Create sekai user (1000) and set up all required directories (including /app!) RUN groupadd -g 1000 sekai \ && useradd -m -u 1000 -g sekai sekai \ && mkdir -p /data/postgres /data/.cache /var/run/postgresql /app \ && chown -R sekai:sekai /data /var/run/postgresql /app WORKDIR /app # Copy files (the --chown ensures the files inside are also owned by sekai) COPY --from=source --chown=sekai:sekai /src/app /app COPY --chown=sekai:sekai entrypoint.sh /app/entrypoint.sh RUN chmod +x /app/entrypoint.sh # IMPORTANT: Switch to the sekai user right here USER sekai # Now uv sync will run as sekai and have full permission to create /app/.venv RUN uv sync --frozen --no-dev EXPOSE 7860 ENTRYPOINT ["/app/entrypoint.sh"]