Skip to content

Commit 07b4aba

Browse files
committed
UPDATE deployment
1 parent 332a4dc commit 07b4aba

5 files changed

Lines changed: 140 additions & 14 deletions

File tree

Dockerfile

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,56 @@
1-
FROM python:3.13.3-slim
1+
# Multi-stage build for better optimization
2+
FROM node:18-alpine AS frontend-builder
3+
4+
WORKDIR /app/frontend
5+
COPY frontend/package*.json ./
6+
RUN npm ci --only=production
7+
8+
COPY frontend/ ./
9+
RUN npm run build
10+
11+
# Python backend stage
12+
FROM python:3.11-slim AS backend
13+
14+
# Create non-root user for security
15+
RUN groupadd -r appuser && useradd -r -g appuser appuser
16+
17+
# Install system dependencies
18+
RUN apt-get update && apt-get install -y \
19+
gcc \
20+
g++ \
21+
curl \
22+
&& rm -rf /var/lib/apt/lists/*
223

324
WORKDIR /app
425

26+
# Copy and install Python dependencies
527
COPY requirements.txt .
628
RUN pip install --no-cache-dir -r requirements.txt
729

30+
# Copy application code
831
COPY . .
932

33+
# Copy built frontend from previous stage
34+
COPY --from=frontend-builder /app/frontend/build ./frontend/build
35+
36+
# Create logs directory and set permissions
37+
RUN mkdir -p logs && \
38+
chown -R appuser:appuser /app
39+
40+
# Switch to non-root user
41+
USER appuser
42+
43+
# Environment variables
1044
ENV PORT=8080
1145
ENV HOST=0.0.0.0
46+
ENV FLASK_ENV=production
47+
ENV PYTHONPATH=/app
1248

1349
EXPOSE 8080
1450

15-
# Fly.io specific entrypoint
16-
CMD ["python", "app.py"]
51+
# Health check
52+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
53+
CMD curl -f http://localhost:8080/api/plugins || exit 1
54+
55+
# Use gunicorn for production
56+
CMD ["gunicorn", "--bind", "0.0.0.0:8080", "--workers", "2", "--timeout", "120", "app:app"]

app.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,15 @@ def configure_logging():
8585

8686
# Initialize Flask application (serve React build in production)
8787
app = Flask(__name__, static_folder='frontend/build', static_url_path='/')
88+
89+
# Configure CORS origins from environment variable
90+
cors_origins = os.environ.get('CORS_ORIGINS',
91+
'http://localhost:3000,http://127.0.0.1:3000,http://localhost:5000,http://127.0.0.1:5000,https://quantumfieldkit.com,https://www.quantumfieldkit.com,https://quantumfieldkit.fly.dev'
92+
).split(',')
93+
8894
CORS(app, resources={
8995
r"/api/*": {
90-
"origins": ["http://localhost:3000", "http://127.0.0.1:3000", "http://localhost:5000", "http://127.0.0.1:5000"],
96+
"origins": [origin.strip() for origin in cors_origins],
9197
"methods": ["GET", "POST", "OPTIONS"],
9298
"allow_headers": ["Content-Type"]
9399
}

docker-compose.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
version: '3.8'
2+
3+
services:
4+
quantum-app:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
ports:
9+
- "5000:8080"
10+
environment:
11+
- FLASK_ENV=development
12+
- PORT=8080
13+
- HOST=0.0.0.0
14+
volumes:
15+
- ./logs:/app/logs
16+
- ./plugins:/app/plugins
17+
restart: unless-stopped
18+
healthcheck:
19+
test: ["CMD", "curl", "-f", "http://localhost:8080/api/plugins"]
20+
interval: 30s
21+
timeout: 10s
22+
retries: 3
23+
start_period: 40s
24+
25+
# Optional: Add Redis for caching
26+
# redis:
27+
# image: redis:7-alpine
28+
# ports:
29+
# - "6379:6379"
30+
# restart: unless-stopped
31+
32+
# Optional: Add PostgreSQL for persistence
33+
# postgres:
34+
# image: postgres:15-alpine
35+
# environment:
36+
# POSTGRES_DB: quantumfieldkit
37+
# POSTGRES_USER: quantum
38+
# POSTGRES_PASSWORD: quantum_password
39+
# ports:
40+
# - "5432:5432"
41+
# volumes:
42+
# - postgres_data:/var/lib/postgresql/data
43+
# restart: unless-stopped
44+
45+
# volumes:
46+
# postgres_data:

fly.toml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,45 @@
11
app = "quantumfieldkit"
22
primary_region = "arn"
33
kill_signal = "SIGINT"
4-
kill_timeout = "5s"
4+
kill_timeout = "10s"
55

66
[build]
77
dockerfile = "Dockerfile"
88

99
[env]
1010
PORT = "8080"
11+
FLASK_ENV = "production"
12+
PYTHONPATH = "/app"
1113

1214
[http_service]
1315
internal_port = 8080
1416
force_https = true
1517
auto_stop_machines = true
1618
auto_start_machines = true
1719
min_machines_running = 0
20+
max_machines_running = 2
1821
processes = ["app"]
1922

2023
[http_service.concurrency]
2124
type = "connections"
2225
hard_limit = 1000
2326
soft_limit = 500
2427

28+
# Health check configuration
29+
[http_service.checks]
30+
[http_service.checks.health]
31+
grace_period = "10s"
32+
interval = "30s"
33+
method = "GET"
34+
path = "/api/plugins"
35+
timeout = "5s"
36+
headers = {}
37+
2538
[[vm]]
2639
cpu_kind = "shared"
27-
cpus = 1
28-
memory_mb = 1024
40+
cpus = 2
41+
memory_mb = 2048 # Increased for quantum simulations
42+
43+
# Optional: Add secrets for sensitive configuration
44+
# [secrets]
45+
# SECRET_KEY = "your-secret-key"

requirements.txt

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
1-
flask>=2.2.3
1+
# Core Flask dependencies
2+
flask>=2.3.0,<3.0.0
23
flask-cors>=4.0.0
3-
Werkzeug>=2.2.3
4-
numpy>=1.24.2
4+
flask-socketio>=5.3.2
5+
Werkzeug>=2.3.0,<3.0.0
6+
7+
# Quantum computing libraries
58
cirq>=1.1.0
69
cirq-core>=1.1.0
10+
numpy>=1.24.0,<2.0.0
711
sympy>=1.11.1
8-
networkx>=3.0
12+
13+
# Networking and async
914
eventlet>=0.33.3
10-
flask-socketio>=5.3.2
11-
gunicorn>=20.1.0
15+
networkx>=3.0
16+
17+
# Production server
18+
gunicorn>=21.2.0
19+
20+
# Environment and configuration
1221
python-dotenv>=1.0.0
13-
psutil>=5.9.0
22+
23+
# System monitoring
24+
psutil>=5.9.0
25+
26+
# Security (if needed)
27+
cryptography>=41.0.0
28+
29+
# Optional: For better JSON handling
30+
orjson>=3.9.0

0 commit comments

Comments
 (0)