-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdeploy.sh
executable file
·76 lines (54 loc) · 1.62 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
#!/bin/bash
# Fail if any script returns a nonzero exit code
set -e
cat <<EOF
############################
# KirBot Deployment Script #
############################
EOF
if [[ $(git rev-parse --is-inside-work-tree 2>/dev/null) == "true" ]]; then
echo "Git repository has been initialized"
else
echo "Git repository was not found."
exit 1
fi
branch=${1:-master}
echo "Deploying branch $branch"
# Fetch the branch and check it out
git fetch origin "$branch"
commit_hash=$(git rev-parse "refs/remotes/origin/$branch^{commit}")
echo "Branch to deploy: $branch ($commit_hash)"
echo "Are you sure you want to deploy this branch? If not hit Ctrl + C now!"
sleep 5
echo "Deploying..."
echo "Backing up database..."
docker-compose exec db mysqldump kirbot --user=kirbot --password=kirbot > .data/last_backup.sql
git reset --hard "$commit_hash"
echo "Updating KirBotPanel"
git submodule init
git submodule update
echo "Building KirBot docker images"
docker-compose build
echo "Updating running images"
docker-compose up -d
echo "Waiting 5 seconds to give updated containers a chance to start"
sleep 5
echo "Installing composer dependencies"
docker-compose exec web composer install --no-dev
echo "Running database migrations"
docker-compose exec web php artisan migrate --force
# Enter KirBotPanel directory
echo "Updating Panel"
cd KirBotPanel
echo "Running yarn"
yarn install
echo "Building dependencies"
yarn run prod
echo "Dashboard has been built successfully"
# Leave KirBotPanel directory
cd ..
echo "Updating documentation"
cd docs
LC_ALL=C.UTF-8 mkdocs build
cd ..
echo "SUCCESS! Panel has been deployed. $branch ($commit_hash)"