forked from liquibase/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
85 lines (73 loc) · 3.01 KB
/
Copy pathdocker-entrypoint.sh
File metadata and controls
85 lines (73 loc) · 3.01 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
#!/bin/bash
#Debug Mode
[[ $DEBUG ]] && set -x
# Create database url frm environment variables
Database_url(){
#Detect mysql from service depend
if [ ! -n "${DEPEND_SERVICE}" ]; then
echo "===================================================================================="
echo 'There is no mysql server on my back, make sure you have define correct ${MYSQL_HOST}'
echo "===================================================================================="
else
while :
do
mysql_host=$(nslookup ${DEPEND_SERVICE%:*} | grep Address | sed '1d' | awk '{print $2}')
if [ -n "${mysql_host}" ];then
export MYSQL_HOST=$(echo $mysql_host)
break
fi
done
fi
sed -i -r -e "s#__CHANGELOG_PATH__#${CHANGELOG_PATH:-'changelog/changelog.mysql.sql'}#" \
-e "s#__MYSQL_HOST__#${MYSQL_HOST:-127.0.0.1}#" \
-e "s#__MYSQL_PORT__#${MYSQL_PORT:-3306}#" \
-e "s#__MYSQL_DATABASE__#${MYSQL_DATABASE:-Initialize}#" \
-e "s#__MYSQL_USER__#${MYSQL_USER:-admin}#" \
-e "s#__MYSQL_PASSWORD__#${MYSQL_PASSWORD}#" /liquibase/liquibase.properties
}
# Check whether Mysql is Online
Check_mysql(){
while :
do
echo "===================================================================================="
echo "Detecting whether Mysql is started···"
echo "===================================================================================="
Database_url
liquibase history
if [ $? == 0 ];then
echo "===================================================================================="
echo "Get ready to start the UPDATE process···"
echo "===================================================================================="
break
else
echo "===================================================================================="
echo "Mysql hasn't started yet! Redetect after 3 seconds"
echo "===================================================================================="
sleep 3
fi
done
}
# Update mysql schema
Schema_update(){
echo "===================================================================================="
echo "Start the UPDATE process,focus on log output!"
echo "===================================================================================="
liquibase update
if [ $? == 0 ];then
echo "===================================================================================="
echo "The update is successful,congratulations"
echo "===================================================================================="
else
echo "===================================================================================="
echo "The update is failed,focus on log output!"
echo "===================================================================================="
exit 1
fi
}
#========================== Main =============================
if [[ "$1" == "debug" ]];then
/bin/bash
else
Check_mysql
Schema_update
fi