aboutsummaryrefslogtreecommitdiffstats
path: root/deploy/deploy.sh
blob: 038d05ad02751e6b17d1d8ae25f25aaf25ac7523 (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 policy_api and restart it. Run by policy-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/policy_api}"
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"
GIT_SHA=$new cargo build --release -q
sudo -n systemctl restart policy-api
echo "$new" > .git/deployed
echo "deployed $(git log --oneline -1)"