-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
94 lines (69 loc) · 2.48 KB
/
Dockerfile
File metadata and controls
94 lines (69 loc) · 2.48 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Summary Bot NG - Production Dockerfile
# Multi-stage build for optimized image size
# Stage 1: Frontend builder
FROM node:20-slim AS frontend-builder
WORKDIR /frontend
COPY src/frontend/package.json src/frontend/package-lock.json ./
RUN npm ci
COPY src/frontend/ ./
RUN npm run build
# Stage 2: Python dependency builder
FROM python:3.11-slim AS builder
# Install system dependencies for building Python packages
RUN apt-get update && apt-get install -y \
gcc \
g++ \
make \
libffi-dev \
&& rm -rf /var/lib/apt/lists/*
# Install Poetry
RUN pip install --no-cache-dir poetry==1.7.1
# Set working directory
WORKDIR /build
# Copy dependency files
COPY pyproject.toml poetry.lock ./
# Configure Poetry to not create virtual environment (we're in a container)
RUN poetry config virtualenvs.create false
# Install dependencies only (no dev dependencies, no root project)
RUN poetry install --only main --no-root --no-interaction --no-ansi
# Stage 3: Runtime
FROM python:3.11-slim
# Build arguments for versioning
ARG BUILD_NUMBER=dev
ARG BUILD_DATE=
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
ca-certificates \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user for security
RUN useradd -m -u 1000 -s /bin/bash botuser
# Set working directory
WORKDIR /app
# Copy installed packages from builder
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Copy application code
COPY --chown=botuser:botuser src/ ./src/
COPY --chown=botuser:botuser pyproject.toml poetry.lock ./
COPY --chown=botuser:botuser scripts/ ./scripts/
# Copy frontend build output
COPY --from=frontend-builder --chown=botuser:botuser /frontend/dist ./src/frontend/dist/
# Create necessary directories with correct permissions
RUN mkdir -p /app/data /app/logs && \
chown -R botuser:botuser /app
# Switch to non-root user
USER botuser
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:5000/health || exit 1
# Expose webhook port
EXPOSE 5000
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONPATH=/app \
BUILD_NUMBER=${BUILD_NUMBER} \
BUILD_DATE=${BUILD_DATE}
# Run the application (uses src/__main__.py for resilient startup)
CMD ["python", "-m", "src"]