Skip to content
Snippets Groups Projects

Resolve "add `undeploy` command"

Merged Ulf Seltmann requested to merge 1-add-undeploy-command into master
Compare and
14 files
+ 346
52
Preferences
Compare changes
Files
14
+ 46
49
@@ -3,7 +3,6 @@
@@ -3,7 +3,6 @@
set -o pipefail -o noclobber -o nounset
set -o pipefail -o noclobber -o nounset
## declare used variables
## declare used variables
cmd=""
image_name="image"
image_name="image"
cluster_name="cluster"
cluster_name="cluster"
context="context"
context="context"
@@ -29,7 +28,7 @@ if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
@@ -29,7 +28,7 @@ if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
exit 1
exit 1
fi
fi
OPTIONS=d:,t:,b:,c:,n:,s:
OPTIONS=
LONGOPTS=docker-config:,tag:,build-arg:,set:,set-string:,charts:,name:,token:,certificate-authority:,namespace:,cluster-url:,service-account:,output:,input:
LONGOPTS=docker-config:,tag:,build-arg:,set:,set-string:,charts:,name:,token:,certificate-authority:,namespace:,cluster-url:,service-account:,output:,input:
# -use ! and PIPESTATUS to get exit code with errexit set
# -use ! and PIPESTATUS to get exit code with errexit set
@@ -218,8 +217,8 @@ prepare_helm() {
@@ -218,8 +217,8 @@ prepare_helm() {
return 0
return 0
}
}
prepare_helm_command() {
helm_deploy() {
echo -ne "Preparing helm command..."
echo -ne "Deploying ${name}..."
if [ "${name}" == "" ];then
if [ "${name}" == "" ];then
echo "failed"
echo "failed"
@@ -233,7 +232,19 @@ prepare_helm_command() {
@@ -233,7 +232,19 @@ prepare_helm_command() {
return 1
return 1
fi
fi
cmd="helm upgrade --install --wait --tiller-namespace=${namespace} --namespace=${namespace}"
local out
 
local cmd
 
 
if [ "$(helm ls --tiller-namespace=${namespace} --namespace=${namespace} --pending --deleted --failed --short | grep ${name})" != "" ];then
 
out=`helm delete --tiller-namespace=${namespace} --purge ${name} 2>&1`
 
if [ "$?" != "0" ];then
 
echo "failed"
 
echo "$out"
 
return 1
 
fi
 
fi
 
 
cmd="helm upgrade --install --wait --timeout=60 --tiller-namespace=${namespace} --namespace=${namespace}"
for set in ${sets};do
for set in ${sets};do
cmd="$cmd --set ${set}"
cmd="$cmd --set ${set}"
@@ -245,24 +256,6 @@ prepare_helm_command() {
@@ -245,24 +256,6 @@ prepare_helm_command() {
cmd="$cmd ${name} ${charts}"
cmd="$cmd ${name} ${charts}"
echo "done"
return 0
}
helm_deploy() {
echo -ne "Deploying ${name}..."
local out=""
# todo: do we need this when we do a "helm upgrade --install" ?
# if [ "$(helm ls --tiller-namespace=${namespace} --namespace=${namespace} --deleted --failed --short | grep ${name})" != "" ];then
# out=`helm delete --tiller-namespace=${namespace} --purge ${name} 2>&1`
# if [ "$?" != "0" ];then
# echo "failed"
# echo "$out"
# return 1
# fi
# fi
out=`$cmd 2>&1`
out=`$cmd 2>&1`
if [ "$?" != "0" ];then
if [ "$?" != "0" ];then
echo "failed"
echo "failed"
@@ -273,23 +266,26 @@ helm_deploy() {
@@ -273,23 +266,26 @@ helm_deploy() {
echo "done"
echo "done"
}
}
test_helm_deploy() {
helm_undeploy() {
echo -ne "Waiting for successful deploy..."
echo -ne "Undeploying ${name}..."
counter=0
if [ "${name}" == "" ];then
while [ "$(helm ls --tiller-namespace=${namespace} --namespace=${namespace} | grep ${name} | awk -F"\t" '{ print $4; }')" != "DEPLOYED" ]; do
echo "failed"
sleep 1
echo "no deploy name specified"
if [ $counter -eq 60 ];then
return 1
break
fi
fi
counter=$[$counter+1]
local out
done
if [ $counter -eq 60 ];then
out=`helm delete --tiller-namespace=${namespace} ${name} 2>&1`
 
 
if [ "$?" != "0" ];then
echo "failed"
echo "failed"
 
echo "$out"
return 1
return 1
fi
fi
 
echo "done"
echo "done"
return 0
}
}
prepare_image_publisher() {
prepare_image_publisher() {
@@ -309,17 +305,6 @@ prepare_image_publisher() {
@@ -309,17 +305,6 @@ prepare_image_publisher() {
return 0
return 0
}
}
prepare_image_builder() {
cmd="docker build --pull"
for arg in $buildargs;do
echo "adding $arg to build command"
cmd="$cmd --build-arg $arg --build-arg ${arg,,}"
done
cmd="$cmd -t ${image_name} ."
return 0
}
save_image() {
save_image() {
local out
local out
echo -ne "saving image ..."
echo -ne "saving image ..."
@@ -341,8 +326,17 @@ save_image() {
@@ -341,8 +326,17 @@ save_image() {
}
}
build_image() {
build_image() {
local out
echo -ne "building image..."
echo -ne "building image..."
 
 
local out
 
local cmd="docker build --pull"
 
 
for arg in $buildargs;do
 
echo "adding $arg to build command"
 
cmd="$cmd --build-arg $arg --build-arg ${arg,,}"
 
done
 
 
cmd="$cmd -t ${image_name} ."
out=`$cmd 2>&1`
out=`$cmd 2>&1`
if [ "$?" != "0" ];then
if [ "$?" != "0" ];then
echo "failed"
echo "failed"
@@ -424,13 +418,16 @@ fi
@@ -424,13 +418,16 @@ fi
case $1 in
case $1 in
build)
build)
prepare_image_builder && build_image && save_image
build_image && save_image
;;
;;
publish)
publish)
prepare_image_publisher && import_image && publish_image
prepare_image_publisher && import_image && publish_image
;;
;;
deploy)
deploy)
prepare_kubectl && prepare_helm && prepare_helm_command && helm_deploy && test_helm_deploy
prepare_kubectl && prepare_helm && helm_deploy
 
;;
 
undeploy)
 
prepare_kubectl && prepare_helm && helm_undeploy
;;
;;
help)
help)
echo "help"
echo "help"