-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
executable file
·82 lines (68 loc) · 2.17 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
#! /bin/sh
RUNNINGROOTDIR=/mnt/data
ROOTDIR=$(pwd)
PODROOTDIR=$ROOTDIR/pods
UPDATEREQUIRED=0
check_for_updates() {
PODNAME=$2
RELATIVEDIR=$(realpath --relative-to=$PODROOTDIR $1)
for i in "$1"/*;do
if [ -d "$i" ];then
check_for_updates "$i" $PODNAME
elif [ -f "$i" ]; then
GIT_FILE_ABSOLUTE=$i
GIT_FILE_RELATIVE=$(realpath --relative-to=$PODROOTDIR $i)
RUNNINGFILE=$RUNNINGROOTDIR/$GIT_FILE_RELATIVE
RUNNINGDIR=$RUNNINGROOTDIR/$RELATIVEDIR
mkdir -p $RUNNINGDIR
if [ ! -f "$RUNNINGFILE" ]; then
touch $RUNNINGFILE
fi
if cmp -s "$GIT_FILE_ABSOLUTE" "$RUNNINGFILE"; then
printf "."
else
echo $GIT_FILE_ABSOLUTE
echo $RUNNINGDIR/$GIT_FILE_RELATIVE
if [ $UPDATEREQUIRED = 0 ]; then
UPDATEREQUIRED=1
fi
echo "Updating $GIT_FILE_RELATIVE"
cp -f $GIT_FILE_ABSOLUTE $RUNNINGFILE
fi
fi
done
}
git fetch --all
UPSTREAM=${1:-'@{u}'}
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse "$UPSTREAM")
BASE=$(git merge-base @ "$UPSTREAM")
if [ $LOCAL = $REMOTE ]; then
echo ""
elif [ $LOCAL = $BASE ]; then
git pull
fi
for f in $PODROOTDIR/*; do
if [ -d "$f" ]; then
PODNAME=$(realpath --relative-to=$PODROOTDIR $f)
UPDATEREQUIRED=0
PODRUNNINGDIR=$RUNNINGROOTDIR/$PODNAME
cp -f $PODRUNNINGDIR/app.yaml $PODRUNNINGDIR/app-bak.yaml
check_for_updates $f $PODNAME
echo
if [ $UPDATEREQUIRED = 1 ]; then
if [ -f "$PODRUNNINGDIR/secrets.yaml" ]; then
kubectl delete -f $PODRUNNINGDIR/secrets.yaml
fi
kubectl apply -f $PODRUNNINGDIR/app.yaml
kubectl rollout restart deployment/$PODNAME
if [ $? != 0 ]; then
kubectl delete -f $PODRUNNINGDIR/app-bak.yaml
kubectl apply -f $PODRUNNINGDIR/app.yaml
kubectl apply -f $PODRUNNINGDIR/secrets.yaml
fi
else
echo "$PODNAME Up to Date"
fi
fi
done