File size: 2,439 Bytes
9375c52
 
 
 
 
 
 
 
 
 
 
 
f4efb47
 
9375c52
 
 
4ec430d
 
 
9375c52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0bc275b
90fbaf5
db05528
9375c52
0bc275b
9375c52
 
4c0ed1a
9375c52
 
 
aa7f8c3
9375c52
 
aa7f8c3
 
9375c52
 
 
aa7f8c3
0bc275b
 
9375c52
 
 
aa7f8c3
9375c52
aa7f8c3
 
0bc275b
9375c52
 
 
4ec430d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# 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"]