Spaces:
Sleeping
Sleeping
| # ============================================================================= | |
| # Multi-stage Dockerfile for Webscout API Server with Auto-Updater (4hr) | |
| # ============================================================================= | |
| # ------------------------------------------------------------------- | |
| # Stage 1: Builder - Install dependencies and build the application | |
| # ------------------------------------------------------------------- | |
| FROM python:3.11-slim as builder | |
| ARG WEBSCOUT_VERSION=latest | |
| ENV PYTHONUNBUFFERED=1 \ | |
| PYTHONDONTWRITEBYTECODE=1 \ | |
| PIP_NO_CACHE_DIR=1 \ | |
| PIP_DISABLE_PIP_VERSION_CHECK=1 \ | |
| PIP_DEFAULT_TIMEOUT=100 | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| build-essential gcc git curl && \ | |
| rm -rf /var/lib/apt/lists/* | |
| RUN python -m venv /opt/venv | |
| ENV PATH="/opt/venv/bin:$PATH" | |
| RUN pip install --upgrade pip setuptools wheel | |
| RUN if [ "$WEBSCOUT_VERSION" = "latest" ]; then \ | |
| pip install "webscout[api] @ git+https://github.com/OEvortex/Webscout.git"; \ | |
| else \ | |
| pip install "webscout[api] @ git+https://github.com/OEvortex/Webscout.git@${WEBSCOUT_VERSION}"; \ | |
| fi | |
| RUN pip install \ | |
| gunicorn[gthread] \ | |
| uvicorn[standard] \ | |
| prometheus-client \ | |
| structlog \ | |
| motor \ | |
| pymongo | |
| # ------------------------------------------------------------------- | |
| # Stage 2: Runtime - Minimal secure image with auto-updater | |
| # ------------------------------------------------------------------- | |
| FROM python:3.11-slim as runtime | |
| ARG BUILD_DATE | |
| ARG VCS_REF | |
| ARG VERSION | |
| LABEL maintainer="OEvortex" \ | |
| org.label-schema.name="webscout-api" \ | |
| org.label-schema.version=$VERSION \ | |
| org.label-schema.vcs-url="https://github.com/OEvortex/Webscout" \ | |
| org.label-schema.build-date=$BUILD_DATE | |
| RUN groupadd --gid 1000 webscout && \ | |
| useradd --uid 1000 --gid webscout --shell /bin/bash --create-home webscout | |
| ENV PYTHONUNBUFFERED=1 \ | |
| PYTHONDONTWRITEBYTECODE=1 \ | |
| PYTHONPATH=/app \ | |
| PATH="/opt/venv/bin:$PATH" \ | |
| PYTHONHASHSEED=random \ | |
| MALLOC_ARENA_MAX=2 \ | |
| WEBSCOUT_HOST=0.0.0.0 \ | |
| WEBSCOUT_PORT=7860 \ | |
| WEBSCOUT_WORKERS=1 \ | |
| WEBSCOUT_LOG_LEVEL=info \ | |
| WEBSCOUT_NO_AUTH=true \ | |
| WEBSCOUT_NO_RATE_LIMIT=true \ | |
| WEBSCOUT_DATA_DIR=/app/data \ | |
| WEBSCOUT_API_TITLE="Webscout API" \ | |
| WEBSCOUT_API_DESCRIPTION="OpenAI-compatible LLM API" \ | |
| WEBSCOUT_API_VERSION="0.3.0" \ | |
| WEBSCOUT_API_DOCS_URL="/docs" \ | |
| WEBSCOUT_API_REDOC_URL="/redoc" \ | |
| WEBSCOUT_API_OPENAPI_URL="/openapi.json" | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| git libffi8 libssl3 curl procps && \ | |
| rm -rf /var/lib/apt/lists/* && apt-get clean | |
| COPY --from=builder /opt/venv /opt/venv | |
| WORKDIR /app | |
| RUN mkdir -p /app/logs /app/data && \ | |
| chown -R webscout:webscout /app | |
| # Auto-update script (every 4 hours) using background process | |
| RUN echo '#!/bin/bash\n\ | |
| (pip install -U "webscout[api] @ git+https://github.com/OEvortex/Webscout.git" && echo "[INFO] Webscout updated at start") &\n\ | |
| while true; do\n\ | |
| sleep 14400\n\ | |
| echo "[INFO] Auto-updating Webscout..."\n\ | |
| pip install -U "webscout[api] @ git+https://github.com/OEvortex/Webscout.git"\n\ | |
| done &\n\ | |
| exec "$@"' > /entrypoint.sh && chmod +x /entrypoint.sh | |
| USER webscout | |
| EXPOSE $WEBSCOUT_PORT | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ | |
| CMD curl -f http://localhost:${WEBSCOUT_PORT:-8000}/health || exit 1 | |
| ENTRYPOINT ["/entrypoint.sh"] | |
| CMD ["python", "-m", "webscout.auth.server"] |