forked from patternhelloworld/docker-blue-green-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollback.sh
71 lines (52 loc) · 2.61 KB
/
rollback.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
#!/bin/bash
set -eu
source use-common.sh
check_bash_version
check_gnu_grep_installed
check_gnu_sed_installed
check_yq_installed
check_git_docker_compose_commands_exist
sudo sed -i -e "s/\r$//g" $(basename $0)
echo "[NOTICE] To prevent CRLF errors in scripts based on the Windows operating system, currently performing CRLF to LF conversion."
sudo bash prevent-crlf.sh
git config apply.whitespace nowarn || echo "[WARN] A supporting command 'git config apply.whitespace nowarn' has NOT been run."
git config core.filemode false || echo "[WARN] A supporting command 'git config core.filemode false' has NOT been run."
source ./use-app.sh
check_git_docker_compose_commands_exist
cache_global_vars
with_edge_router_nginx="${1:-}"
if [[ "$with_edge_router_nginx" == "1" ]]; then
nginx_restart=true
else
nginx_restart=false
fi
# App rollback
echo "[NOTICE] Change the previous app image to the ${new_state} image for rollback."
docker tag ${project_name}:previous ${project_name}:${new_state} || echo "[NOTICE] ${project_name}:previous image does NOT exist."
sleep 2
echo "[NOTICE] Down & Up ${new_state} container."
docker-compose -f docker-compose-${project_name}.yml stop ${project_name}-${new_state} || echo "[NOTICE] The ${new_state} Container has been stopped, if exists."
docker-compose -f docker-compose-${project_name}.yml rm -f ${project_name}-${new_state} || echo "[NOTICE] The ${new_state} Container has been removed, if exists."
docker-compose -f docker-compose-${project_name}.yml up -d ${project_name}-${new_state}
echo "[NOTICE] Wait until the ${new_state} container is fully up."
if [[ $(check_availability_inside_container ${new_state} 60 5 | tail -n 1) != 'true' ]]; then
echo "[ERROR] Failed to rollback to the ${new_state} container." && exit 1
fi
# Rollback Process
if [[ ${nginx_restart} == 'true' ]]; then
echo "[NOTICE] Change the 'previous' tagged Nginx image to the 'latest' tagged image."
docker tag ${project_name}-nginx:previous ${project_name}-nginx:latest || echo "[NOTICE] ${project_name}-nginx:previous image does NOT exist."
sleep 2
echo "[NOTICE] Run 'emergency-nginx-restart.sh' "
bash emergency-nginx-restart.sh
else
echo "[NOTICE] Nginx will NOT be restarted, as ${nginx_restart} = false"
fi
./nginx-blue-green-activate.sh ${new_state} ${state} ${new_upstream} ${consul_key_value_store}
if [[ ${orchestration_type} != 'stack' ]]; then
echo "[NOTICE] Stop the previous ${state} container."
docker-compose -f docker-${orchestration_type}-${project_name}.yml stop ${project_name}-${state}
else
echo "[NOTICE] Remove the previous ${state} stack."
docker stack rm ${project_name}-${state}
fi