Spaces:
Sleeping
Sleeping
Apurva Tiwari
commited on
Commit
·
4c84ee6
1
Parent(s):
6ca7a4a
connect HF to correct port
Browse files- Dockerfile +16 -69
- Dockerfile_1 +119 -0
Dockerfile
CHANGED
|
@@ -2,10 +2,6 @@
|
|
| 2 |
FROM python:3.11-slim
|
| 3 |
|
| 4 |
# 2. Set Environment Variables
|
| 5 |
-
# - DEBIAN_FRONTEND: Prevents installers from asking interactive questions
|
| 6 |
-
# - PYTHONUNBUFFERED/PYTHONDONTWRITEBYTECODE: Standard Python-in-Docker settings
|
| 7 |
-
# - PYVISTA_OFF_SCREEN/DISPLAY: Crucial for running PyVista headless (off-screen)
|
| 8 |
-
# by telling it to use a "virtual" display at address :99
|
| 9 |
ENV DEBIAN_FRONTEND=noninteractive \
|
| 10 |
PYTHONUNBUFFERED=1 \
|
| 11 |
PYTHONDONTWRITEBYTECODE=1 \
|
|
@@ -15,10 +11,9 @@ ENV DEBIAN_FRONTEND=noninteractive \
|
|
| 15 |
DISPLAY=:99 \
|
| 16 |
VTK_SILENCE_GET_VOID_POINTER_WARNINGS=1
|
| 17 |
|
| 18 |
-
# 3. Install System Dependencies
|
| 19 |
-
# Added 'git' here because we need it to clone aqc-research
|
| 20 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 21 |
-
|
| 22 |
libosmesa6 libosmesa6-dev \
|
| 23 |
libgl1 libgl1-mesa-dev \
|
| 24 |
libegl1 libegl1-mesa-dev \
|
|
@@ -31,54 +26,15 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
| 31 |
RUN useradd -m -u 1000 user
|
| 32 |
WORKDIR /home/user/app
|
| 33 |
|
| 34 |
-
# 5. Install Python dependencies (
|
| 35 |
-
# We copy *only* requirements.txt first and install it.
|
| 36 |
-
# This "layer" is cached by Docker. If you only change app.py later,
|
| 37 |
-
# Docker skips this step, making builds much faster.
|
| 38 |
COPY requirements.txt .
|
| 39 |
RUN python3 -m pip install --upgrade pip setuptools wheel \
|
| 40 |
&& python3 -m pip install --no-cache-dir -r requirements.txt
|
| 41 |
|
| 42 |
# 6. Copy the rest of the application code
|
| 43 |
-
# This copies app.py, delta_impulse_generator.py, etc.
|
| 44 |
-
# We set the owner to our new 'user'.
|
| 45 |
COPY --chown=user:user . .
|
| 46 |
COPY docker/nginx.conf /etc/nginx/nginx.conf
|
| 47 |
|
| 48 |
-
# ---------------------------------------------------------------------------
|
| 49 |
-
# Create the 'aqc_venv' and install dependencies
|
| 50 |
-
# ---------------------------------------------------------------------------
|
| 51 |
-
RUN python3 -m venv utils/aqc_venv && \
|
| 52 |
-
# 1. Upgrade pip inside the new venv
|
| 53 |
-
utils/aqc_venv/bin/pip install --upgrade pip setuptools wheel && \
|
| 54 |
-
# 2. Install EXACT versions FIRST (before any library that has qiskit dependency)
|
| 55 |
-
utils/aqc_venv/bin/pip install \
|
| 56 |
-
"qiskit==1.3.1" \
|
| 57 |
-
"qiskit-aer==0.16.4" \
|
| 58 |
-
"qiskit-algorithms==0.4.0" \
|
| 59 |
-
"qiskit-qasm3-import==0.6.0" \
|
| 60 |
-
"qiskit-experiments==0.6.1" \
|
| 61 |
-
"qiskit-ibm-experiment==0.4.8" \
|
| 62 |
-
"numpy==1.26.4" \
|
| 63 |
-
"scipy==1.16.3" \
|
| 64 |
-
"sympy==1.14.0" \
|
| 65 |
-
"openfermion==1.7.1" \
|
| 66 |
-
"cirq-core==1.6.1" \
|
| 67 |
-
"physics-tenpy==1.0.7" \
|
| 68 |
-
"lmfit==1.3.4" \
|
| 69 |
-
"h5py==3.15.1" && \
|
| 70 |
-
# 3. Clone aqc-research inside utils
|
| 71 |
-
cd utils && \
|
| 72 |
-
git clone https://github.com/bjader/aqc-research.git && \
|
| 73 |
-
# 4. Install aqc-research with --no-deps (won't upgrade qiskit)
|
| 74 |
-
/home/user/app/utils/aqc_venv/bin/pip install --no-deps ./aqc-research && \
|
| 75 |
-
# 5. Install adapt-aqc with --no-deps
|
| 76 |
-
/home/user/app/utils/aqc_venv/bin/pip install --no-deps -e ./adapt-aqc && \
|
| 77 |
-
# 6. VERIFY: Print versions to confirm
|
| 78 |
-
echo "=== Qiskit versions ===" && \
|
| 79 |
-
/home/user/app/utils/aqc_venv/bin/pip list | grep -i qiskit && \
|
| 80 |
-
/home/user/app/utils/aqc_venv/bin/python --version
|
| 81 |
-
|
| 82 |
# Prepare writable directories for nginx (running as non-root later)
|
| 83 |
RUN mkdir -p /tmp/nginx/body /tmp/nginx/proxy /tmp/nginx/fastcgi /tmp/nginx/uwsgi /tmp/nginx/scgi \
|
| 84 |
&& touch /tmp/nginx.access.log /tmp/nginx.error.log \
|
|
@@ -87,33 +43,24 @@ RUN mkdir -p /tmp/nginx/body /tmp/nginx/proxy /tmp/nginx/fastcgi /tmp/nginx/uwsg
|
|
| 87 |
# 7. Switch to the non-root user
|
| 88 |
USER user
|
| 89 |
|
| 90 |
-
#
|
| 91 |
-
#
|
| 92 |
-
|
| 93 |
-
# Default runtime configuration for multiprocess layout
|
| 94 |
ENV OMP_NUM_THREADS=1 \
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
QLBM_APP_PORT=8702 \
|
| 99 |
-
EM_HOST=127.0.0.1 \
|
| 100 |
-
QLBM_HOST=127.0.0.1 \
|
| 101 |
-
EM_IFRAME_SRC=/em/ \
|
| 102 |
-
QLBM_IFRAME_SRC=/qlbm/
|
| 103 |
|
| 104 |
-
# 8. Expose the port
|
| 105 |
EXPOSE 7860
|
| 106 |
|
| 107 |
-
# 9. Healthcheck
|
| 108 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
| 109 |
CMD wget --no-verbose --tries=1 --spider http://localhost:${PORT:-7860}/ || exit 1
|
| 110 |
|
| 111 |
# 10. Start Command
|
| 112 |
-
#
|
| 113 |
-
#
|
| 114 |
-
#
|
| 115 |
-
#
|
| 116 |
-
|
| 117 |
-
CMD ["sh", "-c", "Xvfb :99 -screen 0 1024x768x24 >/dev/null 2>&1 & nginx && exec python3 app.py --server --host ${APP_HOST:-127.0.0.1} --port ${APP_PORT:-8700}"]
|
| 118 |
-
|
| 119 |
-
|
|
|
|
| 2 |
FROM python:3.11-slim
|
| 3 |
|
| 4 |
# 2. Set Environment Variables
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
ENV DEBIAN_FRONTEND=noninteractive \
|
| 6 |
PYTHONUNBUFFERED=1 \
|
| 7 |
PYTHONDONTWRITEBYTECODE=1 \
|
|
|
|
| 11 |
DISPLAY=:99 \
|
| 12 |
VTK_SILENCE_GET_VOID_POINTER_WARNINGS=1
|
| 13 |
|
| 14 |
+
# 3. Install System Dependencies (PyVista/VTK headless + nginx + Xvfb)
|
|
|
|
| 15 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 16 |
+
build-essential cmake wget xvfb nginx \
|
| 17 |
libosmesa6 libosmesa6-dev \
|
| 18 |
libgl1 libgl1-mesa-dev \
|
| 19 |
libegl1 libegl1-mesa-dev \
|
|
|
|
| 26 |
RUN useradd -m -u 1000 user
|
| 27 |
WORKDIR /home/user/app
|
| 28 |
|
| 29 |
+
# 5. Install Python dependencies (cached layer)
|
|
|
|
|
|
|
|
|
|
| 30 |
COPY requirements.txt .
|
| 31 |
RUN python3 -m pip install --upgrade pip setuptools wheel \
|
| 32 |
&& python3 -m pip install --no-cache-dir -r requirements.txt
|
| 33 |
|
| 34 |
# 6. Copy the rest of the application code
|
|
|
|
|
|
|
| 35 |
COPY --chown=user:user . .
|
| 36 |
COPY docker/nginx.conf /etc/nginx/nginx.conf
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
# Prepare writable directories for nginx (running as non-root later)
|
| 39 |
RUN mkdir -p /tmp/nginx/body /tmp/nginx/proxy /tmp/nginx/fastcgi /tmp/nginx/uwsgi /tmp/nginx/scgi \
|
| 40 |
&& touch /tmp/nginx.access.log /tmp/nginx.error.log \
|
|
|
|
| 43 |
# 7. Switch to the non-root user
|
| 44 |
USER user
|
| 45 |
|
| 46 |
+
# --- HF Spaces-safe runtime defaults ---
|
| 47 |
+
# Do NOT set APP_PORT (or any internal app ports) in the image.
|
| 48 |
+
# Hugging Face provides $PORT and expects you to bind to 0.0.0.0:$PORT.
|
|
|
|
| 49 |
ENV OMP_NUM_THREADS=1 \
|
| 50 |
+
APP_HOST=0.0.0.0 \
|
| 51 |
+
EM_IFRAME_SRC=/em/ \
|
| 52 |
+
QLBM_IFRAME_SRC=/qlbm/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
+
# 8. Expose the default HF port (HF will still set $PORT at runtime)
|
| 55 |
EXPOSE 7860
|
| 56 |
|
| 57 |
+
# 9. Healthcheck
|
| 58 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
| 59 |
CMD wget --no-verbose --tries=1 --spider http://localhost:${PORT:-7860}/ || exit 1
|
| 60 |
|
| 61 |
# 10. Start Command
|
| 62 |
+
# - Start Xvfb (needed for headless VTK)
|
| 63 |
+
# - Start nginx (as per your setup)
|
| 64 |
+
# - Exec python so it becomes PID 1
|
| 65 |
+
# IMPORTANT: do NOT pass --host/--port overrides here; let app.py use $PORT.
|
| 66 |
+
CMD ["sh", "-c", "Xvfb :99 -screen 0 1024x768x24 >/dev/null 2>&1 & nginx && exec python3 app.py"]
|
|
|
|
|
|
|
|
|
Dockerfile_1
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1. Start from a slim Python 3.11 base image
|
| 2 |
+
FROM python:3.11-slim
|
| 3 |
+
|
| 4 |
+
# 2. Set Environment Variables
|
| 5 |
+
# - DEBIAN_FRONTEND: Prevents installers from asking interactive questions
|
| 6 |
+
# - PYTHONUNBUFFERED/PYTHONDONTWRITEBYTECODE: Standard Python-in-Docker settings
|
| 7 |
+
# - PYVISTA_OFF_SCREEN/DISPLAY: Crucial for running PyVista headless (off-screen)
|
| 8 |
+
# by telling it to use a "virtual" display at address :99
|
| 9 |
+
ENV DEBIAN_FRONTEND=noninteractive \
|
| 10 |
+
PYTHONUNBUFFERED=1 \
|
| 11 |
+
PYTHONDONTWRITEBYTECODE=1 \
|
| 12 |
+
HOME=/home/user \
|
| 13 |
+
PATH=/home/user/.local/bin:$PATH \
|
| 14 |
+
PYVISTA_OFF_SCREEN=true \
|
| 15 |
+
DISPLAY=:99 \
|
| 16 |
+
VTK_SILENCE_GET_VOID_POINTER_WARNINGS=1
|
| 17 |
+
|
| 18 |
+
# 3. Install System Dependencies
|
| 19 |
+
# Added 'git' here because we need it to clone aqc-research
|
| 20 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 21 |
+
build-essential cmake wget xvfb nginx git \
|
| 22 |
+
libosmesa6 libosmesa6-dev \
|
| 23 |
+
libgl1 libgl1-mesa-dev \
|
| 24 |
+
libegl1 libegl1-mesa-dev \
|
| 25 |
+
libglu1-mesa libglu1-mesa-dev \
|
| 26 |
+
libgles2-mesa-dev \
|
| 27 |
+
libx11-6 libxt6 libxrender1 libsm6 libice6 \
|
| 28 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 29 |
+
|
| 30 |
+
# 4. Create a non-root user for security
|
| 31 |
+
RUN useradd -m -u 1000 user
|
| 32 |
+
WORKDIR /home/user/app
|
| 33 |
+
|
| 34 |
+
# 5. Install Python dependencies (optimized)
|
| 35 |
+
# We copy *only* requirements.txt first and install it.
|
| 36 |
+
# This "layer" is cached by Docker. If you only change app.py later,
|
| 37 |
+
# Docker skips this step, making builds much faster.
|
| 38 |
+
COPY requirements.txt .
|
| 39 |
+
RUN python3 -m pip install --upgrade pip setuptools wheel \
|
| 40 |
+
&& python3 -m pip install --no-cache-dir -r requirements.txt
|
| 41 |
+
|
| 42 |
+
# 6. Copy the rest of the application code
|
| 43 |
+
# This copies app.py, delta_impulse_generator.py, etc.
|
| 44 |
+
# We set the owner to our new 'user'.
|
| 45 |
+
COPY --chown=user:user . .
|
| 46 |
+
COPY docker/nginx.conf /etc/nginx/nginx.conf
|
| 47 |
+
|
| 48 |
+
# ---------------------------------------------------------------------------
|
| 49 |
+
# Create the 'aqc_venv' and install dependencies
|
| 50 |
+
# ---------------------------------------------------------------------------
|
| 51 |
+
RUN python3 -m venv utils/aqc_venv && \
|
| 52 |
+
# 1. Upgrade pip inside the new venv
|
| 53 |
+
utils/aqc_venv/bin/pip install --upgrade pip setuptools wheel && \
|
| 54 |
+
# 2. Install EXACT versions FIRST (before any library that has qiskit dependency)
|
| 55 |
+
utils/aqc_venv/bin/pip install \
|
| 56 |
+
"qiskit==1.3.1" \
|
| 57 |
+
"qiskit-aer==0.16.4" \
|
| 58 |
+
"qiskit-algorithms==0.4.0" \
|
| 59 |
+
"qiskit-qasm3-import==0.6.0" \
|
| 60 |
+
"qiskit-experiments==0.6.1" \
|
| 61 |
+
"qiskit-ibm-experiment==0.4.8" \
|
| 62 |
+
"numpy==1.26.4" \
|
| 63 |
+
"scipy==1.16.3" \
|
| 64 |
+
"sympy==1.14.0" \
|
| 65 |
+
"openfermion==1.7.1" \
|
| 66 |
+
"cirq-core==1.6.1" \
|
| 67 |
+
"physics-tenpy==1.0.7" \
|
| 68 |
+
"lmfit==1.3.4" \
|
| 69 |
+
"h5py==3.15.1" && \
|
| 70 |
+
# 3. Clone aqc-research inside utils
|
| 71 |
+
cd utils && \
|
| 72 |
+
git clone https://github.com/bjader/aqc-research.git && \
|
| 73 |
+
# 4. Install aqc-research with --no-deps (won't upgrade qiskit)
|
| 74 |
+
/home/user/app/utils/aqc_venv/bin/pip install --no-deps ./aqc-research && \
|
| 75 |
+
# 5. Install adapt-aqc with --no-deps
|
| 76 |
+
/home/user/app/utils/aqc_venv/bin/pip install --no-deps -e ./adapt-aqc && \
|
| 77 |
+
# 6. VERIFY: Print versions to confirm
|
| 78 |
+
echo "=== Qiskit versions ===" && \
|
| 79 |
+
/home/user/app/utils/aqc_venv/bin/pip list | grep -i qiskit && \
|
| 80 |
+
/home/user/app/utils/aqc_venv/bin/python --version
|
| 81 |
+
|
| 82 |
+
# Prepare writable directories for nginx (running as non-root later)
|
| 83 |
+
RUN mkdir -p /tmp/nginx/body /tmp/nginx/proxy /tmp/nginx/fastcgi /tmp/nginx/uwsgi /tmp/nginx/scgi \
|
| 84 |
+
&& touch /tmp/nginx.access.log /tmp/nginx.error.log \
|
| 85 |
+
&& chown -R user:user /tmp/nginx /tmp/nginx.access.log /tmp/nginx.error.log
|
| 86 |
+
|
| 87 |
+
# 7. Switch to the non-root user
|
| 88 |
+
USER user
|
| 89 |
+
|
| 90 |
+
# Note: We do NOT set PYTHONPATH for adapt-aqc here because it is installed
|
| 91 |
+
# inside the 'aqc_venv' which your code calls via subprocess.
|
| 92 |
+
|
| 93 |
+
# Default runtime configuration for multiprocess layout
|
| 94 |
+
ENV OMP_NUM_THREADS=1 \
|
| 95 |
+
APP_HOST=127.0.0.1 \
|
| 96 |
+
APP_PORT=8700 \
|
| 97 |
+
EM_APP_PORT=8701 \
|
| 98 |
+
QLBM_APP_PORT=8702 \
|
| 99 |
+
EM_HOST=127.0.0.1 \
|
| 100 |
+
QLBM_HOST=127.0.0.1 \
|
| 101 |
+
EM_IFRAME_SRC=/em/ \
|
| 102 |
+
QLBM_IFRAME_SRC=/qlbm/
|
| 103 |
+
|
| 104 |
+
# 8. Expose the port the app will run on
|
| 105 |
+
EXPOSE 7860
|
| 106 |
+
|
| 107 |
+
# 9. Healthcheck (good practice for hosting platforms)
|
| 108 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
| 109 |
+
CMD wget --no-verbose --tries=1 --spider http://localhost:${PORT:-7860}/ || exit 1
|
| 110 |
+
|
| 111 |
+
# 10. Start Command
|
| 112 |
+
# This command does two things:
|
| 113 |
+
# a) Starts the X Virtual FrameBuffer (Xvfb) in the background (&) on display :99
|
| 114 |
+
# b) 'exec' runs your app. Using 'exec' is important as it makes the Python
|
| 115 |
+
# process the main one, which properly handles signals (like stopping the container).
|
| 116 |
+
# '--host 0.0.0.0' is ESSENTIAL to make the server accessible from outside the container.
|
| 117 |
+
CMD ["sh", "-c", "Xvfb :99 -screen 0 1024x768x24 >/dev/null 2>&1 & nginx && exec python3 app.py --server --host ${APP_HOST:-127.0.0.1} --port ${APP_PORT:-8700}"]
|
| 118 |
+
|
| 119 |
+
|