-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker-auto.sh
executable file
·205 lines (182 loc) · 6.04 KB
/
docker-auto.sh
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
#!/usr/bin/env bash
set -e
SCRIPT_BASE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
cd "$SCRIPT_BASE_PATH"
###############################################
# Extract Environment Variables from .env file
# Ex. REGISTRY_URL="$(getenv REGISTRY_URL)"
###############################################
getenv(){
local _env="$(printenv $1)"
echo "${_env:-$(cat .env | awk 'BEGIN { FS="="; } /^'$1'/ {sub(/\r/,"",$2); print $2;}')}"
}
DOCKER_COMPOSE_VERSION="1.29.2"
CONF_ARG="-f docker-compose-prod-full.yml"
PATH=$PATH:/usr/local/bin/
PROJECT_NAME="$(getenv PROJECT_NAME)"
REGISTRY_URL="$(getenv REGISTRY_URL)"
########################################
# Install docker-compose
# DOCKER_COMPOSE_VERSION need to be set
########################################
# install_docker_compose() {
# sudo curl -L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" \
# -o /usr/local/bin/docker-compose
# sudo chmod +x /usr/local/bin/docker-compose
# return 0
# }
# if ! command -v docker-compose >/dev/null 2>&1; then
# install_docker_compose
# elif [[ "$(docker-compose version --short)" != "$DOCKER_COMPOSE_VERSION" ]]; then
# install_docker_compose
# fi
usage() {
echo "Usage: $(basename "$0") [MODE] [OPTIONS] [COMMAND]"
echo
echo "Mode:"
echo " --prod Production mode with all services running"
echo " --prod-was Production mode with only was (tomcat) running"
echo " --dev Development mode with all services running"
echo " --dev-was Development mode with only was (tomcat) running"
echo " --with-hub Production mode - have to run under the hub web server"
echo " --dev-with-hub Development mode - have to run under the hub web server"
echo
echo "Options:"
echo " --jmx Add JMX support"
echo " --jpda Add JPDA remote debugging"
echo " --certgen Run the certbot instance for generating SSL certificate"
echo " --rabbitmq Add RabbitMQ Server"
echo " --noimage Use a war file located in 'was' folder, use the ant task 'docker-build' to create the war file"
echo " --help Show this help message"
echo " --ssl Enable SSL connection, set HTTPS_PORT and certificate correctly"
echo " --hoops Load Hoops BIM Viewer, path: /hoops"
echo " --livechat Load Live chat module, path: /livechat"
echo
echo "Commands:"
echo " up Start the services"
echo " down Stop the services"
echo " ps Show the status of the services"
echo " logs Follow the logs on console"
echo " login Log in to a Docker registry"
echo " force-remove Service is stopped and removed with force!"
echo " remove-all Remove all containers"
echo " stop-all Stop all containers running"
echo " build Build the image"
echo " publish Publish the image to the registry"
echo " arthas Start arthas diagnostic tool"
}
if [ $# -eq 0 ]; then
usage
exit 1
fi
for i in "$@"
do
case $i in
--prod)
CONF_ARG="-f docker-compose-prod-full.yml -f docker-compose-rabbitmq.yml"
shift
;;
--prod-was)
CONF_ARG="-f docker-compose-prod-was.yml"
shift
;;
--with-hub)
CONF_ARG="-f docker-compose-prod-with-hub.yml -f docker-compose-rabbitmq.yml"
shift
;;
--dev)
CONF_ARG="-f docker-compose-dev-full.yml"
shift
;;
--dev-was)
CONF_ARG="-f docker-compose-dev-was.yml"
shift
;;
--dev-with-hub)
CONF_ARG="-f docker-compose-dev-with-hub.yml"
shift
;;
--jmx)
CONF_ARG="$CONF_ARG -f docker-compose-jmx.yml"
shift
;;
--certgen)
CONF_ARG="$CONF_ARG -f docker-compose-certgen.yml"
shift
;;
--rabbitmq)
CONF_ARG="$CONF_ARG -f docker-compose-rabbitmq.yml"
shift
;;
--jpda)
CONF_ARG="$CONF_ARG -f docker-compose-jpda.yml"
shift
;;
--noimage)
CONF_ARG="$CONF_ARG -f docker-compose-prod-noimage.yml"
shift
;;
--ssl)
CONF_ARG="$CONF_ARG -f docker-compose-ssl.yml"
shift
;;
--hoops)
CONF_ARG="$CONF_ARG -f docker-compose-hoops.yml"
shift
;;
--livechat)
CONF_ARG="$CONF_ARG -f docker-compose-livechat.yml"s
shift
;;
--help|-h)
usage
exit 1
;;
*)
CONF_ARG="$CONF_ARG -f docker-compose-rabbitmq.yml"
;;
esac
done
echo "Arguments: $CONF_ARG"
echo "Command: $@"
if [ "$1" == "login" ]; then
docker login $REGISTRY_URL
exit 0
elif [ "$1" == "up" ]; then
docker compose $CONF_ARG pull
docker compose $CONF_ARG build --pull
docker compose $CONF_ARG up -d --remove-orphans
exit 0
elif [ "$1" == "force-remove" ]; then
shift
docker compose $CONF_ARG rm --stop --force "$@"
exit 0
elif [ "$1" == "stop-all" ]; then
if [ -n "$(docker ps --format {{.ID}})" ]
then docker stop $(docker ps --format {{.ID}}); fi
exit 0
elif [ "$1" == "remove-all" ]; then
if [ -n "$(docker ps -a --format {{.ID}})" ]
then docker rm $(docker ps -a --format {{.ID}}); fi
exit 0
elif [ "$1" == "logs" ]; then
shift
docker compose $CONF_ARG logs -f --tail 200 "$@"
exit 0
elif [ "$1" == "build" ]; then
if [ -z "$REGISTRY_URL" ]; then echo "REGISTRY_URL not defined."; exit 1; fi
if [ -z "$PROJECT_NAME" ]; then echo "PROJECT_NAME not defined."; exit 1; fi
docker build -t $REGISTRY_URL/$PROJECT_NAME was
exit 0
elif [ "$1" == "publish" ]; then
if [ -z "$REGISTRY_URL" ]; then echo "REGISTRY_URL not defined."; exit 1; fi
if [ -z "$PROJECT_NAME" ]; then echo "PROJECT_NAME not defined."; exit 1; fi
docker login $REGISTRY_URL
docker push $REGISTRY_URL/$PROJECT_NAME
exit 0
elif [ "$1" == "arthas" ]; then
shift
docker compose $CONF_ARG exec was /bin/bash -c "wget https://alibaba.github.io/arthas/arthas-boot.jar && java -jar arthas-boot.jar $@"
exit 0
fi
docker compose $CONF_ARG "$@"