-
Notifications
You must be signed in to change notification settings - Fork 4
/
common.sh
72 lines (60 loc) · 2.04 KB
/
common.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
#
# Environment Variables with Default Values
#
# namespace name for the container registry
readonly export REGISTRY_NAMESPACE="${REGISTRY_NAMESPACE:-registry}"
# the container registry uses the internal k8s service hosntame
readonly export REGISTRY_HOSTNAME="${REGISTRY_HOSTNAME:-registry.registry.svc.cluster.local}"
# namespace name for Tekton Pipeline controller
readonly export TEKTON_NAMESPACE="${TEKTON_NAMESPACE:-tekton-pipelines}"
# timeout employed during rollout status and deployments in general
readonly export DEPLOYMENT_TIMEOUT="${DEPLOYMENT_TIMEOUT:-5m}"
#
# Helper Functions
#
# print error message and exit on error.
function fail() {
echo "ERROR: ${*}" >&2
exit 1
}
# print out a strutured message.
function phase() {
echo "---> Phase: ${*}..."
}
# uses kubectl to check the deployment status on namespace and name informed.
function rollout_status() {
local namespace="${1}"
local deployment="${2}"
if ! kubectl --namespace="${namespace}" --timeout=${DEPLOYMENT_TIMEOUT} \
rollout status deployment "${deployment}"; then
fail "'${namespace}/${deployment}' is not deployed as expected!"
fi
}
# inspect the path after the informed executable name.
function probe_bin_on_path() {
local name="${1}"
if ! type -a ${name} >/dev/null 2>&1; then
fail "Can't find '${name}' on 'PATH=${PATH}'"
fi
}
# get the artifact url for the specific version (release) or latest.
function get_release_artifact_url() {
local _org_repo="${1}"
local _version="${2}"
local _url="https://api.github.com/repos/${_org_repo}/releases"
if [[ "${_version}" == "latest" ]]; then
echo $(
curl -s ${_url}/latest |
jq -r '.assets[].browser_download_url' |
egrep -i 'release.yaml' |
head -n 1
)
else
echo $(
curl -s ${_url} |
jq -r ".[] | select(.tag_name == \"${_version}\") | .assets[].browser_download_url" |
egrep -i 'release.yaml' |
head -n 1
)
fi
}