-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathupdate.sh
executable file
·130 lines (117 loc) · 2.33 KB
/
update.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
set -x
CFGFILE='grafana.yaml'
usage() {
base="$(basename "$0")"
cat <<EOUSAGE
usage: $base [-1|-2|-3|-4|-5] <github tag>
Setup and release new grafana version on grafana-on-raspberry github repo
-1 do only step 1: create trigger commit
-2 do only step 2: create tag to trigger deployment
-3 do only step 3: wait for travis
-4 do only step 4: create docker image, test and push
-5 do only step 5: commit docker update
-h this help
EOUSAGE
}
trigger_commit() {
echo "dummy commit to trigger ${VERSION} build on ci" > .dummy
git add .dummy
git commit -m "trigger ${VERSION}"
git push
}
deploy_commit() {
DIGEST=$(git log -n1 --pretty=oneline | cut -f1 -d' ')
git tag -a ${VERSION} -m ${VERSION} ${DIGEST}
git push origin ${VERSION}
}
wait_travis() {
sleep 30
STATE=$(travis history -b ${VERSION} --no-interactive | head -n1 | cut -f2 -d' ')
echo ${STATE}
sleep 600
for i in `seq 1 20`; do
STATE=$(travis history -b ${VERSION} --no-interactive | head -n1 | cut -f2 -d' ')
echo ${STATE}
case ${STATE} in
passed:)
break
;;
failed:)
echo "** Err: Travis build failed"
echo "** Docker image NOT build"
echo "** Fail **"
exit 1
;;
esac
sleep 90
done
if [[ ${STATE} != *passed:* ]]; then
echo "** Err: Travis build timeout (current state: ${STATE})"
echo "** Docker image NOT build"
exit 1
fi
}
docker_image() {
cd docker/v4.x/
sed -i "1s/^/- ${VERSION}\n/" ${CFGFILE}
./build.py
./build.py -t
./build.py -p
cd -
}
docker_commit() {
git rm .dummy
git commit -a -m "docker: ${VERSION}"
git push
}
if [[ `git config user.name` != "fg2it" ]]; then
echo "Error: Wrong git user"
exit 1
fi
VERSION=$1
if (( $# != 1 )); then
VERSION=$2
fi
case $1 in
-1)
shift
trigger_commit
exit 0
;;
-2)
shift
deploy_commit
exit 0
;;
-3)
shift
wait_travis
exit 0
;;
-4)
shift
docker_image
exit 0
;;
-5)
shift
docker_commit
exit 0
;;
-*)
usage
exit 0
;;
esac
echo >&2 "1/5 creating trigger commit"
trigger_commit
echo >&2 "2/5 creating tag/trigger deployment"
deploy_commit
echo >&2 "3/5 waiting travis"
wait_travis
echo >&2 "4/5 docker"
docker_image
echo >&2 "5/5 commit docker update"
docker_commit
echo >&2 "Success"