new sslproxy xai cli commands for build, deploy, rollback
This commit is contained in:
0
dockerfiles/services/sslproxy/cli/.bash_cli
Normal file
0
dockerfiles/services/sslproxy/cli/.bash_cli
Normal file
114
dockerfiles/services/sslproxy/cli/build
Executable file
114
dockerfiles/services/sslproxy/cli/build
Executable 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
|
||||
3
dockerfiles/services/sslproxy/cli/build.help
Normal file
3
dockerfiles/services/sslproxy/cli/build.help
Normal file
@@ -0,0 +1,3 @@
|
||||
ARGS - The arguments you wish to provide to this command
|
||||
|
||||
TODO: Fill out the help information for this command.
|
||||
1
dockerfiles/services/sslproxy/cli/build.usage
Normal file
1
dockerfiles/services/sslproxy/cli/build.usage
Normal file
@@ -0,0 +1 @@
|
||||
[-b] [-t] [-d] [-h]
|
||||
36
dockerfiles/services/sslproxy/cli/create-cert
Executable file
36
dockerfiles/services/sslproxy/cli/create-cert
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
echo -e "\033[36mCreate\033[39m: self-signed certificates"
|
||||
|
||||
CERTS_DIR=letsencrypt/live/xai-corp.net
|
||||
|
||||
function make_cert() {
|
||||
mkdir -p $CERTS_DIR
|
||||
|
||||
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -batch \
|
||||
-keyout $CERTS_DIR/privkey.pem \
|
||||
-out $CERTS_DIR/fullchain.pem \
|
||||
-config certs/localhost.conf
|
||||
|
||||
#tell chrome to trust the cert
|
||||
certutil -d sql:$HOME/.pki/nssdb -A -t "P,," -n "www.xai-corp.net" -i $CERTS_DIR/fullchain.pem
|
||||
}
|
||||
|
||||
function test_cert() {
|
||||
ls -l $CERTS_DIR | grep privkey.pem
|
||||
ls -l $CERTS_DIR | grep fullchain.pem
|
||||
}
|
||||
|
||||
function trap_exit() {
|
||||
code=$?
|
||||
if [ $code -gt 0 ]; then
|
||||
echo
|
||||
echo -e "\033[31mFailed to create certificates\033[39m"
|
||||
exit $code
|
||||
fi
|
||||
}
|
||||
trap trap_exit EXIT
|
||||
|
||||
# RUN
|
||||
make_cert && test_cert
|
||||
3
dockerfiles/services/sslproxy/cli/create-cert.help
Normal file
3
dockerfiles/services/sslproxy/cli/create-cert.help
Normal file
@@ -0,0 +1,3 @@
|
||||
ARGS - The arguments you wish to provide to this command
|
||||
|
||||
TODO: Fill out the help information for this command.
|
||||
1
dockerfiles/services/sslproxy/cli/create-cert.usage
Normal file
1
dockerfiles/services/sslproxy/cli/create-cert.usage
Normal file
@@ -0,0 +1 @@
|
||||
ARGS...
|
||||
89
dockerfiles/services/sslproxy/cli/deploy
Executable file
89
dockerfiles/services/sslproxy/cli/deploy
Executable file
@@ -0,0 +1,89 @@
|
||||
#!/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
|
||||
3
dockerfiles/services/sslproxy/cli/deploy.help
Normal file
3
dockerfiles/services/sslproxy/cli/deploy.help
Normal file
@@ -0,0 +1,3 @@
|
||||
ARGS - The arguments you wish to provide to this command
|
||||
|
||||
TODO: Fill out the help information for this command.
|
||||
1
dockerfiles/services/sslproxy/cli/deploy.usage
Normal file
1
dockerfiles/services/sslproxy/cli/deploy.usage
Normal file
@@ -0,0 +1 @@
|
||||
ARGS...
|
||||
75
dockerfiles/services/sslproxy/cli/rollback
Executable file
75
dockerfiles/services/sslproxy/cli/rollback
Executable file
@@ -0,0 +1,75 @@
|
||||
#!/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}
|
||||
APP_NAME=sslproxy_app
|
||||
|
||||
LOG=$(mktemp)
|
||||
|
||||
#export LOCAL_IMAGE
|
||||
export REMOTE_IMAGE
|
||||
#export TAG
|
||||
|
||||
export DOCKER_HOST=${DOCKER_HOST:-'dkhost:2376'}
|
||||
|
||||
###
|
||||
|
||||
function rollback() {
|
||||
docker service inspect ${APP_NAME}
|
||||
docker service update --rollback "${APP_NAME}"
|
||||
docker service scale "${APP_NAME}=2"
|
||||
}
|
||||
|
||||
function rollback_test() {
|
||||
docker ps | grep "${APP_NAME}"
|
||||
|
||||
curl -If https://git.xai-corp.net/
|
||||
}
|
||||
|
||||
function rollback_save() {
|
||||
echo TODO
|
||||
}
|
||||
|
||||
|
||||
function trap_exit() {
|
||||
code=$?
|
||||
docker service ls | grep ${APP_NAME}
|
||||
if [ $code -gt 0 ]; then
|
||||
echo
|
||||
rm "$LOG"
|
||||
echo -e "\033[31mFailed rolling back ${APP_NAME} \033[39m"
|
||||
exit $code
|
||||
fi
|
||||
|
||||
rm "$LOG"
|
||||
echo -e "\033[32mSuccess:\033[39m ${APP_NAME} successfully rolled back"
|
||||
}
|
||||
trap trap_exit EXIT
|
||||
|
||||
print_usage() {
|
||||
printf "Usage: %s: [-b] [-t] [-s] \n" "$0"
|
||||
echo -r rollback
|
||||
echo -t smoke tests
|
||||
echo -s tag as latest
|
||||
echo -h help
|
||||
exit 0
|
||||
}
|
||||
|
||||
######
|
||||
if [ -z "$1" ]; then
|
||||
rollback && rollback_test && rollback_save
|
||||
exit
|
||||
fi
|
||||
|
||||
while getopts tdhs name
|
||||
do
|
||||
case $name in
|
||||
d) rollback;;
|
||||
t) rollback_test;;
|
||||
s) rollback_save;;
|
||||
*) print_usage;;
|
||||
esac
|
||||
done
|
||||
3
dockerfiles/services/sslproxy/cli/rollback.help
Normal file
3
dockerfiles/services/sslproxy/cli/rollback.help
Normal file
@@ -0,0 +1,3 @@
|
||||
ARGS - The arguments you wish to provide to this command
|
||||
|
||||
TODO: Fill out the help information for this command.
|
||||
1
dockerfiles/services/sslproxy/cli/rollback.usage
Normal file
1
dockerfiles/services/sslproxy/cli/rollback.usage
Normal file
@@ -0,0 +1 @@
|
||||
ARGS...
|
||||
Reference in New Issue
Block a user