-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheck_helm_chart
56 lines (50 loc) · 1.65 KB
/
check_helm_chart
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
#!/bin/sh
## Exit code legend
# -2: Unknown error
# -1: Missing arguments
# 0: Success (chart matches or chart is new/uploaded)
# 1: Chart doesn't match
set -e ## Exit on error
TMPDIR=$(mktemp -d)
if [ -z "$1" ]; then
echo "Missing Arguments" >&2
echo "Usage: $0 <path/to/chart> [--upload]"
echo "Note: Order is important. If specified `--upload` MUST come after `path/to/chart`"
exit -1
fi
CHARTDIR=$(realpath "$1")
cd ${TMPDIR}
helm dep up "${CHARTDIR}"
helm package "${CHARTDIR}"
LOCAL_PACKAGE=$(ls *.tgz | head -n1)
REMOTE_PACKAGE=${LOCAL_PACKAGE%%.tgz}.remote.tgz
RESULT=$(curl https://eccr.ecmwf.int/chartrepo/geoglows_api/charts/${LOCAL_PACKAGE} -so ${REMOTE_PACKAGE} -u ${ECCR_USER}:${ECCR_PASSWORD} -w '%{http_code}\n')
if [ ${RESULT} -eq 404 ]; then
echo "Chart not found on remote" >&2
if [[ "$2" == "--upload" ]]; then
helm package ${CHARTDIR} --sign --key 'Aquaveo Chart Signing Key' --keyring ~/.gnupg/secring.gpg
echo "Uploading chart..."
curl -F "chart=@${LOCAL_PACKAGE}" -F "prov=@${LOCAL_PACKAGE}.prov" https://eccr.ecmwf.int/api/chartrepo/geoglows_api/charts -u ${ECCR_USER}:${ECCR_PASSWORD}
echo -e "\nDone."
fi
exit 0
elif [ ${RESULT} -ne 200 ]; then
echo "Unknown error while trying to retrieve chart from remote" >&2
exit -2
fi
mkdir local remote
tar xf ${LOCAL_PACKAGE} -C local
tar xf ${REMOTE_PACKAGE} -C remote
for DIR in local remote; do
rm -f ${DIR}/**/*.lock
done
set +e
diff -r local remote
RESULT=$?
if [ $RESULT -eq 1 ]; then
echo "Chart contains changes, but the version number has not been updated!" >&2
exit 1
else
echo "No changes detected!"
fi
echo "Done."