Spaces:
Sleeping
Sleeping
File size: 3,384 Bytes
de93d43 bab1185 de93d43 bab1185 de93d43 bab1185 de93d43 bab1185 de93d43 bab1185 de93d43 bab1185 de93d43 bab1185 de93d43 bab1185 de93d43 bab1185 de93d43 | 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 | # Hugging Face Spaces: Nginx + FastAPI + Next.js on port 7860
# See Dockerfile.spaces for the same file kept in sync.
FROM python:3.11-slim AS base
# System packages: nginx, curl, Node.js 20
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential gcc nginx curl ca-certificates gnupg \
&& mkdir -p /etc/apt/keyrings \
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key \
| gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" \
> /etc/apt/sources.list.d/nodesource.list \
&& apt-get update && apt-get install -y --no-install-recommends nodejs \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# ββ Python dependencies ββββββββββββββββββββββββββββββββββββββββββββββ
COPY requirements.txt /app/
# Install Python deps; skip liboqs-python if it fails (PQC falls back to simulation)
RUN pip install --no-cache-dir --upgrade pip \
&& grep -v 'liboqs' requirements.txt > /tmp/reqs.txt \
&& pip install --no-cache-dir -r /tmp/reqs.txt \
|| pip install --no-cache-dir fastapi uvicorn[standard] pydantic pydantic-settings \
cryptography pycryptodome numpy scipy loguru python-multipart python-dotenv
# ββ Next.js build ββββββββββββββββββββββββββββββββββββββββββββββββββββ
COPY quantum-oracle-ui/package.json quantum-oracle-ui/package-lock.json* /app/quantum-oracle-ui/
WORKDIR /app/quantum-oracle-ui
RUN npm ci --prefer-offline 2>/dev/null || npm install
COPY quantum-oracle-ui/ /app/quantum-oracle-ui/
RUN npm run build
# Copy standalone static assets (Next.js standalone mode needs these)
RUN cp -r .next/static .next/standalone/.next/static 2>/dev/null || true
RUN cp -r public .next/standalone/public 2>/dev/null || true
# ββ Backend + configs ββββββββββββββββββββββββββββββββββββββββββββββββ
WORKDIR /app
COPY app/ /app/app/
COPY run_api.py /app/
COPY nginx.spaces.conf /etc/nginx/conf.d/default.conf
COPY start-spaces.sh /app/start-spaces.sh
# Remove the default nginx site
RUN rm -f /etc/nginx/sites-enabled/default
# ββ Nginx writable dirs for non-root βββββββββββββββββββββββββββββββββ
RUN mkdir -p /tmp/nginx /var/log/nginx /var/lib/nginx/body \
&& chown -R 1000:1000 /tmp/nginx /var/log/nginx /var/lib/nginx \
&& sed -i 's|/run/nginx.pid|/tmp/nginx/nginx.pid|g' /etc/nginx/nginx.conf \
&& chmod +x /app/start-spaces.sh
# ββ HF Spaces requires user with UID 1000 βββββββββββββββββββββββββββ
RUN useradd -m -u 1000 spacesuser \
&& chown -R 1000:1000 /app
USER 1000
# ββ Environment ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ENV REQUIRE_API_KEY=false \
ENVIRONMENT=production \
DEBUG=false \
LOG_LEVEL=INFO \
PYTHONUNBUFFERED=1
EXPOSE 7860
CMD ["/app/start-spaces.sh"]
|