-
Notifications
You must be signed in to change notification settings - Fork 1
/
chart-build.sh
100 lines (86 loc) · 2.41 KB
/
chart-build.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
94
95
96
97
98
99
100
#!/bin/bash -x
help() {
echo "Build Script
Usage: build.sh -b DRONE_BUILD_NUMBER -e Environment
All flags are optional
-b Drone build number (10)
-e Environment (dev|production)"
}
while getopts ":b:r:e:h" opt; do
case $opt in
b)
DRONE_BUILD_NUMBER="${OPTARG}"
;;
r)
RELEASE="${OPTARG}"
;;
e)
Environment="${OPTARG}"
;;
h)
help && exit 0
;;
:)
echo "Option -$OPTARG requires an argument."
exit 1
;;
*)
help && exit 0
esac
done
if [[ -z $RELEASE ]]
then
echo "Release must be set"
exit 0
fi
echo "::Info::"
echo "Environment: $Environment"
echo "Release: $RELEASE"
echo "Build Number: $DRONE_BUILD_NUMBER"
echo "Setting up SSH..."
mkdir -p ~/.ssh
echo "$SSH_KEY" > ~/.ssh/id_rsa.bin
cat ~/.ssh/id_rsa.bin | base64 -d > ~/.ssh/id_rsa
chmod 0600 ~/.ssh/id_rsa
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
git config --global core.sshCommand "ssh -i ~/.ssh/id_rsa -F /dev/null -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
echo "Find and replace values..."
sed -i "s|RELEASE|${RELEASE}|g" ./chart/k3s-janitor/Chart.yaml
sed -i "s|RELEASE|${RELEASE}|g" ./chart/k3s-janitor/values.yaml
sed -i "s|DRONE_BUILD_NUMBER|${DRONE_BUILD_NUMBER}|g" ./chart/k3s-janitor/Chart.yaml
sed -i "s|DRONE_BUILD_NUMBER|${DRONE_BUILD_NUMBER}|g" ./chart/k3s-janitor/values.yaml
# echo "::Chart::"
# cat ./chart/k3s-janitor/Chart.yaml
# echo "::Values::"
# cat ./chart/k3s-janitor/values.yaml
echo "Packaging helm chart..."
helm package ./chart/k3s-janitor/ --version $RELEASE --app-version $DRONE_BUILD_NUMBER
echo "Pulling down chart repo..."
mkdir -p /drone/helm-repo
cd /drone/helm-repo
if [[ ${Environment} == "production" ]]
then
git clone --verbose --progress [email protected]:SupportTools/helm-chart.git .
elif [[ ${Environment} == "dev" ]]
then
git clone --verbose --progress [email protected]:SupportTools/helm-chart-dev.git .
else
echo "Unknown Environment"
fi
echo "Copying package into repo..."
cp /drone/src/k3s-janitor-*.tgz .
echo "Reindexing repo..."
if [[ ${Environment} == "production" ]]
then
helm repo index --url https://charts.support.tools/ --merge index.yaml .
elif [[ ${Environment} == "dev" ]]
then
helm repo index --url https://charts-dev.support.tools/ --merge index.yaml .
else
echo "Unknown Environment"
fi
echo "Publishing to Chart repo..."
git add .
git commit -m "Publishing KubeBackup ${RELEASE}"
git push