forked from yearn/yearn-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·57 lines (43 loc) · 1.42 KB
/
deploy.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
#!/usr/bin/env bash
set -e
WORKDIR="$HOME/yearn-exporter"
COMPOSE="$WORKDIR/docker-compose.yml"
REPOSITORY="https://github.com/yearn/yearn-exporter"
echo "[*] Starting deployment"
echo "[*] Sourcing environment"
if ! [ -f "$HOME/env" ]; then
echo "[!] env file not found in \$HOME. Exiting..."
exit 1
fi
source $HOME/env
if ! [ -d "$WORKDIR" ]; then
echo "[*] Workdir does not exist, cloning now..."
git clone $REPOSITORY "$WORKDIR"
fi
if ! [ -f "$COMPOSE" ]; then
echo "[!] Compose file does not exist in repository. Exiting..."
exit 1
fi
echo "[*] Checking repo state"
git -C "$WORKDIR" fetch
UPSTREAM=${1:-'@{u}'}
LOCAL=$(git -C "$WORKDIR" rev-parse @)
REMOTE=$(git -C "$WORKDIR" rev-parse "$UPSTREAM")
BASE=$(git -C "$WORKDIR" merge-base @ "$UPSTREAM")
if [ "$LOCAL" = "$REMOTE" ]; then
echo "[*] Up-to-date, no changes needed. Continuing..."
elif [ "$LOCAL" = "$BASE" ]; then
echo "[*] Need to pull. Continuing..."
git -C "$WORKDIR" pull
elif [ "$REMOTE" = "$BASE" ]; then
echo "[!] Local changes detected. Manual maintenance needed. Exiting..."
exit 1
else
echo "[!] Branches are diverged. Manual maintenance needed. Exiting..."
exit 1
fi
echo "[*] Stopping existing service"
docker-compose -f "$COMPOSE" down --remove-orphans
echo "[*] Building and deploying..."
docker-compose -f "$COMPOSE" up --build -d
echo "[*] Finished!"