Spaces:
Runtime error
Runtime error
BIM Query Deploy
Claude Opus 4.7 (1M context)
fix(deploy): create real user for uid 1000 so initdb works
e19c339 Download Dockerfile from 12mhsssss/bimquery-api: direct link, hf CLI and curl.
- Browser
- Download file 4.51 kB
-
https://huggingface.co/spaces/12mhsssss/bimquery-api/resolve/main/Dockerfile
- Command line
-
hf download hf://spaces/12mhsssss/bimquery-api/Dockerfile
-
curl -L -o Dockerfile https://huggingface.co/spaces/12mhsssss/bimquery-api/resolve/main/Dockerfile
4.51 kB
| # BIM Query API for Hugging Face Spaces (Docker SDK). | |
| # HF Spaces run as user 1000, expose a single port (7860), and have no | |
| # persistent disk — everything writeable lives under /tmp or /app and is | |
| # considered ephemeral. | |
| # | |
| # This deployment runs Postgres + pgvector INSIDE the container (Mattia's | |
| # choice — see memory). The DB is wiped every time HF rebuilds or wakes | |
| # from sleep. | |
| FROM python:3.11-slim | |
| ENV PYTHONUNBUFFERED=1 \ | |
| PYTHONDONTWRITEBYTECODE=1 \ | |
| PIP_NO_CACHE_DIR=1 \ | |
| PIP_DISABLE_PIP_VERSION_CHECK=1 \ | |
| DEBIAN_FRONTEND=noninteractive \ | |
| PG_MAJOR=15 \ | |
| PGDATA=/tmp/pgdata | |
| WORKDIR /app | |
| # System dependencies. OCCT libs are for ifcopenshell geometry; | |
| # postgresql-15 + postgresql-15-pgvector give us an in-container Postgres | |
| # with pgvector; supervisor multiplexes uvicorn + celery worker + beat. | |
| # postgresql-15 is in Debian Bookworm via the standard pgdg apt repo. | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| ca-certificates gnupg lsb-release wget \ | |
| && wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc \ | |
| | gpg --dearmor -o /usr/share/keyrings/pgdg.gpg \ | |
| && echo "deb [signed-by=/usr/share/keyrings/pgdg.gpg] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" \ | |
| > /etc/apt/sources.list.d/pgdg.list \ | |
| && apt-get update && apt-get install -y --no-install-recommends \ | |
| build-essential \ | |
| libpq-dev \ | |
| libhdf5-dev \ | |
| libocct-foundation-dev \ | |
| libocct-modeling-algorithms-dev \ | |
| libocct-modeling-data-dev \ | |
| libocct-ocaf-dev \ | |
| libocct-visualization-dev \ | |
| libocct-data-exchange-dev \ | |
| libgl1 \ | |
| libglib2.0-0 \ | |
| libsm6 \ | |
| libxext6 \ | |
| libxrender-dev \ | |
| libgomp1 \ | |
| supervisor \ | |
| curl bzip2 \ | |
| postgresql-${PG_MAJOR} \ | |
| postgresql-${PG_MAJOR}-pgvector \ | |
| postgresql-client-${PG_MAJOR} \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # pythonocc-core has no published wheels on PyPI: install it (and its | |
| # matching Python) into an isolated env via micromamba from conda-forge. | |
| RUN curl -fsSL https://micro.mamba.pm/api/micromamba/linux-64/latest \ | |
| | tar -xj -C /usr/local bin/micromamba \ | |
| && /usr/local/bin/micromamba create -y -p /opt/conda \ | |
| -c conda-forge python=3.11 pythonocc-core \ | |
| && /usr/local/bin/micromamba clean --all --yes | |
| ENV PATH="/opt/conda/bin:/usr/lib/postgresql/${PG_MAJOR}/bin:${PATH}" | |
| # Python dependencies. Copying requirements first keeps Docker's layer | |
| # cache warm across source-only edits. | |
| COPY requirements.txt ./ | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Application source. The sync script from the monorepo populates this | |
| # directory before docker build. | |
| COPY . . | |
| # Make the entrypoint executable. | |
| RUN chmod +x /app/entrypoint.sh | |
| # HF Spaces run containers as uid 1000. initdb does getpwuid(1000), so | |
| # uid 1000 needs to be a real named user in /etc/passwd, not just a bare | |
| # numeric uid. Without this, Postgres refuses to initialise the data | |
| # directory with "could not look up effective user ID 1000". | |
| RUN groupadd -g 1000 bim \ | |
| && useradd -u 1000 -g 1000 -m -s /bin/bash -d /home/bim bim | |
| # Postgres data dir, app logs, upload staging area and supervisor log dir | |
| # all need to be owned by the bim user. | |
| RUN mkdir -p /app/logs /tmp/uploads /tmp/pgdata /var/log/supervisor \ | |
| && chown -R bim:bim /app /var/log/supervisor /tmp/uploads /tmp/pgdata /home/bim \ | |
| && chmod -R u+rwX /app /var/log/supervisor /tmp/uploads /tmp/pgdata | |
| # Default Postgres connection — Postgres runs in the same container, so | |
| # POSTGRES_HOST=localhost and no TLS. Real secrets (Redis, R2, Groq) come | |
| # from HF Space environment variables, not the image. | |
| ENV HOME=/home/bim \ | |
| POSTGRES_HOST=localhost \ | |
| POSTGRES_PORT=5432 \ | |
| POSTGRES_USER=bim \ | |
| POSTGRES_PASSWORD=bim \ | |
| POSTGRES_DB=bim \ | |
| POSTGRES_SSL= \ | |
| UPLOAD_DIR=/tmp/uploads | |
| USER bim | |
| EXPOSE 7860 | |
| # Lightweight HTTP healthcheck against the FastAPI /health endpoint. | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=120s --retries=3 \ | |
| CMD python -c "import urllib.request, sys; \ | |
| sys.exit(0 if urllib.request.urlopen('http://localhost:7860/health', timeout=5).status == 200 else 1)" || exit 1 | |
| # Entrypoint boots Postgres in the background, runs migrations, then exec's | |
| # supervisord to manage the application processes. | |
| ENTRYPOINT ["/app/entrypoint.sh"] | |
| CMD ["/usr/bin/supervisord", "-c", "/app/supervisord.conf"] | |