-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
304 lines (283 loc) · 9.3 KB
/
docker-compose.yml
File metadata and controls
304 lines (283 loc) · 9.3 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
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
# main docker-compose file for local development.
#
# runs & configures by default:
# * `db` -> postgres db
# * `s3` -> minio
#
# optional profile: `web`:
# * `web` -> webserver
#
# optional profile: `builder`:
# * `builder-a` -> build-server 1
# * `builder-b` -> build-server 2
# ( two parallel build-servers, sharing nothing apart
# from the build queue they access)
#
# optional profile: `watcher`:
# * `registry-watcher` ->
# - crates.io registry watcher
# - repo-stats updater
# - cdn invalidator
# - release-rebuild-enqueuer
#
# optional profile: `metrics`:
# * `opentelemetry` -> a debug opentelemetry receiver
#
# optional profile: `full`: all of the above.
#
# Services purely for manual usage with `docker compose run` are:
# * `cli`: to run simple CLI commands that only need the database & S3
# * `builder-cli`: to run CLI commands that need the build environment.
# * `registry-watcher-cli`: to run CLI commands that need the crates.io index.
#
# CAVEATS:
# * the build-servers have to run on the `linux/amd64` platform,
# while it doesn't matter for the rest of the services.
# This means for example on a Mac, the layers will be
# cached separately, once for `linux/amd64` and once for
# `linux/arm64`, which increases build-time.
#
# * volumes: typically docker-native volumes are faster than mounts, but
# sometimes annoying to inspect for debugging.
# For now we choose:
# * docker-native for DB, S3, rustwide workspace, crates.io index
# * mounts for prefix
#
x-docker-cache: &docker-cache
# shared configuration to cache docker layers across CI runs.
# can just always be in in the `docker-compose.yml`, and will
# just do nothing if we're not on GHA.
# So feel free to add more techniques if needed.
cache_from:
- type=gha
cache_to:
- type=gha,mode=max
x-healthcheck: &healthcheck-interval
interval: 10s
timeout: 1s
start_interval: 1s
start_period: 10s
x-environment: &environment
# needed default environment that can be overwritten in `.docker.env`
# Example in `.docker.env.sample`
RUST_BACKTRACE: ${RUST_BACKTRACE:-true}
DOCSRS_LOG: ${DOCSRS_LOG:-docs_rs=trace,tower_http=debug,rustwide=info,aws_smithy_http=trace,axum=debug}
# fixed environment to connect the different services in this file properly
DOCSRS_PREFIX: /opt/docsrs/prefix
DOCSRS_DATABASE_URL: postgresql://cratesfyi:password@db
DOCSRS_MIN_POOL_IDLE: 1
DOCSRS_MIN_POOL_SIZE: 2
DOCSRS_MAX_POOL_SIZE: 10
DOCSRS_STORAGE_BACKEND: s3
S3_ENDPOINT: http://s3:9000
AWS_ACCESS_KEY_ID: cratesfyi
AWS_SECRET_ACCESS_KEY: secret_key
x-builder-environment: &builder-environment
<<: *environment
# default builder environment that can be overwritten in `.docker.env`
DOCSRS_INCLUDE_DEFAULT_TARGETS: ${DOCSRS_INCLUDE_DEFAULT_TARGETS:-false}
DOCSRS_DOCKER_IMAGE: ${DOCSRS_DOCKER_IMAGE:-ghcr.io/rust-lang/crates-build-env/linux-micro}
# fixed environment to connect the different services in this file properly
DOCSRS_RUSTWIDE_WORKSPACE: /opt/docsrs/rustwide
DOCSRS_COMPILER_METRICS_PATH: /opt/docsrs/prefix/metrics
DOCSRS_DOCKER: true
DOCSRS_BUILD_CPU_LIMIT: 2
x-build: &build
context: .
<<: *docker-cache
dockerfile: ./dockerfiles/Dockerfile
args:
PROFILE: dev
PROFILE_DIR: debug
x-builder: &builder
build:
<<: *build
target: build-server
# build servers only work with linux/amd64 for now.
# This makes them much slower when working on a mac, but
# it needs some work and digging into the builder to fix
# this.
platform: "linux/amd64"
depends_on:
- db
- s3
environment:
<<: *builder-environment
env_file:
- .docker.env
x-registry-watcher: ®istry-watcher
build:
<<: *build
target: registry-watcher
depends_on:
- db
- s3
volumes:
- "./ignored/docker-registry-watcher/prefix:/opt/docsrs/prefix"
- crates-io-index:/opt/docsrs/crates.io-index
environment:
<<: *environment
# the crates.io index can be shared between the registry watcher & its
# CLI service.
# So we configure it to be separate from the prefix.
# Also on a native docker volume for performance
REGISTRY_INDEX_PATH: /opt/docsrs/crates.io-index
# configure the rebuild-queuer,
DOCSRS_MAX_QUEUED_REBUILDS: ${DOCSRS_MAX_QUEUED_REBUILDS:-10}
env_file:
- .docker.env
services:
web:
build:
<<: *build
target: web-server
depends_on:
- db
- s3
ports:
- "3000:3000"
environment:
<<: *environment
DOCSRS_RENDER_THREADS: 2
DOCSRS_S3_STATIC_ROOT_PATH: http://localhost:9000/rust-docs-rs
env_file:
- .docker.env
healthcheck:
<<: *healthcheck-interval
test: curl --silent --fail localhost:3000/
profiles:
- web
- full
registry-watcher:
<<: *registry-watcher
profiles:
- watcher
- full
registry-watcher-cli:
<<: *registry-watcher
profiles:
# watcher-CLI should not be run as background daemon, just manually
- manual
builder-a:
<<: *builder
volumes:
- "rustwide-builder-a:/opt/docsrs/rustwide"
- "./ignored/docker-builder-a/prefix:/opt/docsrs/prefix"
# this exposes the docker engine from the host machine
# to the build-server inside the container.
- "/var/run/docker.sock:/var/run/docker.sock"
profiles:
- builder
- full
builder-b:
<<: *builder
volumes:
- "rustwide-builder-b:/opt/docsrs/rustwide"
- "./ignored/docker-builder-b/prefix:/opt/docsrs/prefix"
# this exposes the docker engine from the host machine
# to the build-server inside the container.
- "/var/run/docker.sock:/var/run/docker.sock"
profiles:
- builder
- full
builder-cli:
<<: *builder
volumes:
- "rustwide-builder-cli:/opt/docsrs/rustwide"
- "./ignored/docker-builder-cli/prefix:/opt/docsrs/prefix"
# this exposes the docker engine from the host machine
# to the build-server inside the container.
- "/var/run/docker.sock:/var/run/docker.sock"
profiles:
# builder-CLI should not be run as background daemon, just manually
- manual
cli:
build:
<<: *build
target: cli
depends_on:
# only for clarification.
# When using "docker compose run", these dependencies are ignored,
# we handle this in our `just` commands.
- db
- s3
environment: *environment
volumes:
- "./ignored/docker-cli/prefix:/opt/docsrs/prefix"
env_file:
- .docker.env
profiles:
# CLI should not be run as background daemon, just manually
- manual
db:
build:
context: ./dockerfiles
dockerfile: ./Dockerfile-postgres
<<: *docker-cache
volumes:
- postgres-data:/var/lib/postgresql/data
environment:
POSTGRES_USER: cratesfyi
POSTGRES_PASSWORD: password
ports:
# Use a non-standard port on the host to avoid conflicting
# with existing postgres servers
- "127.0.0.1:15432:5432"
healthcheck:
<<: *healthcheck-interval
test: pg_isready --username cratesfyi
s3:
image: minio/minio
entrypoint: >
/bin/sh -c "
mkdir -p /data/rust-docs-rs;
minio server /data --console-address ":9001";
"
ports:
- "127.0.0.1:9000:9000"
- "127.0.0.1:9001:9001"
volumes:
- minio-data:/data
environment:
MINIO_ROOT_USER: cratesfyi
MINIO_ROOT_PASSWORD: secret_key
healthcheck:
<<: *healthcheck-interval
test: mc ready local
opentelemetry:
build:
context: ./dockerfiles
dockerfile: ./Dockerfile-opentelemetry
<<: *docker-cache
ports:
- "127.0.0.1:4317:4317"
healthcheck:
<<: *healthcheck-interval
test: curl --silent --fail http://localhost:13133/health
profiles:
# we rarely need to test with actual opentelemetry, so always
# running it is a waste.
- metrics
- full
gui_tests:
platform: "linux/amd64"
build:
context: .
dockerfile: ./dockerfiles/Dockerfile-gui-tests
<<: *docker-cache
network_mode: "host"
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
- "${PWD}:/build/out"
profiles:
# gui_tests should not be run as background daemon.
# Run via `just run-gui-tests`.
- manual
volumes:
postgres-data: {}
minio-data: {}
crates-io-index: {}
rustwide-builder-a: {}
rustwide-builder-b: {}
rustwide-builder-cli: {}