Spaces:
Running
Running
deploy commited on
Commit ·
bb0af02
0
Parent(s):
Backend Space: build-time clone of private source (no source in repo)
Browse files- Dockerfile +34 -0
- README.md +16 -0
- start.sh +12 -0
Dockerfile
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# syntax=docker/dockerfile:1
|
| 2 |
+
FROM python:3.12-slim
|
| 3 |
+
|
| 4 |
+
RUN apt-get update \
|
| 5 |
+
&& apt-get install -y --no-install-recommends build-essential curl ca-certificates git \
|
| 6 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 7 |
+
|
| 8 |
+
# Hugging Face runs Spaces as uid 1000.
|
| 9 |
+
RUN useradd -m -u 1000 user
|
| 10 |
+
ENV HOME=/home/user \
|
| 11 |
+
PATH=/home/user/.local/bin:/app/.venv/bin:$PATH \
|
| 12 |
+
PYTHONUNBUFFERED=1 \
|
| 13 |
+
UV_LINK_MODE=copy \
|
| 14 |
+
UV_PROJECT_ENVIRONMENT=/app/.venv
|
| 15 |
+
|
| 16 |
+
RUN mkdir -p /app && chown user:user /app
|
| 17 |
+
USER user
|
| 18 |
+
WORKDIR /app
|
| 19 |
+
|
| 20 |
+
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
|
| 21 |
+
|
| 22 |
+
# Pull the private backend source at BUILD time using the GH_TOKEN build secret.
|
| 23 |
+
# Nothing sensitive (and no app source) is persisted in this public Space repo.
|
| 24 |
+
RUN --mount=type=secret,id=GH_TOKEN,uid=1000 \
|
| 25 |
+
git clone --depth 1 "https://x-access-token:$(cat /run/secrets/GH_TOKEN)@github.com/henryle97/teaching-bot" /tmp/src \
|
| 26 |
+
&& cp -r /tmp/src/backend/app /tmp/src/backend/engine /tmp/src/backend/worker \
|
| 27 |
+
/tmp/src/backend/pyproject.toml /tmp/src/backend/uv.lock /app/ \
|
| 28 |
+
&& rm -rf /tmp/src
|
| 29 |
+
|
| 30 |
+
RUN uv sync --frozen --no-install-project
|
| 31 |
+
|
| 32 |
+
COPY --chown=user:user start.sh /app/start.sh
|
| 33 |
+
EXPOSE 7860
|
| 34 |
+
CMD ["bash", "start.sh"]
|
README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Teaching Bot API
|
| 3 |
+
emoji: 📚
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: pink
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
+
pinned: false
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# Teaching-Bot — backend (API + worker)
|
| 12 |
+
|
| 13 |
+
FastAPI API + Arq worker in one always-on container. The application source is
|
| 14 |
+
**not** stored here — it is cloned from a private repository at build time via a
|
| 15 |
+
build secret (`GH_TOKEN`). Postgres on Supabase, Redis on Upstash. Runtime config
|
| 16 |
+
comes from Space **secrets**. Frontend lives on Vercel.
|
start.sh
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# Run the Arq worker and the FastAPI API in one container. If either exits, the
|
| 3 |
+
# script exits non-zero so the Space restarts the container (crash recovery).
|
| 4 |
+
set -uo pipefail
|
| 5 |
+
arq worker.arq_worker.WorkerSettings &
|
| 6 |
+
WORKER=$!
|
| 7 |
+
uvicorn app.main:app --host 0.0.0.0 --port 7860 &
|
| 8 |
+
API=$!
|
| 9 |
+
wait -n
|
| 10 |
+
echo "[start.sh] a process exited — stopping container for restart"
|
| 11 |
+
kill "$WORKER" "$API" 2>/dev/null || true
|
| 12 |
+
exit 1
|