-
Notifications
You must be signed in to change notification settings - Fork 167
/
docker-compose.yml
372 lines (343 loc) · 10.2 KB
/
docker-compose.yml
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
---
version: '2.4'
volumes:
builder-certs-ca: {}
builder-certs-client: {}
builder-data: {}
cert-manager-data: {}
certs-data: {}
db-data: {}
pki-data: {}
redis-data: {}
resin-data: {}
s3-data: {}
x-default-healthcheck: &default-healthcheck
test: /usr/src/app/docker-hc
interval: 45s
timeout: 15s
retries: 3
x-default-environment: &default-environment
# FIXME: hardcoded https://github.com/balena-io/open-balena-db/blob/master/create-resin-db.sh#L4
DB_NAME: resin
# FIXME: hardcoded https://github.com/balena-io/open-balena-db/blob/master/Dockerfile#L3-L4
DB_PASSWORD: docker
DB_USER: docker
LOG_LEVEL: DEBUG
PRODUCTION_MODE: 'false'
x-default-healthcheck-trait: &with-default-healthcheck
healthcheck:
<<: *default-healthcheck
x-default-volumes-trait: &with-default-volumes
volumes:
- certs-data:/certs
- resin-data:/balena
x-default-privileges-trait: &with-default-privileges
cap_add:
- SYS_ADMIN
- SYS_RESOURCE
security_opt:
- apparmor=unconfined
tmpfs:
- /run
- /sys/fs/cgroup
x-extended-privileges-trait: &with-extended-privileges
security_opt:
- apparmor=unconfined
- seccomp=unconfined
x-all-privileges-trait: &with-all-privileges
privileged: true
cap_add:
- ALL
x-network-privileges-trait: &with-network-privileges
cap_add:
- NET_ADMIN
- SYS_ADMIN
- SYS_RESOURCE
x-base-service-definition: &base-service
restart: 'unless-stopped'
# for docker-compose only, no effect on balenaCloud
env_file:
- .env
tty: true # send syastemd logs from containers to stdout
services:
# https://github.com/balena-io/open-balena-api
api:
<<: [
*base-service,
*with-default-healthcheck,
*with-default-privileges,
*with-default-volumes,
]
image: balena/open-balena-api:31.2.22
depends_on:
- db
- redis
- s3
environment:
<<: *default-environment
CONTRACTS_PUBLIC_REPO_NAME: contracts
CONTRACTS_PUBLIC_REPO_OWNER: balena-io
DB_GENERAL_REPLICA_MAX_USES: 1000
DB_GENERAL_REPLICA_PORT: 5432
DB_HOST: db
DB_PORT: 5432
DB_STATE_REPLICA_MAX_USES: 1000
DB_STATE_REPLICA_PORT: 5432
DB_USER: docker
HOSTS_CONFIG: API_HOST:api,DB_HOST:db,DELTA_HOST:delta,HOST:api,REDIS_HOST:redis,TOKEN_AUTH_CERT_ISSUER:api,VPN_HOST:cloudlink,REGISTRY2_HOST:registry2
IMAGE_STORAGE_BUCKET: resin-production-img-cloudformation
IMAGE_STORAGE_ENDPOINT: s3.amazonaws.com
IMAGE_STORAGE_PREFIX: images
JSON_WEB_TOKEN_EXPIRY_MINUTES: 10080
NUM_WORKERS: 1
OAUTH_CALLBACK_PROTOCOL: https
PORT: 80
REDIS_HOST: redis:6379
REDIS_IS_CLUSTER: 'false'
TOKEN_AUTH_JWT_ALGO: ES256
TOKENS_CONFIG: API_SERVICE_API_KEY:hex,AUTH_RESINOS_REGISTRY_CODE:hex,COOKIE_SESSION_SECRET:hex,JSON_WEB_TOKEN_SECRET:hex,MIXPANEL_TOKEN:hex,SUPERUSER_PASSWORD:hex,TOKEN_AUTH_BUILDER_TOKEN:hex,VPN_GUEST_API_KEY:hex,VPN_SERVICE_API_KEY:hex,API_VPN_SERVICE_API_KEY:API_SERVICE_API_KEY,REGISTRY2_TOKEN:TOKEN_AUTH_BUILDER_TOKEN
TRUST_PROXY: 172.16.0.0/12
VPN_PORT: 443
WEBRESOURCES_S3_BUCKET: web-resources
WEBRESOURCES_S3_REGION: 'us-east-1' # this is required for minio
# https://github.com/balena-io/open-balena-registry
registry:
<<: [
*base-service,
*with-default-healthcheck,
*with-default-privileges,
]
image: balena/open-balena-registry:2.41.14
volumes:
- certs-data:/certs
- resin-data:/balena
depends_on:
- redis
- s3
environment:
COMMON_REGION: open-balena
HOSTS_CONFIG: REGISTRY2_HOST:registry2,REGISTRY2_TOKEN_AUTH_ISSUER:api,REGISTRY2_TOKEN_AUTH_REALM:api
REGISTRY2_CACHE_ADDR: redis:6379
REGISTRY2_CACHE_DB: 1
REGISTRY2_CACHE_ENABLED: 'true'
REGISTRY2_S3_BUCKET: registry-data
REGISTRY2_STORAGEPATH: /data
TOKENS_CONFIG: REGISTRY2_SECRETKEY:hex
# https://github.com/balena-io/open-balena-vpn
vpn:
<<: [
*base-service,
*with-default-healthcheck,
*with-default-volumes,
# privileges in order from minimum to maximum
*with-network-privileges,
*with-default-privileges,
]
image: balena/open-balena-vpn:v11.30.64
depends_on:
- api
environment:
HOSTS_CONFIG: VPN_HOST:cloudlink
TOKENS_CONFIG: ','
VPN_HAPROXY_USEPROXYPROTOCOL: 'true'
VPN_PORT: 443
# ensure correct service instance IP is registered with the API
VPN_SERVICE_REGISTER_INTERFACE: eth0
# https://github.com/balena-io/open-balena-db
db:
<<: *base-service
image: balena/open-balena-db:v5.2.2
volumes:
- db-data:/var/lib/postgresql/data
environment:
<<: *default-environment
healthcheck:
test: pg_isready -U "$${DB_USER}" -d "$${DB_NAME}"
# https://github.com/balena-io/open-balena-s3
s3:
<<: [
*base-service,
*with-default-healthcheck,
*with-default-privileges,
]
image: balena/open-balena-s3:2.28.60
volumes:
- s3-data:/export
- certs-data:/certs
- resin-data:/balena
environment:
BUCKETS: registry-data;web-resources
HOSTS_CONFIG: REGISTRY2_S3_REGION_ENDPOINT:s3,WEBRESOURCES_S3_HOST:s3
TOKENS_CONFIG: REGISTRY2_S3_KEY:hex,REGISTRY2_S3_SECRET:hex,S3_MINIO_ACCESS_KEY:REGISTRY2_S3_KEY,S3_MINIO_SECRET_KEY:REGISTRY2_S3_SECRET,WEBRESOURCES_S3_ACCESS_KEY:REGISTRY2_S3_KEY,WEBRESOURCES_S3_SECRET_KEY:REGISTRY2_S3_SECRET
# https://hub.docker.com/_/redis
redis:
<<: *base-service
# https://redis.io/blog/what-redis-license-change-means-for-our-managed-service-providers/
image: redis:7.4-alpine
volumes:
- redis-data:/data
healthcheck:
<<: *default-healthcheck
test: echo INFO | redis-cli | grep redis_version
# https://github.com/balena-io/open-balena-haproxy
haproxy:
<<: [
*base-service,
*with-default-privileges,
*with-default-volumes,
]
build: src/haproxy
sysctls:
# https://github.com/docker-library/haproxy/issues/160
net.ipv4.ip_unprivileged_port_start: 0
healthcheck:
<<: *default-healthcheck
test: true | openssl s_client -connect localhost:443
ports:
# haproxy/http
- '80:80/tcp'
# haproxy/tcp-router
- '443:443/tcp'
# haproxy/stats
- '1936:1936/tcp'
environment:
LOGLEVEL: info
# dynamically configure Docker network aliases based on DNS_TLD and ALIAS list
# allows DNS resolution from systemd-less images on the Docker network
haproxy-sidecar:
<<: *base-service
build: src/haproxy-sidecar
volumes:
- /var/run/docker.sock:/host/run/docker.sock
environment:
DOCKER_HOST: unix:///host/run/docker.sock
# resolved internally as {{service}}.{{dns-tld-without-balena-device-uuid}} to haproxy service
ALIASES: api,ca,cloudlink,db,delta,logs,redis,registry2,s3,stats,tunnel
labels:
io.balena.features.balena-socket: 1
io.balena.features.supervisor-api : 1
# https://github.com/balena-io/cert-manager
# https://certbot.eff.org/docs/using.html
# https://certbot-dns-cloudflare.readthedocs.io/
cert-manager:
<<: *base-service
build: src/cert-manager
volumes:
- cert-manager-data:/etc/letsencrypt
- certs-data:/certs
- resin-data:/balena
depends_on:
- balena-ca
environment:
# wildcard certificate for reverse proxy
SSH_KEY_NAMES: ','
SUBJECT_ALTERNATE_NAMES: '*'
labels:
io.balena.features.balena-api: 1
io.balena.features.supervisor-api: 1
# https://github.com/balena-io/ca-private
# https://github.com/cloudflare/cfssl/blob/master/doc/api/intro.txt
balena-ca:
<<: *base-service
image: balena/ca-private:0.0.15
volumes:
- pki-data:/pki
- certs-data:/certs
- resin-data:/balena
healthcheck:
test: curl --silent -I --fail localhost:8888
interval: 60s
timeout: 60s
retries: 10
labels:
# future expansion
io.balena.features.balena-api: 1
io.balena.features.supervisor-api: 1
# --- the following are not required for runtime operation of openBalena
# only relevant when running in AWS/EC2
tag-sidecar:
build: src/tag-sidecar
restart: 'no'
environment:
ENABLED: 'true'
labels:
io.balena.features.balena-api: 1
# Software Under Test (SUT) tests orchestrator
sut:
<<: [
*base-service,
*with-extended-privileges,
*with-network-privileges,
]
build: src/balena-tests
command: /usr/sbin/balena.sh
environment:
DOCKER_CERT_PATH: /docker-pki/client
DOCKER_HOST: docker:2376
DOCKER_TLS_VERIFY: 'true'
GUEST_IMAGE: /balena/balena.img
volumes:
- builder-certs-client:/docker-pki/client
- certs-data:/certs
- resin-data:/balena
labels:
io.balena.features.balena-api: 1
io.balena.features.supervisor-api: 1
restart: 'no'
# virtual Device Under Test (DUT)
dut:
<<: [
*base-service,
*with-extended-privileges,
*with-network-privileges,
]
# https://hub.docker.com/r/qemux/qemu-docker
# https://github.com/qemus/qemu-docker
build: src/test-device
entrypoint:
- /bin/sh
- -c
command:
- /usr/sbin/balena.sh
environment:
GUEST_IMAGE: /balena/balena.img
MEMORY: 3072M
CPU: 4
volumes:
- resin-data:/balena
devices:
- /dev/net/tun
restart: 'no'
# https://hub.docker.com/_/docker
# pseudo(builder) service for balena-tests
docker:
<<: [
*base-service,
*with-extended-privileges,
*with-network-privileges,
]
image: docker:dind
entrypoint:
- /bin/sh
- -c
command:
- |
set -x
cp /certs/root-ca.pem /certs/server-ca.pem /usr/local/share/ca-certificates/ \
&& update-ca-certificates
exec /usr/local/bin/dockerd-entrypoint.sh
volumes:
- /sys:/sys
- builder-certs-ca:/docker-pki/ca
- builder-certs-client:/docker-pki/client
- builder-data:/var/lib/docker
- certs-data:/certs
environment:
DOCKER_TLS_CERTDIR: /docker-pki
healthcheck:
test: docker system info
interval: 60s
timeout: 60s
retries: 5
labels:
io.balena.features.sysfs: 1