Repository navigation
Expand file tree
/
Copy pathdocker-compose.hub.yml
More file actions
180 lines (167 loc) · 5.04 KB
/
Copy pathdocker-compose.hub.yml
File metadata and controls
180 lines (167 loc) · 5.04 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
174
175
176
177
178
179
180
# CodeBox - single-file deployment.
#
# Everything needed is in this one file: it pulls prebuilt images from Docker
# Hub and carries the Caddy and Prometheus configs inline, so there is nothing
# to clone and nothing to build.
#
# 1. Save this file on your server as docker-compose.yml
# 2. Create a .env beside it (see the block at the bottom of this file)
# 3. docker compose up -d
#
# Requires Docker Compose v2.23+ for inline configs. Check with:
# docker compose version
services:
caddy:
image: caddy:2-alpine
ports:
- "80:80"
- "443:443"
environment:
# Blank/unset DOMAIN => ":80" => plain HTTP on the server's IP, no SSL.
- SITE_ADDRESS=${DOMAIN:-:80}
- "METRICS_TOKEN=${METRICS_TOKEN:?METRICS_TOKEN must be set (generate one with openssl rand -hex 16)}"
configs:
- source: caddyfile
target: /etc/caddy/Caddyfile
volumes:
- caddy_data:/data
- caddy_config:/config
depends_on:
- api
restart: always
deploy:
resources:
limits:
cpus: '${CADDY_CPUS:-0.25}'
memory: ${CADDY_MEMORY:-128M}
api:
image: ${CODEBOX_IMAGE_NAMESPACE:-hiteshchoudhary}/codebox-api:${CODEBOX_VERSION:-latest}
environment:
- NODE_ENV=production
- REDIS_URL=redis://redis:6379
- "AUTH_TOKEN=${AUTH_TOKEN:?AUTH_TOKEN must be set - an empty token disables auth entirely}"
- PORT=3000
- BODY_LIMIT=50mb
- RATE_LIMIT_MAX_REQUESTS=${RATE_LIMIT_MAX_REQUESTS:-200}
depends_on:
- redis
restart: always
deploy:
resources:
limits:
cpus: '${API_CPUS:-0.25}'
memory: ${API_MEMORY:-256M}
worker:
image: ${CODEBOX_IMAGE_NAMESPACE:-hiteshchoudhary}/codebox-worker:${CODEBOX_VERSION:-latest}
command: node src/queue/worker.js
privileged: true
# isolate writes to /sys/fs/cgroup/cgroup.subtree_control; the host cgroup
# namespace is required for that to take effect.
cgroup: host
environment:
- NODE_ENV=production
- REDIS_URL=redis://redis:6379
- EXECUTOR_TYPE=isolate
- WORKER_CONCURRENCY=${WORKER_CONCURRENCY:-2}
- DEFAULT_MEMORY_LIMIT=${DEFAULT_MEMORY_LIMIT:-256000}
- MAX_MEMORY_LIMIT=${MAX_MEMORY_LIMIT:-512000}
- RESULT_CACHE_TTL=${RESULT_CACHE_TTL:-1800}
depends_on:
- redis
restart: always
deploy:
resources:
limits:
# Must not exceed the host's vCPU count or Docker refuses to start it.
cpus: '${WORKER_CPUS:-1.5}'
memory: ${WORKER_MEMORY:-4G}
redis:
image: redis:7-alpine
volumes:
- redis_data:/data
command: redis-server --appendonly yes --maxmemory ${REDIS_MAXMEMORY:-256mb} --maxmemory-policy noeviction
restart: always
deploy:
resources:
limits:
cpus: '${REDIS_CPUS:-0.25}'
memory: ${REDIS_MEMORY:-384M}
prometheus:
image: prom/prometheus:latest
configs:
- source: prometheus_yml
target: /etc/prometheus/prometheus.yml
volumes:
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--storage.tsdb.retention.time=${PROMETHEUS_RETENTION:-7d}'
restart: always
deploy:
resources:
limits:
cpus: '${PROMETHEUS_CPUS:-0.25}'
memory: ${PROMETHEUS_MEMORY:-512M}
grafana:
image: grafana/grafana:latest
volumes:
- grafana_data:/var/lib/grafana
environment:
- "GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD:?GRAFANA_PASSWORD must be set}"
- GF_USERS_ALLOW_SIGN_UP=false
restart: always
deploy:
resources:
limits:
cpus: '${GRAFANA_CPUS:-0.25}'
memory: ${GRAFANA_MEMORY:-256M}
configs:
caddyfile:
content: |
# DOMAIN blank -> ":80" -> plain HTTP on the server IP, no certificate.
# DOMAIN set -> that hostname -> automatic HTTPS via Let's Encrypt.
{$$SITE_ADDRESS::80} {
@metrics {
path /metrics/*
header X-Metrics-Token {$$METRICS_TOKEN}
}
handle @metrics {
uri strip_prefix /metrics
reverse_proxy prometheus:9090
}
handle /metrics/* {
respond "Unauthorized" 401
}
reverse_proxy api:3000
encode gzip
header {
X-Content-Type-Options nosniff
X-Frame-Options DENY
Referrer-Policy strict-origin-when-cross-origin
-Server
}
log {
output stdout
format json
}
}
prometheus_yml:
content: |
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'codebox-api'
static_configs:
- targets: ['api:3000']
metrics_path: '/metrics'
volumes:
redis_data:
prometheus_data:
grafana_data:
caddy_data:
caddy_config: