new sslproxy xai cli commands for build, deploy, rollback

This commit is contained in:
2020-05-30 09:43:40 -04:00
parent 10b5a1e012
commit 73ad921e3b
27 changed files with 482 additions and 34 deletions

View File

@@ -0,0 +1,114 @@
#!/usr/bin/env bash
set -e
#set -x
LOCAL_IMAGE=sslproxy
TAG=2.2.${BUILD_NUMBER:-dev}
REMOTE_IMAGE=dkregistry.xai-corp.net:5000/${LOCAL_IMAGE}:${TAG}
LOG=$(mktemp)
export LOCAL_IMAGE
export REMOTE_IMAGE
export TAG
dc() {
# shellcheck disable=SC2068
docker-compose \
-f docker-compose.yml \
-f docker-compose.build.yml \
$@
}
###
build() {
dc build
}
build_test() {
echo -e "\e[33mtesting the image\e[39m"
dc up -d
docker ps | grep sslproxy
sleep 2
assertBadGateway https abcapi.xai-corp.net
assertBadGateway https dkui.xai-corp.net
assertBadGateway https git.xai-corp.net
assertBadGateway https jenkins.xai-corp.net
assertBadGateway https xaibox.xai-corp.net
assertBadGateway https metrics.xai-corp.net
assertMisdirectedRequest https not.xai-corp.net
assertBadGateway http xai-corp.net
assertBadGateway http abcapi.xai-corp.net
assertBadGateway http dkui.xai-corp.net
assertBadGateway http git.xai-corp.net
assertBadGateway http jenkins.xai-corp.net
assertBadGateway http xaibox.xai-corp.net
assertBadGateway http metrics.xai-corp.net
}
function assertMisdirectedRequest() {
proto=$1
domain=$2
set -e
echo -e "\033[94m${proto}://${domain}\033[39m testing for mistrected request"
curl --no-progress-meter -skH "Host: ${domain}" "${proto}://localhost" | tee "$LOG" | grep "421 Misdirected Request"
}
function assertBadGateway() {
proto=$1
domain=$2
set -e
echo -e "\033[94m${proto}://${domain}\033[39m"
curl --no-progress-meter -skH "Host: ${domain}" "${proto}://localhost" | tee "$LOG" | grep "502 Bad Gateway"
}
build_save() {
echo push to registry
docker tag $LOCAL_IMAGE $REMOTE_IMAGE
docker push $REMOTE_IMAGE
}
function trap_exit() {
code=$?
dc down
if [ $code -gt 0 ]; then
echo
cat "$LOG"
rm "$LOG"
dc logs --tail=10
echo -e "\033[31mFailed to build functional image\033[39m"
exit $code
fi
rm "$LOG"
echo -e "\033[32mSuccess:\033[39m ${LOCAL_IMAGE}:${TAG} successfully built"
}
trap trap_exit EXIT
print_usage() {
printf "Usage: %s: [-b] [-t] [-s] \n" "$0"
echo -b build
echo -t test
echo -s push to registry
echo -h help
exit 0
}
######
if [ -z "$1" ]; then
build && build_test && build_save
exit
fi
while getopts btdhs name
do
case $name in
b) build;;
t) build_test;;
s) build_save;;
*) print_usage;;
esac
done