-
Notifications
You must be signed in to change notification settings - Fork 7
/
upload.sh
executable file
·92 lines (81 loc) · 1.9 KB
/
upload.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 -x
CHARTMUSEUM_ADDR="http://kubegems-chartmuseum:8080"
CHARTS_DIR="/uploader/charts"
REPO=kubegems
WAIT=0
usage() {
echo "Upload helm charts to chartmuseum"
echo ""
echo "Example: $0 --server http://chartmuseum.example.com --repo myrepo charts/"
echo ""
echo "Usage: $0 [options...] <charts_dir>"
echo ""
echo "Options:"
echo "-s,--server server address of chartmuseum. Default: $CHARTMUSEUM_ADDR"
echo "-r,--repo repo to upload charts. Default: $REPO"
echo "-w,--wait wait util chartmuseum available."
echo "-h,--help show help message."
exit 1
}
wait() {
echo "waiting for chartmuseum $1 available."
while true; do
code=$(curl -sL -w "%{http_code}" "$1" -o /dev/null)
echo "chartmuseum $1: http_code=$code"
[ "$code" = "200" ] && break
sleep 5
done
echo "chartmuseum $1 is available."
}
upload() {
echo "uploading ${1} to server ${2} repo ${3}"
for file in $(find ${1} -name "*.tgz"); do
echo "uploading ${file}"
curl --data-binary "@${file}" -w "%{stdout}\n" ${2}/api/${3}/charts
done
}
OPTS=$(getopt -o s:,w,r:,h -l server:,wait,repo:,help -- "$@")
if [ $? != 0 ]; then
usage
fi
eval set -- "$OPTS"
while true; do
case $1 in
-s | --server)
CHARTMUSEUM_ADDR=$2
shift 2
;;
-r | --repo)
REPO=$2
shift 2
;;
-w | --wait)
shift
WAIT=1
;;
-h | --help)
usage
;;
--)
shift
break
;;
*)
echo "unexpected option: $1"
usage
;;
esac
done
#if [ ! -z $1 ]; then
# CHARTS_DIR=$1
#fi
if [ ! -d $CHARTS_DIR ]; then
echo "charts_dir $CHARTS_DIR not exist."
exit 1
fi
if [ ! $WAIT = 0 ]; then
wait ${CHARTMUSEUM_ADDR} ${WAIT}
fi
upload ${CHARTS_DIR} ${CHARTMUSEUM_ADDR} ${REPO}
exit 0