#!/usr/bin/env bash # Mozimo deploy — build the exact commit at origin/main, tag it with its # commit id, and hand that tag to ansible. Guards make it impossible to # deploy anything other than what git knows about. # # ./deploy.sh deploy HEAD (must be pushed, tree must be clean) # ./deploy.sh --prune also drop old mozimo images on the server (keep 3) # ./deploy.sh --force skip the guards (know what you are doing) 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]" exit 1 ;; esac done # guards: only tracked-file state matters (untracked files never enter a # `git archive HEAD` build); HEAD must equal origin/main if [ "$FORCE" != true ]; then if [ -n "$(git status --porcelain --untracked-files=no)" ]; then echo "✗ 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 "✗ 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 TAG="$TAG" PRUNE_FLAG="" if [ "$PRUNE" = true ]; then PRUNE_FLAG="-e mozimo_image_prune=true" fi cd ansible # shellcheck disable=SC2086 ansible-playbook playbook.yml -e "image_tag=$TAG" $PRUNE_FLAG