-
Notifications
You must be signed in to change notification settings - Fork 0
/
script-update.sh
79 lines (67 loc) · 2.29 KB
/
script-update.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
# causes the shell to exit if any invoked command exits with a non-zero status
set -e
set -o pipefail # Fail the script if any command in a pipeline fails
# Configuration variables with default values
docker_username="${DOCKER_USERNAME:-nimbleopti}"
image_tag="${IMAGE_TAG:-v1.0.0}"
docker_image_name="${DOCKER_IMAGE_NAME:-${docker_username}/nimble-opti-adapter}"
build_platform="${BUILD_PLATFORM:-all}" # local or all
testCode="${TEST_CODE:-true}" # true or false
# Parse command line options
while getopts ":e:" opt; do
case $opt in
e)
export $OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
# Run Go tests
if [ "$testCode" = "true" ]; then
echo "Running Go tests..."
go test ./... || {
echo "Go tests failed"
exit 1
}
fi
echo "Making manifests..."
make manifests
echo "Installing..."
make install
# Docker operations
case "$build_platform" in
"local")
docker build -t "$docker_image_name:latest" -f Dockerfile .
docker push "$docker_image_name"
;;
"all")
docker_target_platform="linux/arm64,linux/amd64"
docker buildx build . \
--platform "$docker_target_platform" \
--tag $docker_image_name:$image_tag --tag $docker_image_name:latest \
--file Dockerfile \
--output type=image,push=true
;;
*)
echo "Invalid BUILD_PLATFORM value. Choose either 'all' or 'local'." >&2
exit 1
;;
esac
echo "Deploying..."
make deploy IMG=$docker_image_name:latest
echo "Rolling out updates..."
kubectl rollout restart deployment/nimble-opti-adapter-controller-manager -n nimble-opti-adapter-system
kubectl rollout status deployment/nimble-opti-adapter-controller-manager -n nimble-opti-adapter-system
echo "Patching deployment..."
kubectl patch deployment nimble-opti-adapter-controller-manager -n nimble-opti-adapter-system -p '{"spec":{"template":{"spec":{"containers":[{"name":"kube-rbac-proxy","imagePullPolicy":"Always"},{"name":"manager","imagePullPolicy":"Always"}]}}}}'
# delete the nimble-opti-adapter-controller-manager pod to force a restart
kubectl delete pod -n nimble-opti-adapter-system -l control-plane=controller-manager
echo "Update complete."