Sam3838 commited on
Commit
142fe97
·
verified ·
1 Parent(s): f8df6bc

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +145 -0
Dockerfile ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # =============================================================================
2
+ # Multi-stage Dockerfile for Webscout API Server
3
+ # Optimized for production with security, performance, and size considerations
4
+ # No external docker/ directory required - works with pip/git installations
5
+ # =============================================================================
6
+
7
+ # -----------------------------------------------------------------------------
8
+ # Stage 1: Builder - Install dependencies and build the application
9
+ # -----------------------------------------------------------------------------
10
+ FROM python:3.11-slim as builder
11
+
12
+ # Set build arguments for flexibility
13
+ ARG WEBSCOUT_VERSION=latest
14
+ ARG TARGETPLATFORM
15
+ ARG BUILDPLATFORM
16
+
17
+ # Set environment variables for build optimization
18
+ ENV PYTHONUNBUFFERED=1 \
19
+ PYTHONDONTWRITEBYTECODE=1 \
20
+ PIP_NO_CACHE_DIR=1 \
21
+ PIP_DISABLE_PIP_VERSION_CHECK=1 \
22
+ PIP_DEFAULT_TIMEOUT=100
23
+
24
+ # Install build dependencies
25
+ RUN apt-get update && apt-get install -y --no-install-recommends \
26
+ build-essential \
27
+ gcc \
28
+ git \
29
+ curl \
30
+ && rm -rf /var/lib/apt/lists/*
31
+
32
+ # Create virtual environment for better dependency isolation
33
+ RUN python -m venv /opt/venv
34
+ ENV PATH="/opt/venv/bin:$PATH"
35
+
36
+ # Upgrade pip and install build tools
37
+ RUN pip install --upgrade pip setuptools wheel
38
+
39
+ # Install webscout with API dependencies
40
+ # Use specific version if provided, otherwise latest
41
+ RUN if [ "$WEBSCOUT_VERSION" = "latest" ]; then \
42
+ pip install git+https://github.com/OEvortex/Webscout.git#egg=webscout[api]; \
43
+ else \
44
+ pip install git+https://github.com/OEvortex/Webscout.git@${WEBSCOUT_VERSION}#egg=webscout[api]; \
45
+ fi
46
+
47
+ # Install additional production dependencies
48
+ RUN pip install \
49
+ gunicorn[gthread] \
50
+ uvicorn[standard] \
51
+ prometheus-client \
52
+ structlog \
53
+ motor \
54
+ pymongo
55
+
56
+ # -----------------------------------------------------------------------------
57
+ # Stage 2: Runtime - Create minimal production image
58
+ # -----------------------------------------------------------------------------
59
+ FROM python:3.11-slim as runtime
60
+
61
+ # Set runtime arguments and labels for metadata
62
+ ARG BUILD_DATE
63
+ ARG VCS_REF
64
+ ARG VERSION
65
+
66
+ LABEL maintainer="OEvortex" \
67
+ org.label-schema.build-date=$BUILD_DATE \
68
+ org.label-schema.name="webscout-api" \
69
+ org.label-schema.description="Webscout API Server - OpenAI-compatible LLM proxy" \
70
+ org.label-schema.url="https://github.com/OEvortex/Webscout" \
71
+ org.label-schema.vcs-ref=$VCS_REF \
72
+ org.label-schema.vcs-url="https://github.com/OEvortex/Webscout" \
73
+ org.label-schema.vendor="OEvortex" \
74
+ org.label-schema.version=$VERSION \
75
+ org.label-schema.schema-version="1.0"
76
+
77
+ # Create non-root user for security
78
+ RUN groupadd --gid 1000 webscout && \
79
+ useradd --uid 1000 --gid webscout --shell /bin/bash --create-home webscout
80
+
81
+ # Set production environment variables
82
+ ENV PYTHONUNBUFFERED=1 \
83
+ PYTHONDONTWRITEBYTECODE=1 \
84
+ PYTHONPATH=/app \
85
+ PATH="/opt/venv/bin:$PATH" \
86
+ # Security settings
87
+ PYTHONHASHSEED=random \
88
+ # Performance settings
89
+ MALLOC_ARENA_MAX=2 \
90
+ # Application settings
91
+ WEBSCOUT_HOST=0.0.0.0 \
92
+ WEBSCOUT_PORT=7860 \
93
+ WEBSCOUT_WORKERS=1 \
94
+ WEBSCOUT_LOG_LEVEL=info \
95
+ # Authentication settings (new)
96
+ WEBSCOUT_NO_AUTH=true \
97
+ WEBSCOUT_NO_RATE_LIMIT=true \
98
+ WEBSCOUT_DATA_DIR=/app/data \
99
+ # FastAPI metadata (new)
100
+ WEBSCOUT_API_TITLE="Webscout OpenAI API" \
101
+ WEBSCOUT_API_DESCRIPTION="OpenAI API compatible interface for various LLM providers with enhanced authentication" \
102
+ WEBSCOUT_API_VERSION="0.2.0" \
103
+ WEBSCOUT_API_DOCS_URL="/docs" \
104
+ WEBSCOUT_API_REDOC_URL="/redoc" \
105
+ WEBSCOUT_API_OPENAPI_URL="/openapi.json"
106
+
107
+ # Install only runtime dependencies
108
+ RUN apt-get update && apt-get install -y --no-install-recommends \
109
+ # Required for some Python packages
110
+ libffi8 \
111
+ libssl3 \
112
+ # Useful for debugging (can be removed for minimal image)
113
+ curl \
114
+ # Health check utilities
115
+ procps \
116
+ && rm -rf /var/lib/apt/lists/* \
117
+ && apt-get clean
118
+
119
+ # Copy virtual environment from builder stage
120
+ COPY --from=builder /opt/venv /opt/venv
121
+
122
+ # Create application directory and set ownership
123
+ WORKDIR /app
124
+ RUN chown -R webscout:webscout /app
125
+
126
+ # Copy application files (if building from source)
127
+ # COPY --chown=webscout:webscout . /app
128
+
129
+ # Create directories for logs and data with proper permissions
130
+ RUN mkdir -p /app/logs /app/data && \
131
+ chown -R webscout:webscout /app/logs /app/data
132
+
133
+ # Switch to non-root user
134
+ USER webscout
135
+
136
+ # Expose port (configurable via environment)
137
+ EXPOSE $WEBSCOUT_PORT
138
+
139
+ # Add health check
140
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
141
+ CMD curl -f http://localhost:${WEBSCOUT_PORT:-8000}/health || exit 1
142
+
143
+ # Default command - start the webscout API server with new auth system
144
+ # Environment variables will be used by the application
145
+ CMD ["python", "-m", "webscout.auth.server"]