-
Notifications
You must be signed in to change notification settings - Fork 10
/
common.sh
executable file
·93 lines (82 loc) · 2.97 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash -l
set -eo pipefail
export HELM_VERSION=${HELM_VERSION:="3.5.1"}
export HELM_ARTIFACTORY_PLUGIN_VERSION=${HELM_ARTIFACTORY_PLUGIN_VERSION:="v1.0.2"}
export CHART_VERSION=${CHART_VERSION:-}
print_title(){
echo "#####################################################"
echo "$1"
echo "#####################################################"
}
get_chart_version(){
if [ -n "$CHART_VERSION" ]; then
echo "CHART_VERSION variable is already set (value: $CHART_VERSION), will override Chart.yaml"
return
fi
print_title "Calculating chart version"
echo "Installing prerequisites"
pip3 install PyYAML
pushd "$CHART_DIR"
CANDIDATE_VERSION=$(python3 -c "import yaml; f=open('Chart.yaml','r'); p=yaml.safe_load(f.read()); print(p['version']); f.close()" )
popd
echo "${GITHUB_EVENT_NAME}"
if [ "${GITHUB_EVENT_NAME}" == "pull_request" ]; then
CHART_VERSION="${CANDIDATE_VERSION}-$(git rev-parse --short "$GITHUB_SHA")"
else
CHART_VERSION="${CANDIDATE_VERSION}"
fi
export CHART_VERSION
}
get_helm() {
print_title "Get helm:${HELM_VERSION}"
curl -L "https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz" | tar xvz
chmod +x linux-amd64/helm
sudo mv linux-amd64/helm /usr/local/bin/helm
}
install_helm() {
if ! command -v helm; then
echo "Helm is missing"
get_helm
elif ! [[ $(helm version --short -c) == *${HELM_VERSION}* ]]; then
echo "Helm $(helm version --short -c) is not desired version"
get_helm
fi
}
install_artifactory_plugin(){
print_title "Install helm artifactory plugin"
if ! (helm plugin list | grep -q push-artifactory); then
helm plugin install https://github.com/belitre/helm-push-artifactory-plugin --version "${HELM_ARTIFACTORY_PLUGIN_VERSION}"
fi
}
remove_helm(){
helm plugin uninstall push-artifactory
sudo rm -rf /usr/local/bin/helm
}
helm_dependency(){
print_title "Helm dependency build"
helm dependency build "${CHART_DIR}"
}
helm_lint(){
print_title "Linting"
helm lint "${CHART_DIR}"
}
helm_package(){
print_title "Packaging"
helm package "${CHART_DIR}" --version v"${CHART_VERSION}" --app-version "${CHART_VERSION}" --destination "${RUNNER_WORKSPACE}"
}
helm_push(){
print_title "Push chart"
if [[ "${SKIP_REINDEX}" == "true" ]]; then
extra_args="--skip-reindex"
else
extra_args=""
fi
if [[ -v ARTIFACTORY_API_KEY ]]; then
helm push-artifactory "${CHART_DIR}" "${ARTIFACTORY_URL}" --api-key "${ARTIFACTORY_API_KEY}" --version "${CHART_VERSION}" "${extra_args}"
elif [[ -v ARTIFACTORY_PASSWORD ]] && [[ -v ARTIFACTORY_USERNAME ]]; then
helm push-artifactory "${CHART_DIR}" "${ARTIFACTORY_URL}" --username "${ARTIFACTORY_USERNAME}" --password "${ARTIFACTORY_PASSWORD}" --version "${CHART_VERSION}" "${extra_args}"
else
echo "ARTIFACTORY_API_KEY or ARTIFACTORY_PASSWORD and ARTIFACTORY_USERNAME must be set"
exit 1
fi
}