-
Notifications
You must be signed in to change notification settings - Fork 26
/
publish.sh
executable file
·92 lines (78 loc) · 2.69 KB
/
publish.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
#!/bin/sh
set -ex
WORKING_DIRECTORY="$PWD"
check_prerequisites() {
[ "$GITHUB_PAGES_REPO" ] || { echo "ERROR: GITHUB_PAGES_REPO is required"; exit 1; }
[ -z "$HELM_CHARTS_SOURCE" ] && HELM_CHARTS_SOURCE="$WORKING_DIRECTORY/charts"
[ -d "$HELM_CHARTS_SOURCE" ] || {
echo "ERROR: Could not find Helm charts in $HELM_CHARTS_SOURCE"
exit 1
}
[ "$BUILDKITE_BRANCH" ] || { echo "ERROR: BUILDKITE_BRANCH is required"; exit 1; }
}
setup_environment() {
GITHUB_PAGES_BRANCH=${GITHUB_PAGES_BRANCH:-gh-pages}
HELM_CHARTS_SOURCE=${HELM_CHARTS_SOURCE:-"$PWD/charts"}
S3_BUCKET="helm-charts${BUILDKITE_PIPELINE_SLUG:+-test}"
}
configure_ssh() {
mkdir -p "$HOME/.ssh"
ssh-keyscan -H github.com >> "$HOME/.ssh/known_hosts"
}
clone_repo() {
echo ">> Cloning $GITHUB_PAGES_BRANCH branch from $GITHUB_PAGES_REPO"
rm -rf /tmp/helm/publish
git clone -b "$GITHUB_PAGES_BRANCH" --depth 1 "[email protected]:$GITHUB_PAGES_REPO.git" /tmp/helm/publish
cd /tmp/helm/publish
}
build_and_sync_charts() {
echo '>> Building charts...'
find "$HELM_CHARTS_SOURCE" -mindepth 1 -maxdepth 1 -type d | while read -r chart; do
chart_name=$(basename "$chart")
echo ">>> Processing $chart_name"
process_chart "$chart" "$chart_name"
done
}
process_chart() {
chart=$1
chart_name=$2
chart_version=$(grep "^version:" "$chart/Chart.yaml" | awk '{print $2}')
[ -f "$chart_name/$chart_name-$chart_version.tgz" ] && { echo ">>> $chart_version exists, skipping"; return; }
helm lint "$chart"
mkdir -p "$chart_name"
helm package -d "$chart_name" "$chart"
[ "$chart_name" = "komodor-agent" ] && push_chart_to_docker_hub "$chart_name/$chart_name-$chart_version.tgz"
sync_to_s3 "$chart_name"
}
push_chart_to_docker_hub() {
tgz_file=$1
echo ">> Pushing $tgz_file to Docker Hub"
export HELM_EXPERIMENTAL_OCI=1
helm registry login "registry-1.docker.io" -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD
helm push "$tgz_file" oci://registry-1.docker.io/komodorio
}
sync_to_s3() {
for domain in komodor.com komodor.io; do
aws s3 sync "$1" "s3://${S3_BUCKET}.${domain}/$1"
done
}
publish() {
[ "$BUILDKITE_BRANCH" != "master" ] && { echo "Not master, not publishing"; return; }
echo ">> Publishing to GitHub Pages"
git config user.email "[email protected]"
git config user.name "Buildkite"
git add .
git commit -m "Published by Buildkite $BUILDKITE_BUILD_URL"
git push origin "$GITHUB_PAGES_BRANCH"
}
main() {
check_prerequisites
setup_environment
configure_ssh
clone_repo
build_and_sync_charts
helm repo index .
sync_to_s3 "."
publish
}
main "$@"