hmn/server/deploy.sh

33 lines
574 B
Bash
Raw 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-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