Spaces:
Running
Running
Download Dockerfile from gamer-forums/archive: direct link, hf CLI and curl.
- Browser
- Download file 2.6 kB
-
https://huggingface.co/spaces/gamer-forums/archive/resolve/main/Dockerfile
- Command line
-
hf download hf://spaces/gamer-forums/archive/Dockerfile
-
curl -L -o Dockerfile https://huggingface.co/spaces/gamer-forums/archive/resolve/main/Dockerfile
2.6 kB
| # gamer.co.il archive search β Hugging Face Spaces (Docker SDK) | |
| # | |
| # Layout at runtime: | |
| # - server.py + static/ (app, shipped in the Space repo) | |
| # - avatars/ (~36 MB, shipped in the Space repo) | |
| # - forum_emojis/ (~120 KB, shipped in the Space repo) | |
| # - posts.db (~24 GB, fetched from a separate HF Dataset | |
| # repo at image-build time β the Space repo | |
| # free-tier cap is 1 GB so the DB cannot live | |
| # alongside the app) | |
| # | |
| # Layer order is tuned for HF's build cache: everything stable comes first, | |
| # small volatile things (app code) last. Editing server.py only re-runs | |
| # the COPY layer, not the 24 GB DB fetch or the chown. | |
| # | |
| # Read-only at request time; no writes happen at runtime. | |
| FROM python:3.11-slim | |
| ENV PYTHONDONTWRITEBYTECODE=1 \ | |
| PYTHONUNBUFFERED=1 \ | |
| PIP_DISABLE_PIP_VERSION_CHECK=1 \ | |
| PIP_NO_CACHE_DIR=1 | |
| # zstd: <1 MB, used to decompress the chunked DB. | |
| RUN apt-get update && apt-get install -y --no-install-recommends zstd \ | |
| && rm -rf /var/lib/apt/lists/* | |
| WORKDIR /app | |
| # 1. Dependencies β cached unless requirements.txt changes. | |
| COPY requirements.txt . | |
| RUN pip install -r requirements.txt | |
| # 2. The big DB layer β cached unless DB_REPO / DB_REVISION changes. | |
| # Pull the chunked, zstd-compressed posts.db from the dataset repo and | |
| # reassemble. Files end up readable by everyone (default 0644) so the | |
| # non-root user added below doesn't need them chowned. | |
| ARG DB_REPO=gamer-forums/archive-db | |
| ARG DB_REVISION=main | |
| RUN python -c "from huggingface_hub import snapshot_download; \ | |
| snapshot_download(repo_id='${DB_REPO}', repo_type='dataset', revision='${DB_REVISION}', \ | |
| local_dir='/tmp/db-chunks', allow_patterns=['posts.db.zst.*'])" \ | |
| && cat /tmp/db-chunks/posts.db.zst.* | zstd -d -o /app/posts.db \ | |
| && rm -rf /tmp/db-chunks \ | |
| && chmod 0644 /app/posts.db \ | |
| && ls -lh /app/posts.db | |
| # 3. Non-root user β created BEFORE the small app COPYs so chown is fast. | |
| RUN useradd -m -u 1000 user | |
| # 4. Small static assets β only re-copied if the dirs change. | |
| COPY --chown=user:user avatars/ ./avatars/ | |
| COPY --chown=user:user forum_emojis/ ./forum_emojis/ | |
| # 5. App code last β frequent edits only re-run these tiny COPYs. | |
| COPY --chown=user:user static/ ./static/ | |
| COPY --chown=user:user server.py . | |
| ENV GAMER_DB=/app/posts.db \ | |
| GAMER_AVATARS=/app/avatars \ | |
| GAMER_EMOJIS=/app/forum_emojis | |
| EXPOSE 7860 | |
| USER user | |
| CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"] | |