forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease-helm.sh
executable file
·92 lines (76 loc) · 2.5 KB
/
release-helm.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
#!/usr/bin/env bash
set -euo pipefail
# release-helm.sh
#
# SUMMARY
#
# Package Helm Chart and update the Helm repo.
cd "$(dirname "${BASH_SOURCE[0]}")/.."
set -x
CHANNEL="${CHANNEL:-"$(scripts/release-channel.sh)"}"
VERSION="${VERSION:-"$(scripts/version.sh)"}"
if [[ "$CHANNEL" == "nightly" ]]; then
DATE="${DATE:-"$(date -u +%Y-%m-%d)"}"
APP_VERSION="nightly-$DATE" # matches the version part of the image tag
CHART_VERSION="$VERSION-nightly-$DATE"
else
APP_VERSION="$VERSION" # matches the version part of the image tag
CHART_VERSION="$VERSION"
fi
if [[ "${USE_TEST_REPO:-"false"}" == "true" ]]; then
PUBLIC_URL="https://vector-helm-repo-tests.s3.amazonaws.com/helm/$CHANNEL"
AWS_REPO_URL="s3://vector-helm-repo-tests/helm/$CHANNEL"
else
PUBLIC_URL="https://packages.timber.io/helm/$CHANNEL"
AWS_REPO_URL="s3://packages.timber.io/helm/$CHANNEL"
fi
WORKDIR="target/helm"
REPO_DIR="$WORKDIR/repo"
PREVIOUS_MANIFEST="$WORKDIR/previous-manifest.yaml"
capture_stderr() {
{ OUTPUT=$("$@" 2>&1 1>&3-); } 3>&1
}
# Prepare work directory.
rm -rf "$REPO_DIR"
mkdir -p "$REPO_DIR"
# Ensure chart dependencies are up to date.
echo "Validating the dependencies"
scripts/helm-dependencies.sh validate
# Read the shared scripting config.
source "distribution/helm/scripting-config.sh"
# Package our charts.
for CHART in "${CHARTS_TO_PUBLISH[@]}"; do
helm package \
"distribution/helm/$CHART" \
--version "$CHART_VERSION" \
--app-version "$APP_VERSION" \
--destination "$REPO_DIR"
# Apply a workaround to fix the subchart versions.
PACKAGED_ARCHIVE_PATH="$REPO_DIR/$CHART-$CHART_VERSION.tgz"
scripts/patch-packaged-helm-chart-versions.sh \
"$PACKAGED_ARCHIVE_PATH" \
"$CHART" \
"$CHART_VERSION" \
"$APP_VERSION"
done
# Download previous manifest.
# If it doesn't exist - ignore the error and continue.
if ! capture_stderr aws s3 cp "$AWS_REPO_URL/index.yaml" "$PREVIOUS_MANIFEST"; then
EXPECTED="^fatal error:"
EXPECTED="$EXPECTED An error occurred \(404\) when calling the HeadObject operation:"
EXPECTED="$EXPECTED Key \".*/index\.yaml\" does not exist$"
if ! grep -Eq "$EXPECTED" <<<"$OUTPUT"; then
echo "$OUTPUT" >&2
exit 1
else
echo "Warning: repo index file doesn't exist, but we ignore the error" \
"because we will initialize it"
fi
fi
# Update the repo index file.
helm repo index \
"$REPO_DIR" \
--merge "$PREVIOUS_MANIFEST" \
--url "$PUBLIC_URL"
# Upload new files to the repo.
aws s3 cp "$REPO_DIR" "$AWS_REPO_URL" --recursive --sse --acl public-read