FROM ollama/ollama:0.40.13 AS ollama-runtime # The backend-only target remains available for Docker Compose / Render. FROM python:3.11-slim AS backend WORKDIR /app RUN apt-get update \ && apt-get install -y --no-install-recommends libexpat1 libgomp1 ca-certificates \ && rm -rf /var/lib/apt/lists/* ENV PYTHONUNBUFFERED=1 SATFORGE_DATA=/data SATFORGE_PIPELINE_ENABLED=1 COPY requirements.txt requirements-ai.txt ./ RUN pip install --no-cache-dir torch==2.10.0 torchvision==0.25.0 --index-url https://download.pytorch.org/whl/cpu \ && pip install --no-cache-dir -r requirements.txt -r requirements-ai.txt COPY backend ./backend COPY ai ./ai COPY scripts ./scripts COPY data/boundaries ./data/boundaries COPY models ./models RUN python -c "from backend.sources import install_model; install_model()" EXPOSE 8000 CMD ["sh", "-c", "uvicorn backend.app:app --host 0.0.0.0 --port ${PORT:-8000} --workers 1"] # Hugging Face builds the final target: both models and API in one Docker Space. FROM backend AS space USER root RUN useradd --create-home --uid 1000 sahab \ && mkdir -p /home/sahab/data /home/sahab/ollama-models \ && chown -R sahab:sahab /home/sahab /app COPY --from=ollama-runtime /usr/bin/ollama /usr/bin/ollama COPY --from=ollama-runtime /usr/lib/ollama /usr/lib/ollama ENV PORT=7860 SATFORGE_DATA=/home/sahab/data \ OLLAMA_MODELS=/home/sahab/ollama-models OLLAMA_HOST=127.0.0.1:11434 \ OLLAMA_NO_CLOUD=1 OLLAMA_NUM_PARALLEL=1 OLLAMA_MAX_LOADED_MODELS=1 \ SATFORGE_OLLAMA_URL=http://127.0.0.1:11434 \ SATFORGE_NARRATOR_MODEL=qwen3.5:0.8b \ OMP_NUM_THREADS=2 MKL_NUM_THREADS=2 USER sahab # Download at build time so cold starts do not download another model. RUN python -m scripts.space_runtime --download-model EXPOSE 7860 CMD ["python", "-m", "scripts.space_runtime"]