@@ -66,11 +66,18 @@ if ! echo "$current_context" | grep -P '.*-admin@.*-mgt-cluster'; then
6666fi
6767
6868branch=$( git branch --show-current)
69+
70+ # No branch name was found. Try to get a git-tag.
6971if [ " $branch " == " " ]; then
70- echo " failed to get branch name"
72+ branch=$( git describe --tags --exact-match 2> /dev/null || echo " " )
73+ fi
74+
75+ if [ " $branch " == " " ]; then
76+ echo " failed to find git branch/tag name"
7177 exit 1
7278fi
7379
80+ # Build tag for container image.
7481tag=" dev-$USER -$branch "
7582tag=" $( echo -n " $tag " | tr -c ' a-zA-Z0-9_.-' ' -' ) "
7683
@@ -81,27 +88,43 @@ image="$image_path/caph-staging:$tag"
8188 make generate-manifests
8289 kustomize build config/crd | kubectl apply -f -
8390} &
91+ pid_generate=$!
8492
85- # run in background2
93+ # run in background
8694{
8795 docker build -f images/caph/Dockerfile -t " $image " .
8896 docker push " $image "
8997} &
98+ pid_docker_push=$!
9099
91- wait
100+ # wait for both processes and check their exit codes
101+ if ! wait $pid_generate ; then
102+ echo " Error: generate-manifests/kustomize failed"
103+ exit 1
104+ fi
105+
106+ if ! wait $pid_docker_push ; then
107+ echo " Error: docker build/push failed"
108+ exit 1
109+ fi
92110
111+ # Find namespace of caph deployment.
93112ns=$( kubectl get deployments.apps -A | { grep caph-controller || true ; } | cut -d' ' -f1)
94113if [[ -z $ns ]]; then
95114 echo " failed to get namespace for caph-controller"
96115 exit 1
97116fi
98117
118+ # Scale deployment to 1.
99119kubectl scale --replicas=1 -n " $ns " deployment/caph-controller-manager
100120
101121kubectl set image -n " $ns " deployment/caph-controller-manager manager=" $image "
102122
123+ # Set imagePullPolicy to "Always", so that a new image (with same name/tag) gets pulled.
103124kubectl patch deployment -n " $ns " -p ' [{"op": "replace", "path": "/spec/template/spec/containers/0/imagePullPolicy", "value": "Always"}]' --type=' json' caph-controller-manager
104125
126+ # If you update the image again, there might be no change the deployment spec.
127+ # Force a rollout:
105128kubectl rollout restart -n " $ns " deployment caph-controller-manager
106129
107130trap " echo 'Interrupted! Exiting...'; exit 1" SIGINT
0 commit comments