#!/usr/bin/env bash # Deploy HEAD with podman and ansible on emily. Flags: --prune keeps three old # images, --force skips the guards. The tree must be clean and HEAD pushed. set -euo pipefail cd "$(dirname "${BASH_SOURCE[0]}")" git push FORCE=false PRUNE=false for arg in "$@"; do case "$arg" in --force) FORCE=true ;; --prune) PRUNE=true ;; *) echo "Usage: $0 [--force] [--prune]" >&2 exit 1 ;; esac done 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/main)" ]; then echo "x HEAD != origin/main, push or pull first (or --force)" >&2 exit 1 fi fi git pull --ff-only TAG=$(git rev-parse --short HEAD) echo "==> deploying commit $TAG" make build-production COMMIT="$TAG" if [ "$PRUNE" = true ]; then PRUNE_FLAG="-e hops_image_prune=true" else PRUNE_FLAG="" fi cd ansible # shellcheck disable=SC2086 ansible-playbook playbook.yml -e "image_tag=$TAG" $PRUNE_FLAG