-
Notifications
You must be signed in to change notification settings - Fork 0
/
pytest_docker-compose.yaml
236 lines (226 loc) · 6.55 KB
/
pytest_docker-compose.yaml
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
#######################################################################################
#
# Description:
# Build and run testing with Python testing framework *pytest*
#
# Environment variables:
# * TESTING_TYPE: Which testing you want to get and run.
# - Allowable values: 'unit-test', 'integration-test'
#
# Example running docker command line:
# >>> # Activate and run the docker compose.
# >>> docker-compose -f ./docker-compose_pytest.yaml up --build
#
# >>> # Shutdown the docker compose.
# >>> docker-compose -f ./docker-compose_pytest.yaml down
#
# Warning:
# Please be careful about the resource configuration (the settings in *deploy.resource*).
# The container with not enough resource may crash lead to it got fail while activating
# entire docker-compose project. For example, I had faced an issue about other 2 or 3
# containers setup successfully temporary, and some of them dead. However, because it
# was successfully activate the service in containers so that the health checking mechanism
# determines the container was health, and docker-compose would go ahead to activate
# rest of containers. But the rest of containers depends on the service health of other
# containers. So unfortunately, it would occur failure and print the error log message
# like below:
#
# ERROR: compose.cli.main.main: Encountered errors while bringing up the project.
#
# But the truly root cause is the resource of other containers is NOT enough. Therefore,
# please be careful of the resource setting in each container.
#
#######################################################################################
version: "3.8"
services:
pytest_linux:
container_name: sc-appintegration_pytest
environment:
# - TESTING_TYPE=unit-test
- TESTING_TYPE=integration-test
- PYTEST_TARGET_URL_DOMAIN=http://10.20.23.3:12345
- PYTEST_KAFKA_IP=10.20.23.11
- PYTEST_RABBITMQ_HOST=10.20.23.12:5672
# - PYTEST_RABBITMQ_VIRTUAL_HOST=/
# - PYTEST_RABBITMQ_USERNAME=user
# - PYTEST_RABBITMQ_PASSWORD=password
- PYTEST_ACTIVEMQ_HOST=10.20.23.13:61613
build:
context: .
dockerfile: pytest_Dockerfile
depends_on:
pytest_http_server:
condition: service_healthy
pytest_mq_kafka:
condition: service_healthy
pytest_mq_rabbitmq:
condition: service_healthy
pytest_mq_activemq:
condition: service_healthy
networks:
sc-appintegraton_pytest_network:
ipv4_address: 10.20.23.2
deploy:
resources:
limits:
cpus: '0.75'
memory: 256M
reservations:
cpus: '0.5'
memory: 128M
restart_policy:
condition: on-failure
max_attempts: 2
pytest_http_server:
container_name: sc-appintegration_pytest-http_server
build:
context: .
dockerfile: pytest_http_server_Dockerfile
networks:
sc-appintegraton_pytest_network:
ipv4_address: 10.20.23.3
ports:
- "12345:12345"
healthcheck:
test: ["CMD", "nc", "-zv", "10.20.23.3", "12345"]
interval: 30s
timeout: 10s
retries: 3
deploy:
resources:
limits:
cpus: '0.5'
memory: 128M
reservations:
cpus: '0.25'
memory: 64M
restart_policy:
condition: on-failure
max_attempts: 2
pytest_zookeeper:
container_name: sc-appintegration_pytest-zookeeper
image: zookeeper:latest
restart: always
networks:
sc-appintegraton_pytest_network:
ipv4_address: 10.20.23.10
ports:
- "2181:2181"
- "2888:2888"
- "3888:3888"
- "7010:7010"
healthcheck:
test: ["CMD", "/apache-zookeeper-3.8.0-bin/bin/zkServer.sh", "status"]
interval: 30s
timeout: 10s
retries: 3
deploy:
resources:
limits:
cpus: '0.75'
memory: 256M
reservations:
cpus: '0.5'
memory: 128M
restart_policy:
condition: on-failure
max_attempts: 2
pytest_mq_kafka:
container_name: sc-appintegration_pytest-kafka
image: wurstmeister/kafka:2.13-2.7.0
restart: always
environment:
- KAFKA_BROKER_ID=0
- KAFKA_ZOOKEEPER_CONNECT=10.20.23.10:2181
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://10.20.23.11:9092
- KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092
depends_on:
pytest_zookeeper:
condition: service_healthy
networks:
sc-appintegraton_pytest_network:
ipv4_address: 10.20.23.11
ports:
- "9092:9092"
healthcheck:
test: ["CMD", "/opt/kafka_2.13-2.7.0/bin/kafka-broker-api-versions.sh", "--bootstrap-server", "127.0.0.1:9092", "--version"]
interval: 10s
timeout: 5s
retries: 5
deploy:
resources:
limits:
cpus: '1'
memory: 512M
reservations:
cpus: '0.75'
memory: 256M
restart_policy:
condition: on-failure
max_attempts: 2
pytest_mq_rabbitmq:
container_name: sc-appintegration_pytest-rabbitmq
image: rabbitmq:3.9.20
hostname: pytest-rabbit
environment:
- RABBITMQ_DEFAULT_USER=user
- RABBITMQ_DEFAULT_PASS=password
networks:
sc-appintegraton_pytest_network:
ipv4_address: 10.20.23.12
ports:
- "5671:5671"
- "5672:5672"
- "15672:15672"
healthcheck:
test: ["CMD", "rabbitmqctl", "status"]
interval: 30s
timeout: 10s
retries: 3
deploy:
resources:
limits:
cpus: '1'
memory: 512M
reservations:
cpus: '0.75'
memory: 256M
restart_policy:
condition: on-failure
max_attempts: 2
pytest_mq_activemq:
container_name: sc-appintegration_pytest-activemq
image: rmohr/activemq:5.15.9
networks:
sc-appintegraton_pytest_network:
ipv4_address: 10.20.23.13
ports:
- "61613:61613"
- "8161:8161"
healthcheck:
test: ["CMD", "/opt/apache-activemq-5.15.9/bin/activemq", "list"]
interval: 30s
timeout: 10s
retries: 3
deploy:
resources:
limits:
cpus: '1'
memory: 512M
reservations:
cpus: '0.75'
memory: 256M
restart_policy:
condition: on-failure
max_attempts: 2
networks:
sc-appintegraton_pytest_network:
# # It would test web spider features so that it needs to connect to internet.
driver: ipvlan
ipam:
driver: default
config:
- subnet: 10.20.23.0/24
gateway: 10.20.23.1
options:
parent: en0