-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
244 lines (231 loc) · 7.68 KB
/
Copy pathdocker-compose.yml
File metadata and controls
244 lines (231 loc) · 7.68 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
# =============================================================================
# SupplyChainForge — Docker Compose (Local Development)
# =============================================================================
# Services:
# mysql — MySQL 8.0 (shared DB server, per-service databases)
# redis — Redis 7 (cache layer)
# pubsub-emulator — Google Cloud Pub/Sub emulator (local event bus)
# inventory — Inventory microservice (Port 8001)
# order — Order microservice (Port 8002)
# fulfillment — Fulfillment microservice (Port 8003)
#
# Ports (host:container):
# 3306:3306 MySQL
# 6379:6379 Redis
# 8085:8085 Pub/Sub emulator
# 8001:8000 Inventory Service
# 8002:8000 Order Service (NOTE: both services listen on 8000 internally)
# 8003:8002 Fulfillment Service
#
# Usage:
# docker compose up --build # start everything
# docker compose down -v # stop and remove volumes
# NOTE: All service Dockerfiles require this file (docker-compose.yml) to be
# run from the supplychainforge/ directory so the build context is correct.
# =============================================================================
services:
# ── Infrastructure ──────────────────────────────────────────────────────────
mysql:
image: mysql:8.0
container_name: scf-mysql
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-rootpassword}
ports:
- "3306:3306"
volumes:
- mysql_data:/var/lib/mysql
- ./infra/mysql/init:/docker-entrypoint-initdb.d:ro
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-u", "root", "-p${MYSQL_ROOT_PASSWORD:-rootpassword}"]
interval: 10s
timeout: 5s
retries: 10
start_period: 30s
networks:
- scf-network
redis:
image: redis:7-alpine
container_name: scf-redis
restart: unless-stopped
command: redis-server --save 60 1 --loglevel warning
ports:
- "${REDIS_PORT:-6379}:6379"
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
networks:
- scf-network
pubsub-emulator:
image: gcr.io/google.com/cloudsdktool/cloud-sdk:emulators
container_name: scf-pubsub-emulator
restart: unless-stopped
command: >
gcloud beta emulators pubsub start
--project=local-project
--host-port=0.0.0.0:8085
ports:
- "8085:8085"
healthcheck:
test: ["CMD-SHELL", "curl -sf http://localhost:8085/v1/projects/local-project/topics || exit 1"]
interval: 10s
timeout: 5s
retries: 10
start_period: 20s
networks:
- scf-network
# ── Topic / Subscription initialisation ───────────────────────────────────
# Runs once after the emulator is healthy and creates all topics + subscriptions
pubsub-setup:
image: gcr.io/google.com/cloudsdktool/cloud-sdk:emulators
container_name: scf-pubsub-setup
restart: "no"
depends_on:
pubsub-emulator:
condition: service_healthy
environment:
PUBSUB_EMULATOR_HOST: pubsub-emulator:8085
volumes:
- ./infra/pubsub:/scripts:ro
command: bash /scripts/setup_topics.sh
networks:
- scf-network
# ── Microservices ────────────────────────────────────────────────────────────
inventory:
build:
context: .
dockerfile: services/inventory/Dockerfile
target: runtime
platforms:
- linux/amd64
container_name: scf-inventory
restart: unless-stopped
env_file:
- ./services/inventory/.env.example
environment:
DB_HOST: mysql
DB_PORT: 3306
DB_NAME: inventory_db
DB_USER: inventory_user
DB_PASSWORD: inventory_password
REDIS_HOST: redis
REDIS_PORT: 6379
GCP_PROJECT_ID: local-project
PUBSUB_EMULATOR_HOST: pubsub-emulator:8085
PUBSUB_TOPIC_INVENTORY_EVENTS: inventory-events
PUBSUB_SUBSCRIPTION_ORDER_CREATED: inventory-order-created-sub
PUBSUB_SUBSCRIPTION_FULFILLMENT_COMPLETED: inventory-fulfillment-completed-sub
ports:
- "${INVENTORY_SERVICE_PORT:-8001}:8000"
depends_on:
mysql:
condition: service_healthy
redis:
condition: service_healthy
pubsub-setup:
condition: service_completed_successfully
networks:
- scf-network
healthcheck:
test: ["CMD-SHELL", "python -c \"import urllib.request; urllib.request.urlopen('http://localhost:8000/health')\""]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
order:
build:
context: .
dockerfile: services/order/Dockerfile
target: runtime
platforms:
- linux/amd64
container_name: scf-order
restart: unless-stopped
env_file:
- ./services/order/.env.example
environment:
DB_HOST: mysql
DB_PORT: 3306
DB_NAME: order_db
DB_USER: order_user
DB_PASSWORD: order_password
REDIS_HOST: redis
REDIS_PORT: 6379
INVENTORY_SERVICE_URL: http://inventory:8000
GCP_PROJECT_ID: local-project
PUBSUB_EMULATOR_HOST: pubsub-emulator:8085
PUBSUB_TOPIC_ORDER_EVENTS: order-events
PUBSUB_SUBSCRIPTION_FULFILLMENT_ASSIGNED: order-fulfillment-assigned-sub
PUBSUB_SUBSCRIPTION_FULFILLMENT_COMPLETED: order-fulfillment-completed-sub
ports:
- "${ORDER_SERVICE_PORT:-8002}:8000"
depends_on:
mysql:
condition: service_healthy
inventory:
condition: service_healthy
pubsub-setup:
condition: service_completed_successfully
networks:
- scf-network
healthcheck:
test: ["CMD-SHELL", "python -c \"import urllib.request; urllib.request.urlopen('http://localhost:8000/health')\""]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
fulfillment:
build:
context: .
dockerfile: services/fulfillment/Dockerfile
target: runtime
platforms:
- linux/amd64
container_name: scf-fulfillment
restart: unless-stopped
env_file:
- ./services/fulfillment/.env.example
environment:
DB_HOST: mysql
DB_PORT: 3306
DB_NAME: fulfillment_db
DB_USER: fulfillment_user
DB_PASSWORD: fulfillment_password
REDIS_HOST: redis
REDIS_PORT: 6379
ORDER_SERVICE_URL: http://order:8000
GCP_PROJECT_ID: local-project
PUBSUB_EMULATOR_HOST: pubsub-emulator:8085
PUBSUB_TOPIC_FULFILLMENT_EVENTS: fulfillment-events
PUBSUB_SUBSCRIPTION_ORDER_CREATED: fulfillment-order-created-sub
ports:
- "${FULFILLMENT_SERVICE_PORT:-8003}:8002"
depends_on:
mysql:
condition: service_healthy
order:
condition: service_healthy
pubsub-setup:
condition: service_completed_successfully
networks:
- scf-network
healthcheck:
test: ["CMD-SHELL", "python -c \"import urllib.request; urllib.request.urlopen('http://localhost:8002/health')\""]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
# ── Volumes & Networks ────────────────────────────────────────────────────────
volumes:
mysql_data:
name: scf-mysql-data
redis_data:
name: scf-redis-data
networks:
scf-network:
name: scf-network
driver: bridge