-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDockerfile
More file actions
99 lines (78 loc) · 3.24 KB
/
Copy pathDockerfile
File metadata and controls
99 lines (78 loc) · 3.24 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
# Stage 1: Build the frontend
FROM --platform=$BUILDPLATFORM node:24-slim AS frontend-builder
# Accept version as build argument
ARG APP_VERSION=dev
WORKDIR /app/frontend
# Copy frontend source code
COPY src/frontend/ ./
# Create the target directory for the build output
RUN mkdir -p ../api/static
# Install dependencies and build the frontend with version
RUN npm ci && \
VITE_APP_VERSION=$APP_VERSION npm run build
# Stage 2: Python application with built frontend
FROM python:3.13-slim
WORKDIR /app
# Install OpenSSL for certificate generation and curl for healthchecks
RUN apt-get update && apt-get install -y \
openssl \
curl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install UV for faster package management
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Copy Python requirements and install dependencies with UV (10-100x faster)
COPY requirements.txt requirements-teams.txt ./
ARG INSTALL_TEAMS_BOT=false
# flatdict >=4.1 provides a wheel; retain build isolation for source packages.
RUN if [ "$INSTALL_TEAMS_BOT" = "true" ]; then \
uv pip install --system --no-cache -r requirements.txt -r requirements-teams.txt; \
else \
uv pip install --system --no-cache -r requirements.txt; \
fi
# Copy main entry point
COPY main.py /app/
# Copy Python source code (excluding legacy folder)
COPY src/api /app/src/api
COPY src/config /app/src/config
COPY src/core /app/src/core
COPY src/data /app/src/data
COPY src/utils /app/src/utils
COPY src/integrations /app/src/integrations
# Copy scripts directory for CLI tools
COPY scripts /app/scripts
# Copy built frontend assets from the frontend builder stage
# Frontend builds to ../api/static relative to the frontend directory
COPY --from=frontend-builder /app/api/static/ /app/src/api/static/
# Create a dedicated runtime user and writable runtime directories
RUN groupadd --system tako && \
useradd --system --gid tako --home-dir /app --shell /usr/sbin/nologin tako && \
mkdir -p /app/certs /app/sqlite_db /app/chat_sessions /app/logs /app/generated_scripts && \
chown -R tako:tako /app
# Create startup script for SSL and server
RUN echo '#!/bin/bash \n\
# Generate SSL certificates if they don\'t exist \n\
if [ ! -f /app/certs/cert.pem ] || [ ! -f /app/certs/key.pem ]; then \n\
echo "Generating SSL certificates..." \n\
mkdir -p /app/certs \n\
openssl req -x509 -newkey rsa:2048 -keyout /app/certs/key.pem -out /app/certs/cert.pem -sha256 -days 3650 -nodes \
-subj "/C=US/ST=State/L=City/O=Okta AI Agent/OU=Development/CN=localhost" \
-addext "subjectAltName=DNS:localhost,DNS:127.0.0.1,DNS:host.docker.internal" \n\
echo "SSL certificates generated successfully" \n\
fi \n\
\n\
# Start the server with SSL \n\
exec python -m uvicorn src.api.main:app --host 0.0.0.0 --port 8001 --ssl-keyfile /app/certs/key.pem --ssl-certfile /app/certs/cert.pem \n\
' > /app/start.sh && chmod +x /app/start.sh
# Environment variables
ENV PYTHONPATH=/app
ENV PYTHONUNBUFFERED=1
# Drop root privileges for the application runtime
USER tako:tako
# Expose HTTPS port
EXPOSE 8001
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
CMD curl -k https://localhost:8001/health || exit 1
# Start the server with SSL
CMD ["/app/start.sh"]