summaryrefslogtreecommitdiffstats
path: root/flood_api/deploy/deploy.sh
blob: cf95e64c691311d1346e0dc4e31794b0b92d10c1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/sh
# Pull-based deploy (valencia): move the checkout to origin/live (CI moves it only after green checks on main),
# rebuild flood_api and restart it. Run by flood-api-deploy.timer every minute. A failed build keeps the old
# binary running and is retried on the next run.
set -eu
cd "${REPO_DIR:-$HOME/hackathon}"
git fetch -q origin live 2>/dev/null || exit 0          # no live branch yet
new=$(git rev-parse FETCH_HEAD)
[ "$(cat .git/deployed 2>/dev/null)" = "$new" ] && exit 0
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
    echo "local changes in $(pwd), not deploying $new" >&2; exit 1
fi
git checkout -q -B live "$new"
(cd flood_api && GIT_SHA=$new cargo build --release -q)
sudo -n systemctl restart flood-api
echo "$new" > .git/deployed
echo "deployed $(git log --oneline -1)"