66: " ${taito_namespace:? } "
77: " ${taito_target_env:? } "
88: " ${taito_branch:? } "
9+ : " ${taito_container_registry:? } "
10+ : " ${taito_project:? } "
11+ : " ${taito_basic_auth_enabled:? } "
912
1013set -e
1114
1215image_tag=$1
1316if [[ ! $image_tag ]]; then
17+ echo " [Getting commit sha of the latest commit on branch ${taito_branch} ]"
1418 image_tag=$( git rev-parse " ${taito_branch} " )
19+ echo " Commit SHA: ${image_tag} "
20+ echo
1521fi
1622
1723# Add untested prefix
18- if [[ " ${ci_exec_build:- } " == " true" ]]; then
24+ if [[ " ${ci_exec_build:- } " == " true" ]] && [[ ${image_tag} != * " -untested " ]] ; then
1925 image_tag=" ${image_tag} -untested"
2026fi
2127
2228echo " [Starting deployment of image $image_tag ]"
23- echo
2429echo " NOTE: Deployment is done using the taito-config.sh and"
2530echo " docker-compose-remote.yaml currently located on your local directory."
2631echo
@@ -38,39 +43,60 @@ echo "[Copy docker-compose-remote.yaml to ${taito_host}:/tmp]"
3843)
3944echo
4045
41- echo " [Execute on ${taito_host} ]"
46+ echo " [Execute on host ${taito_host} ]"
4247ssh ${opts} " ${taito_ssh_user} @${taito_host} " "
4348 sudo bash -c '
4449 set -e
4550 ${taito_setv:? }
4651 cd ${taito_host_dir}
4752 echo
48- echo [Extract /tmp/${taito_namespace} .tar]
53+ echo [Check that Docker images exist]
54+ if ! sudo docker images | grep ${taito_container_registry} | grep ${image_tag} &> /dev/null; then
55+ echo Latest images on remote host:
56+ sudo docker images | grep ${taito_container_registry}
57+ echo
58+ echo ERROR: No image with tag ${image_tag}
59+ exit 1
60+ fi
61+ echo
62+ echo [Extract configuration files from /tmp/${taito_namespace} .tar]
4963 tar -xf /tmp/${taito_namespace} .tar -C .
5064 rm -f /tmp/${taito_namespace} .tar
51- mv -f docker-compose-remote.yaml docker-compose.yaml
5265 echo
53- echo [Replace port and image tag in docker-compose.yaml]
66+ echo [Replace port and image tag in docker-compose-remote .yaml]
5467 PORT=\$ (getsiteport ${taito_namespace} )
55- sed -i s/__PORT__ /\$ {PORT}/ docker-compose.yaml
56- sed -i s/__IMAGE_TAG__ /${image_tag} / docker-compose.yaml
68+ sed -i \" s/_PORT_ /\$ {PORT}/g \" docker-compose-remote .yaml
69+ sed -i \" s/_IMAGE_TAG_ /${image_tag} /g \" docker-compose-remote .yaml
5770 echo
71+ if [[ ${taito_basic_auth_enabled} != false ]]; then
72+ echo [Enable basic auth]
73+ sed -i \" s/# auth_basic/auth_basic/\" docker-nginx.conf
74+ if ! grep \" ^[[:space:]]*auth_basic\" docker-nginx.conf &> /dev/null; then
75+ echo ERROR: Basic auth not enabled
76+ exit 1
77+ fi
78+ echo
79+ fi
5880 echo [Modify taito-config.sh]
59- sed -i \" 1 ataito_target_env=${taito_target_env} \" taito-config.sh
60- sed -i \" 1 aset -a\" taito-config.sh
61- echo set +a >> taito-config.sh
81+ sed -i \" 3 ataito_target_env=${taito_target_env} \" taito-config.sh
6282 sed -i /taito_util_path/d taito-config.sh
6383 echo
64- echo [Set environment variables]
65- . taito-config.sh
66- echo
67- echo [Pull new container images]
84+ echo [Pull container images using the new configuration]
6885 echo NOTE: Pulling of local-only images will print an error! This is OK.
69- (docker-compose pull || :)
86+ (. taito-config.sh && docker-compose -f docker-compose-remote.yaml pull || :)
7087 echo
71- echo [Restart docker-compose]
72- docker-compose stop
88+ echo [Stop docker-compose using the old configuration]
89+ (. taito-config.sh && docker-compose stop)
90+ echo
91+ echo [Start docker-compose using the new configuration]
92+ . taito-config.sh
93+ mv -f docker-compose-remote.yaml docker-compose.yaml
7394 docker-compose up -d
7495 '
75- "
96+ " || (
97+ echo " Recent commits in ${taito_target_env} branch:"
98+ git log -10 --pretty=oneline " ${taito_target_env} "
99+ exit 1
100+ )
101+
76102echo
0 commit comments