-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
71 lines (54 loc) · 2.35 KB
/
Copy pathDockerfile
File metadata and controls
71 lines (54 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# ==============================================================================
# Stage 1: Build & Dependencies
# ==============================================================================
FROM python:3.11-slim AS builder
WORKDIR /build
# Configure environment for clean dependency installation
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
# Copy dependency definition
COPY requirements.txt .
# Create virtual environment and install dependencies
RUN python -m venv /opt/venv && \
/opt/venv/bin/pip install --upgrade pip && \
/opt/venv/bin/pip install -r requirements.txt
# ==============================================================================
# Stage 2: Minimal Production Runtime
# ==============================================================================
FROM python:3.11-slim AS runner
LABEL maintainer="Chatbot Engine Team" \
service="ai-agent-gateway" \
runtime="fastapi-python3.11"
WORKDIR /app
# Configure runtime environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PATH="/opt/venv/bin:$PATH" \
PORT=8000 \
ENVIRONMENT=production
# Install minimal runtime system utilities (curl for Docker healthcheck)
RUN apt-get update && \
apt-get install -y --no-install-recommends curl && \
rm -rf /var/lib/apt/lists/*
# Security: Create non-root group and user
RUN groupadd -g 1000 appgroup && \
useradd -u 1000 -g appgroup -s /bin/bash -m appuser
# Copy virtual environment from builder stage
COPY --from=builder /opt/venv /opt/venv
# Copy application source code, business knowledge base, and deployment scripts
COPY --chown=appuser:appgroup app /app/app
COPY --chown=appuser:appgroup data /app/data
COPY --chown=appuser:appgroup scripts /app/scripts
# Grant execution permissions to entrypoint scripts
RUN chmod +x /app/scripts/*.sh || true
# Switch to non-root execution context
USER appuser
# Expose default port (Render overrides this dynamically via $PORT)
EXPOSE 8000
# Docker-level healthcheck against lightweight /health endpoint
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -f http://localhost:${PORT:-8000}/health || exit 1
# Execute startup entrypoint with graceful signal propagation and SSE streaming optimizations
CMD ["/bin/sh", "/app/scripts/render_entrypoint.sh"]