-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
188 lines (179 loc) · 5.86 KB
/
docker-compose.yml
File metadata and controls
188 lines (179 loc) · 5.86 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
# week05/docker-compose.yml
version: "3.8"
services:
# RabbitMQ Message Broker
rabbitmq:
image: rabbitmq:3-management-alpine
container_name: rabbitmq
restart: always
ports:
- "5672:5672" # Standard AMQP port
- "15672:15672" # Management UI (accessible via http://localhost:15672)
environment:
RABBITMQ_DEFAULT_USER: guest
RABBITMQ_DEFAULT_PASS: guest
healthcheck:
test: ["CMD", "rabbitmq-diagnostics", "check_port_connectivity"]
interval: 10s
timeout: 5s
retries: 5
# PostgreSQL Database for Product Service
product_db:
image: postgres:15-alpine
container_name: product_db_container
restart: always
environment:
POSTGRES_DB: products
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- "5432:5432" # Map container port 5432 to host port 5432
volumes:
# Persistent volume for Product Service database data
- product_db_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d products"]
interval: 5s
timeout: 5s
retries: 5
# PostgreSQL Database for Order Service
order_db:
image: postgres:15-alpine
container_name: order_db_container
restart: always
environment:
POSTGRES_DB: orders
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- "5433:5432"
volumes:
# Persistent volume for Order Service database data
- order_db_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d orders"]
interval: 5s
timeout: 5s
retries: 5
# PostgreSQL Database for Customer Service
customer_db:
image: postgres:15-alpine
container_name: customer_db_container
restart: always
environment:
POSTGRES_DB: customers
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- "5434:5432"
volumes:
- customer_db_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d customers"]
interval: 5s
timeout: 5s
retries: 5
# Product Microservice (FastAPI)
product_service:
build:
context: ./backend/product_service
dockerfile: Dockerfile
image: week05_example01_product_service:latest
container_name: product_api_container
restart: always
ports:
- "8000:8000" # Map container port 8000 to host port 8000 (as per your request)
environment:
POSTGRES_HOST: product_db # Connects to the 'product_db' service within Docker network
AZURE_STORAGE_ACCOUNT_NAME: <your_storage_account_name> # Replace with your Azure Storage account name
AZURE_STORAGE_ACCOUNT_KEY: <your_storage_account_key> # Replace with your Azure Storage account key
AZURE_STORAGE_CONTAINER_NAME: <your_container_name> # Replace with your Azure Storage container name
AZURE_SAS_TOKEN_EXPIRY_HOURS: 24
RABBITMQ_HOST: rabbitmq # Internal Docker network hostname for RabbitMQ
RABBITMQ_PORT: 5672
RABBITMQ_USER: guest
RABBITMQ_PASS: guest
depends_on:
product_db:
condition: service_healthy
rabbitmq:
condition: service_healthy
volumes:
- ./backend/product_service/app:/app
command: uvicorn app.main:app --host 0.0.0.0 --port 8000
# Order Microservice (FastAPI)
order_service:
build:
context: ./backend/order_service
dockerfile: Dockerfile
image: week05_example01_order_service:latest
container_name: order_api_container
restart: always
ports:
- "8001:8000" # Map container port 8000 to host port 8001 (as per your request)
environment:
POSTGRES_HOST: order_db # Connects to the 'order_db' service within Docker network
CUSTOMER_SERVICE_URL: http://customer_service:8000 # Internal Docker network URL for Customer Service
RABBITMQ_HOST: rabbitmq # Internal Docker network hostname for RabbitMQ
RABBITMQ_PORT: 5672
RABBITMQ_USER: guest
RABBITMQ_PASS: guest
depends_on:
order_db:
condition: service_healthy
customer_service:
condition: service_started # Order Service needs Customer Service for sync validation
rabbitmq:
condition: service_healthy
volumes:
- ./backend/order_service/app:/app
command: uvicorn app.main:app --host 0.0.0.0 --port 8000 # Use --reload for dev
# Customer Microservice (FastAPI)
customer_service:
build:
context: ./backend/customer_service
dockerfile: Dockerfile
image: week05_example01_customer_service:latest
container_name: customer_api_container
restart: always
ports:
- "8002:8000" # Host:Container (Customer Service on 8002)
environment:
POSTGRES_HOST: customer_db # Connects to the 'customer_db' service within Docker network
POSTGRES_DB: customers
RABBITMQ_HOST: rabbitmq
RABBITMQ_PORT: 5672
RABBITMQ_USER: guest
RABBITMQ_PASS: guest
depends_on:
customer_db:
condition: service_healthy
rabbitmq:
condition: service_healthy
volumes:
- ./backend/customer_service/app:/app
command: uvicorn app.main:app --host 0.0.0.0 --port 8000
# Frontend Service (Simple HTML/JS served by Nginx)
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
image: week05_example01_frontend:latest
container_name: product_order_frontend
restart: always
ports:
- "3000:80" # Map container port 80 (Nginx default) to host port 3000
depends_on:
product_service:
condition: service_started
order_service:
condition: service_started
customer_service:
condition: service_started
volumes:
- ./frontend:/usr/share/nginx/html # Mount frontend files directly
# Named volumes for data persistence for each database
volumes:
product_db_data:
order_db_data:
customer_db_data: