Repository navigation
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
107 lines (102 loc) · 3.38 KB
/
Copy pathdocker-compose.yml
File metadata and controls
107 lines (102 loc) · 3.38 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
# MalVis local end-to-end stack.
#
# Three services on a single private network:
# api FastAPI backend, runs the worker via subprocess for OS-level
# isolation (RLIMIT_AS/CPU + wall-clock timeout).
# frontend Next.js standalone build. Talks to the backend via /api/*
# through the proxy — same-origin, no CORS gymnastics.
# proxy Caddy. Public entry point, strips /api before forwarding.
#
# To bring it up:
# cp .env.example .env # edit if you want
# docker compose up --build
# open http://localhost:8080
#
# To shut down cleanly:
# docker compose down
#
# Notes:
# - The full SECURITY.md "container-per-request" extractor isolation is
# a Phase-4-prod concern; locally we use SubprocessExtractor inside
# the api container, which gives OS-level isolation without the
# orchestration burden of per-request container spawn.
# - artifacts/ is mounted read-only so a pickle never gets mutated by
# a running worker. The mock-mode default means most users won't
# have anything in there yet — that's fine.
#
services:
api:
build:
context: ./backend
dockerfile: Dockerfile
container_name: malvis-api
restart: unless-stopped
environment:
ENVIRONMENT: ${ENVIRONMENT:-production}
LOG_LEVEL: ${LOG_LEVEL:-info}
# Caddy strips /api before forwarding, so FastAPI is mounted at /api
# from the public URL's perspective. Tell uvicorn so Swagger UI's
# generated openapi.json URL is correct. (On Render's bare subdomain
# we leave this unset — backend lives at the root.)
ROOT_PATH: /api
# Subprocess extractor: forks the worker per request with rlimits.
EXTRACTOR_STRATEGY: subprocess
EXTRACTOR_TIMEOUT_SECONDS: "30"
EXTRACTOR_MEMORY_MB: "512"
EXTRACTOR_CPU_SECONDS: "30"
# CORS lock: same-origin via the proxy, but the backend's allowlist
# is enforced regardless. Multiple origins comma-separated.
CORS_ALLOWED_ORIGINS: ${PUBLIC_ORIGIN:-http://localhost:8080}
USE_MOCK_MODELS: ${USE_MOCK_MODELS:-true}
volumes:
# Read-only — predictions never write to artifacts.
- ./artifacts:/app/artifacts:ro
expose:
- "8000"
networks:
- malvis
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request,sys; urllib.request.urlopen('http://localhost:8000/health', timeout=3); sys.exit(0)"]
interval: 30s
timeout: 5s
start_period: 10s
retries: 3
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
args:
# NEXT_PUBLIC_* must be present at *build* time. /api is the path
# Caddy strips before forwarding, so same-origin works locally
# and in production with a real hostname.
NEXT_PUBLIC_API_BASE: ${NEXT_PUBLIC_API_BASE:-/api}
container_name: malvis-frontend
restart: unless-stopped
expose:
- "3000"
networks:
- malvis
depends_on:
api:
condition: service_healthy
proxy:
image: caddy:2.8-alpine
container_name: malvis-proxy
restart: unless-stopped
ports:
- "${PROXY_HTTP_PORT:-8080}:8080"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
networks:
- malvis
depends_on:
- api
- frontend
networks:
malvis:
name: malvis
volumes:
caddy_data:
caddy_config: