-
Notifications
You must be signed in to change notification settings - Fork 15
/
deploy.sh
99 lines (75 loc) · 2.26 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
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
#!/bin/bash
function deploy() {
# Ensure we always start from the repository root-folder
local repo
repo=$(git rev-parse --show-toplevel)
cd "$repo" || return
# Arguments
local target=$1 || false
function log() {
printf "\n\n"
# highlight/warn:
tput setaf 3
echo "$@"
printf "\n"
# reset highlight/warn:
tput sgr0
}
function update_code() {
log "Update code..."
local target=$1 || false
cd "$repo" || return
git reset --hard
git fetch --all --tags
# When a target is provided, checkout that
if [[ -n "$target" ]]
then
log "Check out: $target"
git checkout "$target"
else
log "Pull latest changes"
git checkout master
git pull --ff-only
fi
}
function load_environment_variables() {
log "Load environment variables..."
set -a; [ -f ./.env ] && . ./.env; set +a;
export NG_IBF_SYSTEM_VERSION=v$(node -p "require('./package.json').version")
log echo "NODE_ENV: $NODE_ENV"
log echo "NG_CONFIGURATION: $NG_CONFIGURATION"
log echo "NG_IBF_SYSTEM_VERSION: $NG_IBF_SYSTEM_VERSION"
}
function update_containers() {
log "Update containers..."
cd "$repo" || return
docker compose down -v
docker compose --env-file /dev/null config > inspect.docker-compose.config
docker compose --env-file /dev/null -f docker-compose.yml up -d --build
docker compose --env-file /dev/null restart
# wait 30 seconds for services to go live
sleep 30s
}
function restart_webhook_service() {
log "Restart webhook service..."
sudo systemctl daemon-reload
sudo service webhook restart
}
function cleanup_docker() {
log "Clean up Docker..."
docker system prune -f
}
function cleanup_dashboard_build() {
log "Clean up dashboard build..."
rm -rf "$repo"/interfaces/IBF-dashboard/www/*
}
update_code "$target"
load_environment_variables
cleanup_docker
cleanup_dashboard_build
update_containers
cleanup_docker
restart_webhook_service
log "Done."
}
deploy "$@"