-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
211 lines (161 loc) · 4.92 KB
/
Dockerfile
File metadata and controls
211 lines (161 loc) · 4.92 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# UAP Production Dockerfile
# Multi-stage build for optimized production deployment with security hardening
# === Frontend Build Stage ===
FROM node:20-alpine AS frontend-build
LABEL stage=frontend-build
# Create non-root user for security
RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001
# Set working directory
WORKDIR /app
# Copy package files and install dependencies
COPY frontend/package*.json ./
RUN npm ci --only=production && npm cache clean --force
# Copy frontend source and build
COPY frontend/ ./
RUN npm run build
# Verify build output
RUN ls -la dist/
# === Python Dependencies Stage ===
FROM python:3.11-slim AS python-deps
# Install system dependencies for building Python packages
RUN apt-get update && apt-get install -y \
build-essential \
curl \
git \
&& rm -rf /var/lib/apt/lists/*
# Create virtual environment
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Copy requirements and install Python dependencies
COPY backend/requirements.txt /tmp/requirements.txt
RUN pip install --upgrade pip && \
pip install --no-cache-dir -r /tmp/requirements.txt
# === Production Runtime Stage ===
FROM python:3.11-slim AS production
# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV PATH="/opt/venv/bin:$PATH"
ENV PYTHONPATH="/app/backend"
# Install runtime system dependencies
RUN apt-get update && apt-get install -y \
curl \
tini \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Create non-root user for security
RUN groupadd -r uap && useradd -r -g uap -s /bin/bash uap
# Create application directories
RUN mkdir -p /app/logs /app/temp /app/uploads /app/models \
&& chown -R uap:uap /app
# Copy Python virtual environment from deps stage
COPY --from=python-deps /opt/venv /opt/venv
# Set working directory
WORKDIR /app
# Copy backend application
COPY --chown=uap:uap backend/ ./backend/
# Copy built frontend from frontend-build stage
COPY --from=frontend-build --chown=uap:uap /app/dist ./frontend/dist/
# Copy production scripts and configurations
COPY --chown=uap:uap scripts/ ./scripts/
COPY --chown=uap:uap .env.production.template ./.env.template
# Make scripts executable
RUN chmod +x ./scripts/*.sh
# Create logging configuration
RUN cat > /app/logging.conf << EOF
[loggers]
keys=root,uvicorn,uap
[handlers]
keys=console,file,json
[formatters]
keys=generic,json
[logger_root]
level=INFO
handlers=console,file
[logger_uvicorn]
level=INFO
handlers=console,file
qualname=uvicorn
propagate=0
[logger_uap]
level=INFO
handlers=console,json
qualname=uap
propagate=0
[handler_console]
class=StreamHandler
formatter=generic
args=(sys.stdout,)
[handler_file]
class=logging.handlers.RotatingFileHandler
formatter=generic
args=('/app/logs/app.log', 'a', 100*1024*1024, 10)
[handler_json]
class=logging.handlers.RotatingFileHandler
formatter=json
args=('/app/logs/app-json.log', 'a', 100*1024*1024, 10)
[formatter_generic]
format=%(asctime)s [%(process)d] [%(levelname)s] %(name)s: %(message)s
datefmt=%Y-%m-%d %H:%M:%S
[formatter_json]
class=pythonjsonlogger.jsonlogger.JsonFormatter
format=%(asctime)s %(name)s %(levelname)s %(message)s
EOF
# Create health check script
RUN cat > /app/healthcheck.sh << 'EOF'
#!/bin/bash
curl -f http://localhost:8000/health || exit 1
EOF
RUN chmod +x /app/healthcheck.sh
# Switch to non-root user
USER uap
# Expose ports
EXPOSE 8000 3000 9090
# Add health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
CMD ["/app/healthcheck.sh"]
# Set labels for metadata
LABEL org.opencontainers.image.title="UAP Agent Orchestration Platform"
LABEL org.opencontainers.image.description="Multi-framework AI agent orchestration platform"
LABEL org.opencontainers.image.version="3.0.0"
LABEL org.opencontainers.image.vendor="UAP Team"
LABEL org.opencontainers.image.source="https://github.com/uap/uap-platform"
# Use tini as PID 1 for proper signal handling
ENTRYPOINT ["/usr/bin/tini", "--"]
# Default command - can be overridden
CMD ["/app/scripts/start-production.sh"]
# === Development Stage (for development builds) ===
FROM production AS development
# Switch back to root for installing dev dependencies
USER root
# Install development tools
RUN apt-get update && apt-get install -y \
vim \
htop \
net-tools \
&& rm -rf /var/lib/apt/lists/*
# Install development Python packages
RUN /opt/venv/bin/pip install \
pytest \
pytest-asyncio \
pytest-cov \
black \
flake8 \
mypy
# Switch back to uap user
USER uap
# Override for development
ENV UAP_ENV=development
ENV DEBUG=true
CMD ["/opt/venv/bin/uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
# === Testing Stage ===
FROM development AS testing
USER root
# Install additional testing dependencies
RUN /opt/venv/bin/pip install \
pytest-benchmark \
pytest-mock \
locust
USER uap
# Run tests by default
CMD ["/opt/venv/bin/pytest", "/app/backend/tests/", "-v", "--cov=/app/backend"]