Spaces:
Sleeping
Sleeping
Commit ·
a2ed773
1
Parent(s): a5c202c
Updated Dockerfile
Browse files- Dockerfile +15 -115
Dockerfile
CHANGED
|
@@ -1,121 +1,21 @@
|
|
| 1 |
-
|
| 2 |
-
# Base image – pick slim Python for a smaller footprint
|
| 3 |
-
###############################################################################
|
| 4 |
-
FROM python:3.10-slim
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
ENV HF_HOME=/hf
|
| 12 |
-
WORKDIR /app
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
RUN apt-get update && \
|
| 18 |
-
apt-get install -y --no-install-recommends \
|
| 19 |
-
git git-lfs \ # for pulling large LFS blobs / models
|
| 20 |
-
ffmpeg libsm6 libxext6 \ # common for OpenCV / video / image ops
|
| 21 |
-
&& rm -rf /var/lib/apt/lists/* \
|
| 22 |
-
&& git lfs install
|
| 23 |
|
| 24 |
-
|
| 25 |
-
# 3. Python deps #
|
| 26 |
-
# --------------------------------------------------------------------------- #
|
| 27 |
-
# a) First install *only* requirements.txt to leverage Docker layer caching
|
| 28 |
-
COPY requirements.txt .
|
| 29 |
-
RUN pip install --upgrade pip && pip install -r requirements.txt
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
# --------------------------------------------------------------------------- #
|
| 34 |
-
# Copy each top-level directory you showed in the screenshot
|
| 35 |
-
COPY --link --chown=1000:1000 ./frontend ./frontend
|
| 36 |
-
COPY --link --chown=1000:1000 ./data ./data
|
| 37 |
-
COPY --link --chown=1000:1000 ./insucompass ./insucompass
|
| 38 |
-
COPY --link --chown=1000:1000 ./scripts ./scripts
|
| 39 |
|
| 40 |
-
|
| 41 |
-
COPY insucompass.db .
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
# --------------------------------------------------------------------------- #
|
| 46 |
-
ENV PORT=7860
|
| 47 |
-
EXPOSE $PORT
|
| 48 |
-
|
| 49 |
-
# FastAPI app entry-point assumed at insucompass/main.py → app = FastAPI(...)
|
| 50 |
-
# Adjust the dotted path if your `FastAPI()` object lives elsewhere.
|
| 51 |
-
CMD ["uvicorn", "insucompass.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
###############################################################################
|
| 59 |
-
# --------------------------- Stage 1: base image -------------------------- #
|
| 60 |
-
###############################################################################
|
| 61 |
-
# Pin the exact digest for reproducibility and give this stage the alias `base`
|
| 62 |
-
FROM python:3.10-slim
|
| 63 |
-
|
| 64 |
-
# --- Set Working Directory ---
|
| 65 |
-
WORKDIR /app
|
| 66 |
-
|
| 67 |
-
###############################################################################
|
| 68 |
-
# --------------------------- Stage 2: pipfreeze --------------------------- #
|
| 69 |
-
###############################################################################
|
| 70 |
-
# Capture the *exact* package versions present in the base layer for auditing.
|
| 71 |
-
FROM base AS pipfreeze
|
| 72 |
-
RUN pip freeze > /tmp/freeze.txt
|
| 73 |
-
|
| 74 |
-
###############################################################################
|
| 75 |
-
# --------------------------- Stage 3: final image -------------------------- #
|
| 76 |
-
###############################################################################
|
| 77 |
-
FROM base
|
| 78 |
-
|
| 79 |
-
# Copy the entire filesystem from the `base` stage and fix ownership to our non-root user.
|
| 80 |
-
COPY --chown=1000:1000 --from=base / /
|
| 81 |
-
|
| 82 |
-
# --- Install Project-Specific Requirements ---
|
| 83 |
-
# Use BuildKit’s inline `--mount` to copy requirements.txt.
|
| 84 |
-
# This is highly efficient as it avoids busting the cache if only source code changes.
|
| 85 |
-
RUN --mount=target=/app/requirements.txt,source=requirements.txt \
|
| 86 |
-
pip install --no-cache-dir -r /app/requirements.txt
|
| 87 |
-
|
| 88 |
-
# --- Copy Application Code ---
|
| 89 |
-
# Copy all our application code into the container.
|
| 90 |
-
# Using --link can speed up builds on filesystems that support it.
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
# --- Create Writable Data Directory ---
|
| 94 |
-
# This is crucial for ChromaDB and the LangGraph checkpointer.
|
| 95 |
-
# We create it and give ownership to our non-root user.
|
| 96 |
-
COPY --link --chown=1000:1000 ./data ./data
|
| 97 |
-
RUN mkdir -p /data && chown -R 1000:1000 /data
|
| 98 |
-
|
| 99 |
-
# --- Copy the package lockfile for debugging/auditing ---
|
| 100 |
-
COPY --from=pipfreeze --link --chown=1000:1000 /tmp/freeze.txt /tmp/freeze.txt
|
| 101 |
-
COPY requirements.txt ./
|
| 102 |
-
|
| 103 |
-
RUN pip3 install -r requirements.txt
|
| 104 |
-
|
| 105 |
-
# --- Switch to the non-root user for runtime ---
|
| 106 |
-
# This is a security best practice.
|
| 107 |
-
USER 1000
|
| 108 |
-
|
| 109 |
-
# --- Expose Port ---
|
| 110 |
-
# Tell Docker that the container will listen on port 8000 at runtime.
|
| 111 |
-
EXPOSE 8000
|
| 112 |
-
|
| 113 |
-
# --- Health Check ---
|
| 114 |
-
# A simple check to ensure the FastAPI root endpoint is responsive.
|
| 115 |
-
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
# --- Run Command ---
|
| 119 |
-
# The command to execute when the container starts.
|
| 120 |
-
# --host 0.0.0.0 is ESSENTIAL to make the server accessible from outside the container.
|
| 121 |
-
CMD ["uvicorn", "insucompass.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
|
|
|
| 1 |
+
FROM python:3.10
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
# Install system dependencies including libGL
|
| 4 |
+
RUN apt-get update && apt-get install -y \
|
| 5 |
+
libgl1-mesa-glx \
|
| 6 |
+
libglib2.0-0 \
|
| 7 |
+
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
RUN useradd -m -u 1000 user
|
| 10 |
+
USER user
|
| 11 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
WORKDIR /insucompass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
| 16 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
RUN ls -R /insucompass
|
|
|
|
| 19 |
|
| 20 |
+
COPY --chown=user . /insucompass
|
| 21 |
+
CMD ["uvicorn", "insucompass.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|