-
Notifications
You must be signed in to change notification settings - Fork 4
/
docker-compose.yml
99 lines (98 loc) · 4.54 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
version: "3.9"
services:
emulator:
# set up functions emulator locally
# especially functions configuration
# we need to create `.runtimeconfig.json`
# https://firebase.google.com/docs/functions/local-emulator
build: ./functions
volumes:
- .:/node_app/app
- ./functions/package.json:/node_app/package.json
- ./functions/package-lock.json:/node_app/package-lock.json
- no-used:/node_app/app/functions/node_modules
# avoid emulators repeated download
# https://firebase.google.com/docs/emulator-suite/install_and_configure#running_containerized_emulator_suite_images
- emulators:/home/node/.cache/firebase/emulators/
# used for pubsub emulator connection
environment:
- PUBSUB_EMULATOR_HOST=pubsub_emulator:8085
- PUBSUB_PROJECT_ID=${PUBSUB_PROJECT_ID:-test}
ports:
# need to specify host as 0.0.0.0 so that we can connect to the container
# fron host
# from: https://stackoverflow.com/questions/66176947/run-google-firestore-emulator-with-docker-compose
# from: https://stackoverflow.com/questions/20778771/what-is-the-difference-between-0-0-0-0-127-0-0-1-and-localhost
- "0.0.0.0:5001:5001"
- "0.0.0.0:4000:4000"
- "0.0.0.0:9099:9099"
- "0.0.0.0:8080:8080"
- "0.0.0.0:9199:9199"
stdin_open: true
tty: true
pubsub_emulator:
build:
# https://github.com/GoogleCloudPlatform/cloud-sdk-docker
# https://docs.docker.com/engine/reference/commandline/build/#git-repositories
# https://docs.docker.com/build/building/context/#url-context
# {branch}/{dir}
# WARNING: currently could not use remote git source
# related to buildkit
# https://github.com/docker/compose-cli/issues/1958
# context: https://github.com/GoogleCloudPlatform/cloud-sdk-docker.git#master:debian_slim
# WORKAROUND: manually clone repo to local from https://github.com/GoogleCloudPlatform/cloud-sdk-docker
context: ./cloud-sdk-docker/debian_slim
args:
- INSTALL_COMPONENTS=google-cloud-cli-app-engine-java google-cloud-cli-pubsub-emulator openjdk-17-jre
- CLOUD_SDK_VERSION=431.0.0
volumes:
- ./pubsub-emulator:/pubsub-emulator
# https://cloud.google.com/sdk/gcloud/reference/beta/emulators/pubsub/start
# default host port is localhost:8085
# use --quiet flag to accept default answers for all prompts
command: gcloud --quiet beta emulators pubsub start --data-dir=/pubsub-emulator --host-port=pubsub_emulator:8085
pubsub_clients_setting:
build:
context: ./
dockerfile: Dockerfile.python3.pubsub.clients
# used environment variable to set the compose variable
# https://docs.docker.com/compose/environment-variables/
environment:
- PUBSUB_EMULATOR_HOST=pubsub_emulator:8085
- PUBSUB_PROJECT_ID=${PUBSUB_PROJECT_ID:-test}
# https://cloud.google.com/pubsub/docs/emulator#using_the_emulator
# https://docs.docker.com/compose/compose-file/compose-file-v3/#variable-substitution
# a $$ allows you to refer to environment variables that you don’t want processed by Compose.
# https://docs.docker.com/engine/reference/builder/#cmd
# https://stackoverflow.com/questions/30063907/using-docker-compose-how-to-execute-multiple-commands
# use the shell form or execute a shell directly for shell processing
command: >
bash -c " /wait-for-it/wait-for-it.sh $${PUBSUB_EMULATOR_HOST} --
echo \"pubsub emulator ready($${PUBSUB_EMULATOR_HOST}), start pubsub setting...\"
&& python publisher.py ${PUBSUB_PROJECT_ID:-test} create ${TOPIC_ID:-test-topic}
&& python subscriber.py ${PUBSUB_PROJECT_ID:-test} create ${TOPIC_ID:-test-topic} ${SUBSCRIPTION_ID:-test-topic-sub}"
# https://docs.docker.com/compose/compose-file/compose-file-v3/#depends_on
# improvement direction: https://docs.docker.com/compose/startup-order/
# However, the python pubsub client would wait for port to run and
# set the pubsub topic and subscription
depends_on:
- pubsub_emulator
apollo:
build:
context: ./apollo
dockerfile: Dockerfile.test
volumes:
- ./apollo:/node_app/app
- ./apollo/package.json:/node_app/package.json
- ./apollo/package-lock.json:/node_app/package-lock.json
- no-used:/node_app/app/apollo/node_modules
env_file: ./apollo/compose.env
# used for pubsub emulator connection
environment:
- PUBSUB_EMULATOR_HOST=pubsub_emulator:8085
- PUBSUB_PROJECT_ID=${PUBSUB_PROJECT_ID:-test}
ports:
- "8333:8080"
volumes:
no-used:
emulators: