Repository navigation
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
617 lines (595 loc) · 26.1 KB
/
Copy pathdocker-compose.yml
File metadata and controls
617 lines (595 loc) · 26.1 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
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
# See usages of this compose file and its commands in the README.md file
volumes:
local_pg_data:
driver: local
local_es_data:
driver: local
# There are populated by .env when using docker compose
x-application-variables: &application-vars
# Primary data stores for the API
DATABASE_URL: ${DATABASE_URL}
DOWNLOAD_DATABASE_URL: ${DOWNLOAD_DATABASE_URL}
ES_HOSTNAME: ${ES_HOSTNAME}
# For connection to Broker
BROKER_DB: ${BROKER_DB}
# For local development
DJANGO_DEBUG: ${DJANGO_DEBUG}
DJANGO_SETTINGS_MODULE: ${DJANGO_SETTINGS_MODULE}
IS_LOCAL: ${IS_LOCAL}
# S3
RUSTFS_ACCESS_KEY: ${RUSTFS_ACCESS_KEY}
RUSTFS_SECRET_KEY: ${RUSTFS_SECRET_KEY}
RUSTFS_HOST: ${RUSTFS_HOST}
RUSTFS_PORT: ${RUSTFS_PORT}
# Defined for tracing
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: ${OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}
TOGGLE_OTEL_CONSOLE_LOGGING: ${TOGGLE_OTEL_CONSOLE_LOGGING}
x-spark-submit-variables: &spark-submit-vars
<<: *application-vars
AWS_ACCESS_KEY_ID: ${RUSTFS_ACCESS_KEY}
AWS_ENDPOINT_URL: http://${RUSTFS_HOST}:${RUSTFS_PORT}
AWS_SECRET_ACCESS_KEY: ${RUSTFS_SECRET_KEY}
# Needed for the Spark containers to interact
SPARK_MASTER_HOST: ${SPARK_MASTER_HOST}
SPARK_MASTER_PORT: ${SPARK_MASTER_PORT}
SPARK_WORKER_WEBUI_PORT: ${SPARK_WORKER_WEBUI_PORT}
# This env var needs to be picked up as the config for the spark.sql.warehouse.dir spark conf setting when
# SparkSessions are created inside a spark-submitted job
# (i.e., target where host warehouse dir is bound in volume config)
SPARK_SQL_WAREHOUSE_DIR: ${TARGET_SPARK_SQL_WAREHOUSE_DIR}
# This env var needs to be picked up as the path part of the config for the
# spark.hadoop.javax.jdo.option.ConnectionURL spark conf setting when SparkSessions are created inside a
# spark-submitted job
# (i.e., a metastore_db sub dir of the target where host warehouse dir is bound in volume config.)
HIVE_METASTORE_DERBY_DB_DIR: ${TARGET_HIVE_METASTORE_DERBY_DB_DIR}
services:
usaspending-db:
command: postgres -c 'max_connections=500'
profiles: # must pass --profile usaspending to docker compose for this to come up, or run a service with one of these other profiles
- ci
- manage
- spark
- test
- usaspending
build:
context: .
dockerfile: db.Dockerfile
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U ${USASPENDING_DB_USER} -d ${USASPENDING_DB_NAME}" ]
interval: 5s
timeout: 5s
retries: 5
shm_size: 1g
container_name: usaspending-db
volumes:
- type: volume
source: local_pg_data
target: /var/lib/postgresql/data
ports:
- ${USASPENDING_DB_PORT}:5432
environment:
POSTGRES_USER: ${USASPENDING_DB_USER}
POSTGRES_PASSWORD: ${USASPENDING_DB_PASSWORD}
POSTGRES_DB: ${USASPENDING_DB_NAME}
usaspending-manage:
profiles:
- manage # must pass --profile manage to docker compose for this to come up, or use docker compose run
image: usaspending-development # when an image by this name is not found in the local repo, and it is forced to build, it will use this as the tag
build: .
container_name: usaspending-manage
volumes:
- type: bind
source: .
target: /usaspending-api
read_only: false
depends_on:
- usaspending-db
# For an interactive shell, override this command with: docker compose run --rm usaspending-manage python3 -u manage.py shell
entrypoint: ["uv", "run", "manage.py"]
environment:
<<: *application-vars
usaspending-test:
profiles:
- test # must pass --profile test to docker compose for this to come up, or use docker compose run
image: usaspending-development # when an image by this name is not found in the local repo, and it is forced to build, it will use this as the tag
build:
context: .
dockerfile: development.Dockerfile
args:
PROJECT_LOG_DIR: ${PROJECT_LOG_DIR}
SPARK_LOGGING_LEVEL: ${SPARK_LOGGING_LEVEL}
init: true # needed for the reaping of processes created for tests
container_name: usaspending-test
volumes:
- type: bind
source: .
target: /usaspending-api
read_only: false
# Required to interact with host's docker daemon from within this running container,
# to spin up the data-act-broker-init-test-db container used for broker integration tests (see: conftest.broker_db_setup)
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
- usaspending-s3
- usaspending-db
- usaspending-es
entrypoint: [] # override entrypoint
environment:
<<: *spark-submit-vars
# Location in host machine where broker src code root can be found
DATA_BROKER_SRC_PATH: "${PWD}/../data-act-broker-backend"
# Tests will retrieve the root directory from the path and use it to assume the docker network name
PROJECT_SRC_PATH: "${PWD}"
usaspending-style-checks:
profiles:
- ci # must pass --profile ci to docker compose for this to come up, or use docker compose run
image: usaspending-development
build:
context: .
dockerfile: development.Dockerfile
container_name: usaspending-style-checks
volumes:
- type: bind
source: .
target: /usaspending-api
read_only: false
entrypoint: [] # override entrypoint
command:
- sh
- -c
- |
printf -- "==============\nFormatting code:\n"
git diff --name-only --diff-filter=ACMR | grep '\.py$' | xargs -r uv run ruff format
printf -- "==============\nChecking code syntax and quality:\n"
git diff --name-only --diff-filter=ACMR | grep '\.py$' | xargs -r uv run ruff check --fix || exit 1
printf -- "==============\nChecking API documentation files:\n"
python3 manage.py check_for_endpoint_documentation
printf -- "==============\nChecking API contracts:\n"
dredd > dredd-results.txt && echo '! grep -E "^[warn:|error:]" dredd-results.txt' | bash
environment:
<<: *application-vars
# dredd-hooks (unmaintained since 2018) imports the `imp` module, removed in Python 3.12; patches/imp.py shims it
PYTHONPATH: patches
usaspending-ci:
profiles:
- ci # must pass --profile ci to docker compose for this to come up, or use docker compose run
image: usaspending-development # when an image by this name is not found in the local repo, and it is forced to build, it will use this as the tag
build:
context: .
dockerfile: development.Dockerfile
init: true # needed for the reaping of processes created for tests
container_name: usaspending-ci
volumes:
- type: bind
source: .
target: /usaspending-api
read_only: false
# Required to interact with host's docker daemon from within this running container,
# to spin up the data-act-broker-init-test-db container used for broker integration tests (see: conftest.broker_db_setup)
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
usaspending-db:
condition: service_healthy
usaspending-es:
condition: service_healthy
usaspending-style-checks:
condition: service_completed_successfully
entrypoint: [] # override entrypoint
command:
- sh
- -c
- |
printf -- "-------\nRunning non-spark integration tests:\n"
pytest --override-ini=python_files="**/tests/integration/*" -m "(not signal_handling and not spark)" --no-cov --disable-warnings --reuse-db --numprocesses auto
printf -- "-------\nRunning non-spark integration tests with signal handling:\n"
pytest --override-ini=python_files="**/tests/integration/*" -m "(signal_handling and not spark)" --no-cov --disable-warnings --reuse-db --numprocesses 0
printf -- "-------\nRunning spark integration tests -- load to / from delta:\n"
pytest --override-ini=python_files="test_*.py *_test.py" -m "(spark)" -k "test_load_to_from_delta.py" --no-cov --disable-warnings --reuse-db --numprocesses 2
printf -- "-------\nRunning spark integration tests -- load transaction fabs / fpds:\n"
pytest --override-ini=python_files="test_*.py *_test.py" -m "(spark)" -k "test_load_transactions_in_delta_fabs_fpds.py" --no-cov --disable-warnings --reuse-db --numprocesses 0
printf -- "-------\nRunning spark integration tests -- load transaction lookup:\n"
pytest --override-ini=python_files="test_*.py *_test.py" -m "(spark)" -k "test_load_transactions_in_delta_lookups.py" --no-cov --disable-warnings --reuse-db --numprocesses 0
printf -- "-------\nRunning spark integration tests -- other:\n"
pytest --override-ini=python_files="test_*.py *_test.py" -m "(spark)" -k "(not test_load_to_from_delta.py and not test_load_transactions_in_delta_lookups.py and not test_load_transactions_in_delta_fabs_fpds.py)" --no-cov --disable-warnings --reuse-db --numprocesses auto
printf -- "-------\nRunning unit tests:\n"
pytest --override-ini=python_files="test_*.py *_test.py" -m "(not signal_handling)" --ignore-glob="**/tests/integration/*" --no-cov --disable-warnings --reuse-db --numprocesses auto
printf -- "-------\nRunning unit tests with signal handling:\n"
pytest --override-ini=python_files="test_*.py *_test.py" -m "(signal_handling)" --ignore-glob="**/tests/integration/*" --no-cov --disable-warnings --reuse-db --numprocesses 0
environment:
<<: *spark-submit-vars
# Location in host machine where broker src code root can be found
DATA_BROKER_SRC_PATH: "${PWD}/../data-act-broker-backend"
# Tests will retrieve the root directory from the path and use it to assume the docker network name
PROJECT_SRC_PATH: "${PWD}"
usaspending-api: # builds using the default Dockerfile to mirror deployed environments for local testing
profiles:
- usaspending # must pass --profile usaspending to docker compose for this to come up
image: usaspending-backend # when an image by this name is not found in the local repo, and it is forced to build, it will use this as the tag
build: .
container_name: usaspending-api
init: true # needed for the reaping of processes; mostly related to downloads run in a process
volumes:
- type: bind
source: .
target: /usaspending-api
read_only: false
ports:
- 8000:8000
depends_on:
- usaspending-db
- usaspending-es
restart: on-failure:3 # 3 max attempt, and then it will stop restarting
# Must wait on postgres db to be up (~9s)
command: /bin/sh -c "sleep 9s; python3 -u manage.py runserver --verbosity 2 0.0.0.0:8000"
environment:
<<: *application-vars
usaspending-bulk-download:
profiles:
- usaspending # must pass --profile usaspending to docker compose for this to come up
image: usaspending-download # when an image by this name is not found in the local repo, and it is forced to build, it will use this as the tag
build:
context: .
dockerfile: download.Dockerfile
init: true # needed for the reaping of processes
container_name: usaspending-bulk-download
restart: on-failure:5 # 5 max attempt, and then it will stop restarting. NOTE: bulk download errors will cause one failure+restart iterations
volumes:
- type: bind
source: .
target: /usaspending-api
read_only: false
# Required to interact with host's docker daemon from within this running container,
# to submit a spark job via the spark-submit container (see download_sqs_worker._run_spark_download)
- /var/run/docker.sock:/var/run/docker.sock
command: python3 manage.py download_sqs_worker
environment:
<<: *application-vars
usaspending-es:
profiles:
- usaspending # must pass --profile usaspending to docker compose for this to come up
- test
- ci
image: opensearchproject/opensearch:2.9.0
healthcheck:
test: [ "CMD-SHELL", "curl -f -k http://localhost:9200/_cluster/health || exit 1" ]
interval: 10s
timeout: 5s
retries: 10
start_period: 60s
container_name: usaspending-es
environment:
- node.name=usaspending-es
- discovery.seed_hosts=usaspending-es
- cluster.initial_master_nodes=usaspending-es
- cluster.name=usaspending
- network.host=0.0.0.0
- transport.host=localhost
- bootstrap.memory_lock=true
- plugins.security.disabled=true
- "OPENSEARCH_JAVA_OPTS=-Xms2g -Xmx2g" # Ensure Docker is allocated plenty of memory, otherwise this will fail
# Inject plugin install, then resume with orignial entrypoint command
command: >
/bin/sh -c "
if [ ! -d /usr/share/opensearch/plugins/mapper-murmur3 ]; then
/usr/share/opensearch/bin/opensearch-plugin install mapper-murmur3
fi
/usr/share/opensearch/opensearch-docker-entrypoint.sh"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- type: volume
source: local_es_data
target: /usr/share/opensearch/data
ports:
- ${ES_PORT}:9200
usaspending-kibana-es:
profiles:
- usaspending # must pass --profile usaspending to docker compose for this to come up
image: opensearchproject/opensearch-dashboards:2.9.0
container_name: usaspending-kibana-es
depends_on:
- usaspending-es
# ELASTICSEARCH_HOSTS should match the port for "usaspending-es"; value will need to be updated if using Windows
environment:
- OPENSEARCH_HOSTS="http://usaspending-es:9200"
- DISABLE_SECURITY_DASHBOARDS_PLUGIN=true
- DISABLE_SECURITY_PLUGIN=true
ports:
- 5601:5601
usaspending-s3:
profiles: # must pass one of these with --profile to docker compose
- s3
- spark
- test
image: rustfs/rustfs:1.0.0
container_name: usaspending-s3
volumes:
- type: bind
source: .
target: /usaspending-api
read_only: false
- type: bind
source: ${S3_DATA_DIR}
target: /data
ports:
- ${RUSTFS_PORT}:10001
- ${RUSTFS_CONSOLE_PORT}:10002
environment:
RUSTFS_ACCESS_KEY: ${RUSTFS_ACCESS_KEY}
RUSTFS_SECRET_KEY: ${RUSTFS_SECRET_KEY}
entrypoint: ["rustfs", "server", "--address", ":10001", "--console-address", ":10002", "/data"]
healthcheck:
test: ["CMD", "curl", "-f", "http://${RUSTFS_HOST}:${RUSTFS_PORT}/health/ready"]
interval: 30s
timeout: 20s
retries: 3
# One-shot container that provisions the buckets and seed files RustFS needs for local dev/tests.
# RustFS (unlike MinIO) does not auto-discover buckets that are created by just placing directories/files directly
# on its backing filesystem, so this must go through the S3 API.
usaspending-s3-init:
profiles:
- s3
- spark
- test
image: rustfs/rc:v0.1.35
container_name: usaspending-s3-init
depends_on:
usaspending-s3:
condition: service_healthy
volumes:
- type: bind
source: .
target: /usaspending-api
read_only: true
environment:
RUSTFS_ACCESS_KEY: ${RUSTFS_ACCESS_KEY}
RUSTFS_SECRET_KEY: ${RUSTFS_SECRET_KEY}
entrypoint: ["/bin/sh"]
command:
- -c
- |
rc alias set local http://usaspending-s3:10001 "$$RUSTFS_ACCESS_KEY" "$$RUSTFS_SECRET_KEY"
rc mb local/dti-da-public-files-nonprod || true
rc mb local/bulk-download || true
rc mb local/monthly-download || true
rc mb local/data || true
rc cp /usaspending-api/usaspending_api/data/Data_Dictionary_Crosswalk.xlsx local/dti-da-public-files-nonprod/user_reference_docs/Data_Dictionary_Crosswalk.xlsx
rc cp /usaspending-api/usaspending_api/data/COVID-19_download_readme.txt local/data/files/COVID-19_download_readme.txt
spark-master:
profiles:
- spark # must pass --profile spark to docker compose for this to come up
- test
image: usaspending-development
# build context path needs to be relative to project root, from where docker compose will be run
build:
context: .
dockerfile: development.Dockerfile
args:
PROJECT_LOG_DIR: ${PROJECT_LOG_DIR}
SPARK_LOGGING_LEVEL: ${SPARK_LOGGING_LEVEL}
container_name: spark-master
environment:
<<: *spark-submit-vars
entrypoint: [] # override the entrypoint
command: >
/bin/sh -c "
$${SPARK_HOME}/bin/spark-class org.apache.spark.deploy.master.Master \
--port $${SPARK_MASTER_PORT} \
--webui-port $${SPARK_MASTER_WEBUI_PORT}"
ports:
- ${SPARK_MASTER_PORT}
- ${SPARK_MASTER_WEBUI_PORT}
volumes:
- type: bind
source: .
target: /usaspending-api
read_only: false
# Required to interact with host's docker daemon from within this running container and access the Broker DB
- /var/run/docker.sock:/var/run/docker.sock
spark-worker:
profiles:
- spark # must pass --profile spark to docker compose for this to come up
- test
image: usaspending-development
# build context path needs to be relative to project root, from where docker compose will be run
build:
context: .
dockerfile: development.Dockerfile
args:
PROJECT_LOG_DIR: ${PROJECT_LOG_DIR}
SPARK_LOGGING_LEVEL: ${SPARK_LOGGING_LEVEL}
container_name: spark-worker
depends_on:
- spark-master
environment:
<<: *spark-submit-vars
entrypoint: [] # override the entrypoint
command: /bin/sh -c "$${SPARK_HOME}/bin/spark-class org.apache.spark.deploy.worker.Worker --webui-port $${SPARK_WORKER_WEBUI_PORT} spark://$${SPARK_MASTER_HOST}:$${SPARK_MASTER_PORT}"
ports:
- ${SPARK_WORKER_WEBUI_PORT}:4041
volumes:
- type: bind
source: .
target: /usaspending-api
read_only: false
# Required to interact with host's docker daemon from within this running container and access the Broker DB
- /var/run/docker.sock:/var/run/docker.sock
spark-history-server:
profiles:
- spark # must pass --profile spark to docker compose for this to come up
- test
image: usaspending-development
# build context path needs to be relative to project root, from where docker compose will be run
build:
context: .
dockerfile: development.Dockerfile
args:
PROJECT_LOG_DIR: ${PROJECT_LOG_DIR}
SPARK_LOGGING_LEVEL: ${SPARK_LOGGING_LEVEL}
container_name: spark-history-server
environment:
SPARK_HISTORY_SERVER_PORT: ${SPARK_HISTORY_SERVER_PORT}
entrypoint: [] # override the entrypoint
command: /usr/bin/sh -c "$${SPARK_HOME}/bin/spark-class org.apache.spark.deploy.history.HistoryServer"
ports:
- ${SPARK_HISTORY_SERVER_PORT}:18080
volumes:
- type: bind
source: .
target: /usaspending-api
read_only: false
# Example of running spark-submit container:
# NOTE: double check package dependency versions here with those used in unit tests (conftest_spark.py), as these docs could have gotten stale
# (1) Review config values in usaspending_api/config/envs/local.py and override any as needed in a .env file or -e environment variable
# (2) Deploy RustFS in docker container (see README.md)
# (3) Deploy the postgres DB docker container, if your script connects to a DB.
# - If so, also export a JDBC_URL environment variable to pass in to the spark-submit container so it can find its connection
# (4) If reading or writing to S3, make sure the bucket given by the value of config setting CONFIG.AWS_S3_BUCKET exists
# - e.g. create via UI at http://localhost:10001
# - or use RustFS client CLI: rc mb local/data
# (4) Run the spark-submit container, citing the dependent packages:
# (NOTEs:
# - postgresql is needed as a JDBC driver, if connecting to a Postgres DB
# - delta-core is needed to read/write in Delta Lake format
# - hadoop-aws is needed for the S3AFileSystem.java, used to write data to S3,
# - and should use the same hadoop version in your local setup
# - NOTE that specifying hadoop-awas should pull in on its own the required version of the aws-java-sdk
# - spark-hive is needed to use a hive metastore_db of schemas and tables
# - the Docker image at this time only installs spark and hadoop standalone, which does not seem to include all the needed Hive jars
#
# make docker-compose-run profiles="--profile spark" args="--rm -e RUSTFS_HOST=usaspending-s3 -e JDBC_URL -e COMPONENT_NAME='My Spark Prototype Script' spark-submit \
# --packages <SEE MAKEFILE> \
# /usaspending-api/usaspending_api/etl/tests/path_to_your_spark_prototype_script.py"
spark-submit:
profiles:
- spark # must pass --profile spark to docker compose for this to come up
- test
image: usaspending-development
# build context path needs to be relative to project root, from where docker compose will be run
build:
context: .
dockerfile: development.Dockerfile
args:
PROJECT_LOG_DIR: ${PROJECT_LOG_DIR}
SPARK_LOGGING_LEVEL: ${SPARK_LOGGING_LEVEL}
container_name: spark-submit
depends_on:
- usaspending-s3
- spark-history-server
- spark-master
- spark-worker
- usaspending-db
environment:
<<: *spark-submit-vars
# NOTE: entrypoint CANNOT interpolate env vars when processed. They are passed through literally.
# So in using 1 $ rather than 2 $$, the var is evaluated based on the current SHELL ENV when docker compose is run,
# and interpolated before accessed as the entrypoint.
# While this service has values for these interpolated vars in the environment: element, those are not used here,
# but merely passed into the container. KEEP the two references to these vars and their defaults consistent!
# To see what it will be, you can run docker compose config (i.e. make docker-compose-config in this project's Makefile)
entrypoint: /usr/bin/spark-submit --master spark://${SPARK_MASTER_HOST}:${SPARK_MASTER_PORT}
command: --help
volumes:
- type: bind
source: .
target: /usaspending-api
read_only: false
# NOTE: The hive metastore_db Derby database folder is expected to be configured to show up as a subfolder of the spark-warehouse dir
- type: bind
source: ${SOURCE_SPARK_SQL_WAREHOUSE_DIR}
target: ${TARGET_SPARK_SQL_WAREHOUSE_DIR}
# Required to interact with host's docker daemon from within this running container and access the Broker DB
- /var/run/docker.sock:/var/run/docker.sock
spark-shell:
profiles:
- spark # must pass --profile spark to docker compose for this to come up
- test
#image: public.ecr.aws/emr-serverless/spark/emr-7.12.0:latest
image: usaspending-development
# build context path needs to be relative to project root, from where docker compose will be run
build:
context: .
dockerfile: development.Dockerfile
args:
PROJECT_LOG_DIR: ${PROJECT_LOG_DIR}
SPARK_LOGGING_LEVEL: ${SPARK_LOGGING_LEVEL}
container_name: spark-shell
depends_on:
- usaspending-s3
environment:
<<: *spark-submit-vars
# NOTE: entrypoint CANNOT interpolate env vars when processed. They are passed through literally.
# So in using 1 $ rather than 2 $$, the var is evaluated based on the current SHELL ENV when docker compose is run,
# and interpolated before accessed as the entrypoint.
# While this service has values for these interpolated vars in the environment: element, those are not used here,
# but merely passed into the container. KEEP the two references to these vars and their defaults consistent!
# To see what it will be, you can run docker compose config (i.e. make docker-compose-config in this project's Makefile)
entrypoint: >
/usr/bin/pyspark --master local[*]
--conf spark.sql.extensions=io.delta.sql.DeltaSparkSessionExtension
--conf spark.sql.catalog.spark_catalog=org.apache.spark.sql.delta.catalog.DeltaCatalog
--conf spark.hadoop.fs.s3a.endpoint=${RUSTFS_HOST}:${RUSTFS_PORT}
--conf spark.hadoop.fs.s3a.access.key=${RUSTFS_ACCESS_KEY}
--conf spark.hadoop.fs.s3a.secret.key=${RUSTFS_SECRET_KEY}
--conf spark.hadoop.fs.s3a.connection.ssl.enabled=false
--conf spark.hadoop.fs.s3a.path.style.access=true
--conf spark.sql.catalogImplementation=hive
--conf spark.sql.warehouse.dir='${TARGET_SPARK_SQL_WAREHOUSE_DIR}'
--conf spark.hadoop.javax.jdo.option.ConnectionURL='jdbc:derby:;databaseName=${TARGET_HIVE_METASTORE_DERBY_DB_DIR};create=true'
volumes:
- type: bind
source: .
target: /usaspending-api
read_only: false
# NOTE: The hive metastore_db Derby database folder is expected to be configured to show up as a subfolder of the spark-warehouse dir
- type: bind
source: ${SOURCE_SPARK_SQL_WAREHOUSE_DIR}
target: ${TARGET_SPARK_SQL_WAREHOUSE_DIR}
read_only: false
otel-collector:
profiles:
- tracing
image: otel/opentelemetry-collector:0.86.0
command: [ "--config=/etc/otel-collector.yaml" ]
volumes:
- ./otel-collector.yaml:/etc/otel-collector.yaml
# Tempo runs as user 10001, and docker compose creates the volume as root.
# As such, we need to chown the volume in order for Tempo to start correctly.
tempo-init:
profiles:
- tracing
image: &tempoImage grafana/tempo:2.8.2
user: root
entrypoint:
- "chown"
- "10001:10001"
- "/var/tempo"
volumes:
- ./tempo-data:/var/tempo
tempo:
profiles:
- tracing
image: *tempoImage
command: [ "-config.file=/etc/tempo.yaml" ]
volumes:
- ./tempo.yaml:/etc/tempo.yaml
- ./tempo-data:/var/tempo
ports:
- "3200" # tempo
- "4317" # otlp grpc
depends_on:
- tempo-init
grafana:
profiles:
- tracing
image: grafana/grafana:11.0.0
volumes:
- ./grafana-datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml
environment:
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
- GF_AUTH_DISABLE_LOGIN_FORM=true
- GF_FEATURE_TOGGLES_ENABLE=traceqlEditor
ports:
- "3000:3000"