This repository has been archived by the owner on Nov 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
docker-compose-using-port-checking.yml
93 lines (86 loc) · 3.41 KB
/
docker-compose-using-port-checking.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
### Before running any Compose services, make sure you have an .env file
# inside your current folder and that it has been populated with the following content:
# mysql_root_password=<MYSQL_ROOT_PASSWORD>
#
# mysql_database_name=jdbcwithdocker
# mysql_database_user=<DB_USER_NAME>
# mysql_database_password=<DB_PASSWORD>
#
# check_db_connectivity_interval=2s
# check_db_connectivity_retries=20
#
# java_jvm_flags=-Xmx512m
#
# java_debug_port=9876
# java_debug_settings=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9876
### Start Docker containers with the following command executed inside a Powershell run as admin:
# mvn `
# ;docker-compose --file docker-compose-using-port-checking.yml down --rmi local `
# ;docker-compose --file docker-compose-using-port-checking.yml build `
# ;docker-compose --file docker-compose-using-port-checking.yml up --exit-code-from check_db_connectivity check_db_connectivity `
# ;if ($LASTEXITCODE -eq 0) { docker-compose --file docker-compose-using-port-checking.yml up app } `
# else { echo "ERROR: Failed to start service due to one of its dependencies!" }
version: '3.6'
services:
db:
image: mysql:5.7.20
environment:
MYSQL_ROOT_PASSWORD: ${mysql_root_password}
MYSQL_DATABASE: ${mysql_database_name}
MYSQL_USER: ${mysql_database_user}
MYSQL_PASSWORD: ${mysql_database_password}
stdin_open: true
tty: true
ports:
- 3306
volumes:
- jdbc-with-docker-mysql-data:/var/lib/mysql
check_db_connectivity:
image: activatedgeek/mysql-client:0.1
entrypoint: >
/bin/sh -c "
sleepingTime='${check_db_connectivity_interval}'
totalAttempts=${check_db_connectivity_retries}
currentAttempt=1
echo \"Start checking whether MySQL database \"${mysql_database_name}\" is up & running\" \
\"(able to process incoming connections) each $$sleepingTime for a total amount of $$totalAttempts times\"
while [ $$currentAttempt -le $$totalAttempts ]; do
sleep $$sleepingTime
mysql \
--host='db' \
--port='3306' \
--user='${mysql_database_user}' \
--password='${mysql_database_password}' \
--execute='USE ${mysql_database_name}'
if [ $$? -eq 0 ]; then
echo \"OK: [$$currentAttempt/$$totalAttempts] MySQL database \"${mysql_database_name}\" is up & running.\"
return 0
else
echo \"WARN: [$$currentAttempt/$$totalAttempts] MySQL database \"${mysql_database_name}\" is still NOT up & running ...\"
currentAttempt=`expr $$currentAttempt + 1`
fi
done;
echo 'ERROR: Could not connect to MySQL database \"${mysql_database_name}\" in due time.'
return 1"
depends_on:
- db
app:
image: satrapu/jdbc-with-docker-console-runner
build:
context: .
dockerfile: ./Dockerfile-jdbc-with-docker-console-runner
args:
JAVA_DEBUG_PORT: ${java_debug_port}
environment:
JDBC_URL: jdbc:mysql://address=(protocol=tcp)(host=db)(port=3306)/${mysql_database_name}?useSSL=false
JDBC_USER: ${mysql_database_user}
JDBC_PASSWORD: ${mysql_database_password}
JAVA_OPTIONS: ${java_jvm_flags} ${java_debug_settings}
stdin_open: true
tty: true
ports:
- ${java_debug_port}
depends_on:
- db
volumes:
jdbc-with-docker-mysql-data: