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