This repository has been archived by the owner on Jul 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_service.sh
executable file
·44 lines (38 loc) · 2.02 KB
/
update_service.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
#!/bin/bash
if [ -z "$GITHUB_API_TOKEN" ]; then
echo "Error: GITHUB_API_TOKEN is not set!"
exit 1
fi
while [ $# -gt 0 ]
do
case "$1" in
-f) service_file="$2"; shift;;
-n) service_name="$2"; shift;;
-b) build_num="$2"; shift;;
-t) branch="$2"; shift;;
-h)
echo >&2 "usage: $0 -t branch -b build -f service_file -n service_name"
exit 1;;
*) break;; # terminate while loop
esac
shift
done
set -o xtrace
# create branch, if missing in gaia-fleet
master_sha=$(curl --fail -S -L "https://api.github.com/repos/gaia-adm/gaia-fleet/git/refs/heads/master" | jq .object.sha | tr -d '"')
branch_missing=$(curl -I -s https://api.github.com/repos/gaia-adm/gaia-fleet/git/refs/heads/${branch} | grep '404 Not Found' | wc -l)
if (( $branch_missing > 0 )); then
curl -XPOST -H "Authorization: token ${GITHUB_API_TOKEN}" -H "Content-Type: application/json" -H "Accept: application/vnd.github.v3+json" -d '{"ref": "refs/heads/'${branch}'", "sha": "'$master_sha'"}' https://api.github.com/repos/gaia-adm/gaia-fleet/git/refs
fi
f_sha=$(curl --fail -S -L "https://api.github.com/repos/gaia-adm/gaia-fleet/contents/${service_file}?ref=${branch}" | jq .sha | tr -d '"')
# set version for gaiaadm images
grep gaiaadm\/${service_name} ${service_file}
if [ $(echo $?) -eq "0" ]; then
f_64=$(openssl enc -base64 -A -in <(sed "s/gaiaadm\/${service_name}/gaiaadm\/${service_name}:${build_num}-${branch}/g" ${service_file}))
fi
# set version for gaiadocker images
grep gaiadocker\/${service_name} ${service_file}
if [ $(echo $?) -eq "0" ]; then
f_64=$(openssl enc -base64 -A -in <(sed "s/gaiadocker\/${service_name}/gaiadocker\/${service_name}:${build_num}-${branch}/g" ${service_file}))
fi
curl --fail -S -i -X PUT -H "Authorization: token ${GITHUB_API_TOKEN}" -d "{\"path\": \"${service_file}\", \"message\": \"updating ${service_file} with the new image tag: ${build_num}-${branch}\", \"content\": \"${f_64}\", \"sha\": \"${f_sha}\", \"branch\": \"${branch}\"}" https://api.github.com/repos/gaia-adm/gaia-fleet/contents/${service_file}