-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
173 lines (165 loc) · 5.41 KB
/
Copy pathdocker-compose.yml
File metadata and controls
173 lines (165 loc) · 5.41 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
# SafeOS Guardian - full local stack.
#
# cp .env.example .env # optional: fill in only the keys you want
# docker compose up -d --build
#
# Startup order is enforced by health/completion gates:
# ollama (healthy) -> ollama-pull (models cached) -> api (healthy) -> ui
#
# NVIDIA GPU: docker compose -f docker-compose.yml -f docker-compose.gpu.yml up -d --build
# With Redis: docker compose --profile with-redis up -d --build
#
# Values written as ${VAR:-default} are read from ./.env automatically.
name: safeos
services:
# ---------------------------------------------------------------------------
# Ollama - local vision-model inference server
# ---------------------------------------------------------------------------
ollama:
image: ollama/ollama:latest
container_name: safeos-ollama
restart: unless-stopped
ports:
- "11434:11434"
volumes:
- ollama-models:/root/.ollama
healthcheck:
test: ["CMD-SHELL", "ollama list >/dev/null 2>&1 || exit 1"]
interval: 10s
timeout: 10s
retries: 12
start_period: 20s
networks:
- safeos-network
# ---------------------------------------------------------------------------
# ollama-pull - one-shot: download the configured models into the
# ollama-models volume (the cache) before the API starts, so the API's
# ensureModels() call is instant instead of blocking on a cold pull.
# ---------------------------------------------------------------------------
ollama-pull:
image: ollama/ollama:latest
container_name: safeos-ollama-pull
depends_on:
ollama:
condition: service_healthy
environment:
- OLLAMA_HOST=http://ollama:11434
- OLLAMA_MODELS=${OLLAMA_MODELS:-moondream llava:7b}
entrypoint: ["/bin/sh", "-c"]
command:
- |
set -e
models=$$(echo "$$OLLAMA_MODELS" | tr ',' ' ')
echo "Caching Ollama models: $$models"
for m in $$models; do
echo ">> ollama pull $$m"
ollama pull "$$m"
done
echo "Model cache ready:"
ollama list
restart: "no"
networks:
- safeos-network
# ---------------------------------------------------------------------------
# api - backend (Express + Socket.io + BullMQ), runs src/ via tsx
# ---------------------------------------------------------------------------
api:
build:
context: .
target: backend
container_name: safeos-api
restart: unless-stopped
init: true
ports:
- "3001:3001"
environment:
- NODE_ENV=production
- SAFEOS_PORT=3001
- SAFEOS_DB_PATH=/app/db_data/safeos.sqlite3
- OLLAMA_HOST=http://ollama:11434
- CORS_ORIGIN=${CORS_ORIGIN:-http://localhost:3000}
- REDIS_URL=${REDIS_URL:-}
- RATE_LIMIT_RPM=${RATE_LIMIT_RPM:-60}
- LOG_LEVEL=${LOG_LEVEL:-info}
- JWT_SECRET=${JWT_SECRET:-}
- SESSION_EXPIRY=${SESSION_EXPIRY:-604800}
# Cloud AI fallback (optional)
- OPENROUTER_API_KEY=${OPENROUTER_API_KEY:-}
- OPENAI_API_KEY=${OPENAI_API_KEY:-}
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY:-}
# Alert channels (optional)
- TWILIO_ACCOUNT_SID=${TWILIO_ACCOUNT_SID:-}
- TWILIO_AUTH_TOKEN=${TWILIO_AUTH_TOKEN:-}
- TWILIO_PHONE_NUMBER=${TWILIO_PHONE_NUMBER:-}
- TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN:-}
- RESEND_API_KEY=${RESEND_API_KEY:-}
- EMAIL_FROM=${EMAIL_FROM:-}
- EMAIL_REPLY_TO=${EMAIL_REPLY_TO:-}
# Web push (optional)
- VAPID_PUBLIC_KEY=${VAPID_PUBLIC_KEY:-}
- VAPID_PRIVATE_KEY=${VAPID_PRIVATE_KEY:-}
- VAPID_EMAIL=${VAPID_EMAIL:-}
volumes:
- safeos-data:/app/db_data
depends_on:
ollama:
condition: service_healthy
ollama-pull:
condition: service_completed_successfully
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3001/health"]
interval: 30s
timeout: 10s
retries: 5
start_period: 30s
networks:
- safeos-network
# ---------------------------------------------------------------------------
# ui - Next.js static export served by nginx
# NEXT_PUBLIC_* are inlined at build time, so they are passed as build args.
# ---------------------------------------------------------------------------
ui:
build:
context: .
target: frontend
args:
NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL:-http://localhost:3001}
NEXT_PUBLIC_WS_URL: ${NEXT_PUBLIC_WS_URL:-ws://localhost:3001}
container_name: safeos-ui
restart: unless-stopped
ports:
- "3000:3000"
depends_on:
api:
condition: service_healthy
networks:
- safeos-network
# ---------------------------------------------------------------------------
# redis - optional, for BullMQ scaling / rate limiting
# docker compose --profile with-redis up -d
# ---------------------------------------------------------------------------
redis:
image: redis:7-alpine
container_name: safeos-redis
restart: unless-stopped
ports:
- "6379:6379"
command: redis-server --appendonly yes
volumes:
- redis-data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
networks:
- safeos-network
profiles:
- with-redis
volumes:
ollama-models:
safeos-data:
redis-data:
networks:
safeos-network:
driver: bridge