Deploy: push before building, and tag images with the commit
deploy.sh no longer needs a manual push before it, and no made-up tag: - It pushes the current branch, refuses a dirty tracked tree, and requires HEAD == origin/main before anything is built, so the image can only be built for a commit the remote actually has. --force and --no-push skip the guards. - The image is tagged :<commit> as well as :latest, and ansible takes -e image_tag=<commit>, so a deploy pins the exact revision; rollback is the same play with an older commit. - Makefile builds `git archive HEAD` instead of cloning the remote (the push guard makes the local commit the remote state) and defaults PLATFORM to linux/arm64, because emily is aarch64 — the same default mozimo uses. Drop build-check-local; build-check already builds the committed tree.
This commit is contained in:
1 parent
9620847108
commit
1c78fc5103
4 files changed
+113
-84
No files matched your search
@@ -1,15 +1,63 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# The Great Bear deploy — push the current commit, build it with podman, and
|
||||
# install the Quadlet unit on emily with ansible.
|
||||
#
|
||||
# The image is built from the committed tree (`git archive HEAD`) and tagged
|
||||
# with its commit id, so what runs on the host is exactly what git knows about.
|
||||
#
|
||||
# ./deploy.sh deploy HEAD (tracked tree must be clean and pushed)
|
||||
# ./deploy.sh --force skip the guards (know what you are doing)
|
||||
# ./deploy.sh --no-push skip the push, if you already pushed
|
||||
#
|
||||
# Log in to the registry once beforehand: podman login registry.tanshu.com
|
||||
set -euo pipefail
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")"
|
||||
|
||||
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" || exit ; pwd -P )
|
||||
cd "$parent_path" || exit
|
||||
BRANCH="${BRANCH:-main}"
|
||||
|
||||
FORCE=false
|
||||
NO_PUSH=false
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--force) FORCE=true ;;
|
||||
--no-push) NO_PUSH=true ;;
|
||||
*)
|
||||
echo "Usage: $0 [--force] [--no-push]" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# The build takes HEAD, so push first: otherwise the registry collects an image
|
||||
# for a commit that exists only on this machine.
|
||||
if [ "$NO_PUSH" != true ]; then
|
||||
echo "==> pushing"
|
||||
git push
|
||||
fi
|
||||
|
||||
# Guards. Only tracked-file state matters — untracked and ignored files never
|
||||
# enter a `git archive HEAD` build. HEAD must match origin/$BRANCH so the commit
|
||||
# the image is tagged with is one the remote actually has.
|
||||
if [ "$FORCE" != true ]; then
|
||||
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
|
||||
echo "x tracked files modified - commit or stash first (or --force)" >&2
|
||||
exit 1
|
||||
fi
|
||||
git fetch origin --quiet
|
||||
if [ "$(git rev-parse HEAD)" != "$(git rev-parse "origin/$BRANCH")" ]; then
|
||||
echo "x HEAD != origin/$BRANCH - push or pull first (or --force)" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
TAG=$(git rev-parse --short HEAD)
|
||||
echo "==> deploying commit $TAG"
|
||||
|
||||
echo "========================================================"
|
||||
echo " Building & Uploading Container Image (Podman)"
|
||||
echo "========================================================"
|
||||
current_version="${1:-latest}"
|
||||
make build-production TAG="$current_version"
|
||||
|
||||
make build-production COMMIT="$TAG"
|
||||
|
||||
echo ""
|
||||
echo "========================================================"
|
||||
@@ -19,5 +67,6 @@ echo "========================================================"
|
||||
# connecting user, so it must connect as that user and must NOT become root.
|
||||
# `-u` is the account that owns ~/.config/containers/systemd on the target.
|
||||
deploy_user="${ANSIBLE_USER:-tanshu}"
|
||||
cd "$parent_path/ansible" || exit
|
||||
ansible-playbook -u "$deploy_user" playbook.yml -e "tag=$current_version"
|
||||
cd ansible || exit
|
||||
# image_tag pins the exact commit; rollback is -e image_tag=<older-commit>.
|
||||
ansible-playbook -u "$deploy_user" playbook.yml -e "image_tag=$TAG"
|
||||
Reference in new issue
Block a user