hmn/server/deploy.sh

46 lines
846 B
Bash
Raw Permalink Normal View History

2021-08-28 20:36:52 +00:00
#!/bin/bash
2021-08-29 23:11:41 +00:00
set -eo pipefail
2021-09-04 14:27:05 +00:00
source /home/hmn/hmn/server/hmn.conf
2021-08-28 20:36:52 +00:00
2021-08-29 23:11:41 +00:00
branch=$1
if [ -z "$branch" ]; then
echo "Type the name of the branch you would like to deploy: "
read branch
fi
echo "Deploying branch $branch..."
do_as() {
sudo -u $1 --preserve-env=PATH bash -s
}
2021-08-28 20:36:52 +00:00
2021-09-05 20:35:56 +00:00
cd /home/hmn/hmn
old_rev=$(git log -1 --pretty=format:%H)
2021-08-29 23:11:41 +00:00
do_as hmn <<SCRIPT
2021-08-28 20:36:52 +00:00
set -euo pipefail
2021-08-29 23:11:41 +00:00
cd /home/hmn/hmn
git fetch --all
git reset --hard origin/$branch
go build -o /home/hmn/bin/hmn src/main.go
2021-08-28 20:36:52 +00:00
SCRIPT
2021-08-29 23:11:41 +00:00
echo "Running migrations..."
systemctl stop hmn
2021-08-29 23:11:41 +00:00
do_as hmn <<'SCRIPT'
2021-08-28 20:36:52 +00:00
set -euo pipefail
/home/hmn/bin/hmn migrate
2021-08-28 20:36:52 +00:00
SCRIPT
systemctl start hmn
2021-09-05 20:35:56 +00:00
cd /home/hmn/hmn
new_rev=$(git log -1 --pretty=format:%H)
if [ $old_rev != $new_rev ]; then
adminmailer "[$HMN_ENV] Deployed new version" <<DEPLOYMAIL
$(git --no-pager log --no-color $old_rev..)
DEPLOYMAIL
fi