90 lines
1.6 KiB
Bash
Executable File
90 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -e
|
|
set -x
|
|
|
|
LOCAL_IMAGE=sslproxy
|
|
#TAG=2.2.${BUILD_NUMBER:-dev}
|
|
TAG=2.1
|
|
REMOTE_IMAGE=dkregistry.xai-corp.net:5000/${LOCAL_IMAGE}:${TAG}
|
|
APP_NAME=sslproxy_app
|
|
|
|
LOG=$(mktemp)
|
|
|
|
export LOCAL_IMAGE
|
|
export REMOTE_IMAGE
|
|
export TAG
|
|
|
|
export DOCKER_HOST=${DOCKER_HOST:-'dkhost:2376'}
|
|
|
|
###
|
|
function deploy() {
|
|
docker stack deploy \
|
|
--with-registry-auth \
|
|
--prune \
|
|
-c docker-compose.prod.yml \
|
|
sslproxy
|
|
|
|
(cd ../ && chmod +x ./scaleout.sh && ./scaleout.sh sslproxy_app 30)
|
|
}
|
|
|
|
function deploy_test() {
|
|
docker ps | grep sslproxy_app
|
|
|
|
curl -If https://git.xai-corp.net/
|
|
# curl -If -H "Host: not.xai-corp.net" https://dkhost
|
|
}
|
|
|
|
function deploy_save() {
|
|
#tag as latest
|
|
docker tag "$REMOTE_IMAGE" latest
|
|
docker push latest
|
|
}
|
|
|
|
dc() {
|
|
# shellcheck disable=SC2068
|
|
docker-compose \
|
|
-f docker-compose.yml \
|
|
-f docker-compose.prod.yml \
|
|
$@
|
|
}
|
|
|
|
function trap_exit() {
|
|
code=$?
|
|
docker service ls | grep "${APP_NAME}"
|
|
if [ $code -gt 0 ]; then
|
|
echo
|
|
rm "$LOG"
|
|
echo -e "\033[31mFailed to deploy ${REMOTE_IMAGE} \033[39m"
|
|
exit $code
|
|
fi
|
|
|
|
rm "$LOG"
|
|
echo -e "\033[32mSuccess:\033[39m ${REMOTE_IMAGE} successfully deployed"
|
|
}
|
|
trap trap_exit EXIT
|
|
|
|
print_usage() {
|
|
printf "Usage: %s: [-b] [-t] [-s] \n" "$0"
|
|
echo -d deploy
|
|
echo -t smoke tests
|
|
echo -s tag as latest
|
|
echo -h help
|
|
exit 0
|
|
}
|
|
|
|
######
|
|
if [ -z "$1" ]; then
|
|
deploy && deploy_test && deploy_save
|
|
exit
|
|
fi
|
|
|
|
while getopts tdhs name
|
|
do
|
|
case $name in
|
|
d) deploy;;
|
|
t) deploy_test;;
|
|
s) deploy_save;;
|
|
*) print_usage;;
|
|
esac
|
|
done
|