Spaces:
Running
Running
William Mattingly commited on
Commit Β·
fc77a0b
1
Parent(s): e576673
Refactor Dockerfile for improved clarity and usage instructions
Browse files- Simplified comments and updated usage instructions for local and HuggingFace Spaces deployment.
- Adjusted database handling instructions and default command for running the application.
- Removed unnecessary user creation and streamlined dependency installation process.
- Dockerfile +28 -59
Dockerfile
CHANGED
|
@@ -1,80 +1,49 @@
|
|
| 1 |
-
# ββ Scripture Detector
|
| 2 |
#
|
| 3 |
-
#
|
| 4 |
-
# βββββββββββββββββββββββββββ
|
| 5 |
-
# 1. Push this repo to a HF Space (Docker SDK).
|
| 6 |
-
# 2. Add the following secrets in Space Settings β Variables and secrets:
|
| 7 |
-
# SD_SECRET_KEY β any long random string, e.g. `openssl rand -hex 32`
|
| 8 |
-
# GEMINI_API_KEY β your Google AI Studio key (optional; can be set in-app)
|
| 9 |
-
#
|
| 10 |
-
# Local usage (standard)
|
| 11 |
-
# ββββββββββββββββββββββ
|
| 12 |
# docker build -t scripture-detector .
|
| 13 |
-
# docker run -p 7860:7860 scripture-detector
|
| 14 |
#
|
| 15 |
-
#
|
| 16 |
-
#
|
| 17 |
-
#
|
| 18 |
-
#
|
|
|
|
|
|
|
| 19 |
# -e SD_DB_DIR=/app/db \
|
| 20 |
-
# -e
|
| 21 |
-
# scripture-detector
|
|
|
|
|
|
|
|
|
|
| 22 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 23 |
|
| 24 |
FROM python:3.12-slim
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 28 |
-
git curl \
|
| 29 |
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
| 30 |
|
| 31 |
-
# ββ Non-root user (required by HuggingFace Spaces) βββββββββββββββββββββββββββ
|
| 32 |
-
RUN useradd -m -u 1000 user
|
| 33 |
WORKDIR /app
|
| 34 |
|
| 35 |
-
# ββ Install uv (fast Python package manager) βββββββββββββββββββββββββββββββββ
|
| 36 |
-
RUN pip install --no-cache-dir uv
|
| 37 |
|
| 38 |
-
#
|
| 39 |
-
|
| 40 |
-
|
| 41 |
|
| 42 |
-
#
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
# ββ Runtime environment βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 46 |
-
# Per-user in-memory database (each browser session gets its own isolated DB).
|
| 47 |
-
ENV SCRIPTURE_DETECTOR_CACHE_DB=1
|
| 48 |
|
| 49 |
-
#
|
| 50 |
-
|
| 51 |
-
ENV SD_BEHIND_PROXY=1
|
| 52 |
|
| 53 |
-
# Bind to all interfaces
|
| 54 |
ENV SD_HOST=0.0.0.0
|
| 55 |
ENV SD_PORT=7860
|
| 56 |
|
| 57 |
-
#
|
| 58 |
-
# If absent, a random key is generated at startup β sessions reset on redeploy.
|
| 59 |
-
|
| 60 |
-
# Gunicorn needs to see the app module
|
| 61 |
-
ENV PYTHONUNBUFFERED=1
|
| 62 |
-
|
| 63 |
-
# ββ Non-root user βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 64 |
-
USER user
|
| 65 |
-
|
| 66 |
EXPOSE 7860
|
| 67 |
|
| 68 |
-
#
|
| 69 |
-
#
|
| 70 |
-
|
| 71 |
-
# causing "I added a source but now it's gone" bugs.
|
| 72 |
-
CMD ["uv", "run", "gunicorn", \
|
| 73 |
-
"--worker-class", "gthread", \
|
| 74 |
-
"--workers", "1", \
|
| 75 |
-
"--threads", "4", \
|
| 76 |
-
"--bind", "0.0.0.0:7860", \
|
| 77 |
-
"--timeout", "120", \
|
| 78 |
-
"--access-logfile", "-", \
|
| 79 |
-
"--error-logfile", "-", \
|
| 80 |
-
"app:app"]
|
|
|
|
| 1 |
+
# ββ Scripture Detector ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 2 |
#
|
| 3 |
+
# Build:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
# docker build -t scripture-detector .
|
|
|
|
| 5 |
#
|
| 6 |
+
# Run (ephemeral in-memory database β data resets on container restart):
|
| 7 |
+
# docker run -p 5001:5001 scripture-detector
|
| 8 |
+
#
|
| 9 |
+
# Run (persistent database β mount a host directory):
|
| 10 |
+
# docker run -p 5001:5001 \
|
| 11 |
+
# -v "$(pwd)/data_volume:/app/db" \
|
| 12 |
# -e SD_DB_DIR=/app/db \
|
| 13 |
+
# -e GEMINI_API_KEY=your_key_here \
|
| 14 |
+
# scripture-detector python app.py
|
| 15 |
+
#
|
| 16 |
+
# The default CMD uses --cache-db (in-memory SQLite) which is ideal for
|
| 17 |
+
# workshops and demos where persistence across restarts is not needed.
|
| 18 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 19 |
|
| 20 |
FROM python:3.12-slim
|
| 21 |
|
| 22 |
+
# Install git (required by Hugging Face Spaces build system) and uv
|
| 23 |
+
RUN apt-get update && apt-get install -y --no-install-recommends git \
|
|
|
|
| 24 |
&& rm -rf /var/lib/apt/lists/*
|
| 25 |
+
RUN pip install --no-cache-dir uv
|
| 26 |
|
|
|
|
|
|
|
| 27 |
WORKDIR /app
|
| 28 |
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
# Copy dependency manifest first to leverage Docker layer caching.
|
| 31 |
+
# Dependencies are only re-installed when pyproject.toml / uv.lock changes.
|
| 32 |
+
COPY pyproject.toml uv.lock* ./
|
| 33 |
|
| 34 |
+
# Sync dependencies (no dev extras)
|
| 35 |
+
RUN uv sync --no-dev --frozen || uv sync --no-dev
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
# Copy application source
|
| 38 |
+
COPY . .
|
|
|
|
| 39 |
|
| 40 |
+
# Bind to all interfaces inside the container
|
| 41 |
ENV SD_HOST=0.0.0.0
|
| 42 |
ENV SD_PORT=7860
|
| 43 |
|
| 44 |
+
# Expose the Flask port
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
EXPOSE 7860
|
| 46 |
|
| 47 |
+
# Default: run with --cache-db (in-memory database, no volume needed).
|
| 48 |
+
# To use a persistent database instead, override CMD and set SD_DB_DIR.
|
| 49 |
+
CMD ["uv", "run", "python", "app.py", "--cache-db"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|