Skip to content

Commit eba1191

Browse files
authored
feat(docker): build and serve frontend (#4)
2 parents 68bbabf + a07e55a commit eba1191

File tree

5 files changed

+120
-12
lines changed

5 files changed

+120
-12
lines changed

.env.example

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# GEMINI API key
22
GEMINI_API_KEY=YOUR_API_KEY
33

4-
# OpenRouter API key
5-
OPEN_ROUTER_API_KEY=YOUR_API_KEY
6-
74
# For TEE deployment only
8-
TEE_IMAGE_REFERENCE=ghcr.io/YOUR_REPO_IMAGE:main
5+
TEE_IMAGE_REFERENCE=ghcr.io/flare-foundation/flare-ai-rag:main
96
INSTANCE_NAME=PROJECT_NAME-TEAM-_NAME

Dockerfile

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
# Stage 1: Build Backend
1+
# Stage 1: Build Frontend
2+
FROM node:18-alpine AS frontend-builder
3+
WORKDIR /frontend
4+
COPY chat-ui/ .
5+
RUN npm install
6+
RUN npm run build
7+
8+
# Stage 2: Build Backend
29
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS backend-builder
310
WORKDIR /flare-ai-rag
411
COPY pyproject.toml README.md ./
@@ -7,14 +14,16 @@ RUN uv venv .venv && \
714
. .venv/bin/activate && \
815
uv pip install -e .
916

10-
# Stage 2: Final Image
17+
# Stage 3: Final Image
1118
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
1219
# Install OS-level dependencies needed for Qdrant
1320
RUN apt-get update && \
1421
apt-get install -y \
1522
wget \
1623
tar \
1724
curl \
25+
nginx \
26+
supervisor \
1827
&& rm -rf /var/lib/apt/lists/*
1928

2029
WORKDIR /app
@@ -29,11 +38,24 @@ RUN wget https://github.com/qdrant/qdrant/releases/download/v1.13.4/qdrant-x86_6
2938
mv qdrant /usr/local/bin/ && \
3039
rm qdrant-x86_64-unknown-linux-musl.tar.gz
3140

41+
# Make entrypoint executable
42+
COPY entrypoint.sh /app/entrypoint.sh
43+
RUN chmod +x /app/entrypoint.sh
44+
45+
# Copy frontend files
46+
COPY --from=frontend-builder /frontend/build /usr/share/nginx/html
47+
48+
# Copy nginx configuration
49+
COPY nginx.conf /etc/nginx/sites-enabled/default
50+
51+
# Setup supervisor configuration
52+
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
53+
3254
# Allow workload operator to override environment variables
33-
LABEL "tee.launch_policy.allow_env_override"="OPEN_ROUTER_API_KEY"
55+
LABEL "tee.launch_policy.allow_env_override"="GEMINI_API_KEY"
3456
LABEL "tee.launch_policy.log_redirect"="always"
3557

36-
COPY entrypoint.sh /app/entrypoint.sh
37-
RUN chmod +x /app/entrypoint.sh
58+
EXPOSE 80
3859

39-
CMD ["/app/entrypoint.sh"]
60+
# Start supervisor (which will start both nginx and the backend)
61+
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

entrypoint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ qdrant &
44

55
# Wait until Qdrant is ready
66
echo "Waiting for Qdrant to initialize..."
7-
until curl -s http://localhost:6333/collections >/dev/null; do
7+
until curl -s http://127.0.0.1:6333/collections >/dev/null; do
88
echo "Qdrant is not ready yet, waiting..."
99
sleep 10
1010
done
1111
echo "Qdrant is up and running!"
1212

1313
# Start RAG application
14-
uv run start-rag
14+
uv run start-backend

nginx.conf

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
server {
2+
listen 80 default_server;
3+
listen [::]:80 default_server;
4+
5+
root /usr/share/nginx/html;
6+
index index.html;
7+
8+
# Enable gzip compression
9+
gzip on;
10+
gzip_vary on;
11+
gzip_min_length 10240;
12+
gzip_proxied expired no-cache no-store private auth;
13+
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
14+
gzip_disable "MSIE [1-6]\.";
15+
16+
# Security headers
17+
add_header X-Frame-Options "SAMEORIGIN";
18+
add_header X-XSS-Protection "1; mode=block";
19+
add_header X-Content-Type-Options "nosniff";
20+
add_header Referrer-Policy "strict-origin-when-cross-origin";
21+
22+
# Cache static assets
23+
location /static/ {
24+
expires 1y;
25+
add_header Cache-Control "public, no-transform";
26+
}
27+
28+
# Handle React routing
29+
location / {
30+
try_files $uri $uri/ /index.html;
31+
32+
# Don't cache index.html
33+
add_header Cache-Control "no-store, no-cache, must-revalidate";
34+
}
35+
36+
# API proxy configuration
37+
location /api/ {
38+
proxy_pass http://127.0.0.1:8080;
39+
proxy_http_version 1.1;
40+
proxy_set_header Upgrade $http_upgrade;
41+
proxy_set_header Connection 'upgrade';
42+
proxy_set_header Host $host;
43+
proxy_set_header X-Real-IP $remote_addr;
44+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
45+
proxy_set_header X-Forwarded-Proto $scheme;
46+
proxy_cache_bypass $http_upgrade;
47+
48+
# CORS settings
49+
add_header 'Access-Control-Allow-Origin' '*';
50+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
51+
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
52+
53+
# Handle preflight requests
54+
if ($request_method = 'OPTIONS') {
55+
add_header 'Access-Control-Allow-Origin' '*';
56+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
57+
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
58+
add_header 'Access-Control-Max-Age' 1728000;
59+
add_header 'Content-Type' 'text/plain charset=UTF-8';
60+
add_header 'Content-Length' 0;
61+
return 204;
62+
}
63+
}
64+
65+
# Handle 404 errors
66+
error_page 404 /index.html;
67+
}

supervisord.conf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[supervisord]
2+
nodaemon=true
3+
user=root
4+
5+
[program:nginx]
6+
command=nginx -g 'daemon off;'
7+
autostart=true
8+
autorestart=true
9+
stdout_logfile=/dev/stdout
10+
stdout_logfile_maxbytes=0
11+
stderr_logfile=/dev/stderr
12+
stderr_logfile_maxbytes=0
13+
14+
[program:backend]
15+
command=/app/entrypoint.sh
16+
directory=/app
17+
autostart=true
18+
autorestart=true
19+
stdout_logfile=/dev/stdout
20+
stdout_logfile_maxbytes=0
21+
stderr_logfile=/dev/stderr
22+
stderr_logfile_maxbytes=0

0 commit comments

Comments
 (0)