update
This commit is contained in:
@@ -15,26 +15,44 @@ trap 'printf "ERROR: broker update failed at line %d.\n" "$LINENO" >&2' ERR
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
command -v git >/dev/null 2>&1 || fail "git is required"
|
||||
command -v docker >/dev/null 2>&1 || fail "docker is required"
|
||||
docker compose version >/dev/null 2>&1 || fail "Docker Compose v2 is required"
|
||||
[[ -f compose.yaml ]] || fail "compose.yaml was not found in ${SCRIPT_DIR}"
|
||||
[[ -f .env ]] || fail ".env was not found in ${SCRIPT_DIR}"
|
||||
|
||||
if [[ "${1:-}" != "--post-pull" ]]; then
|
||||
branch="$(git symbolic-ref --quiet --short HEAD)" ||
|
||||
fail "the repository is in detached HEAD state"
|
||||
git rev-parse --abbrev-ref --symbolic-full-name '@{upstream}' >/dev/null 2>&1 ||
|
||||
upstream="$(git rev-parse --abbrev-ref --symbolic-full-name '@{upstream}' 2>/dev/null)" ||
|
||||
fail "branch ${branch} does not have an upstream branch"
|
||||
remote="$(git config --get "branch.${branch}.remote")" ||
|
||||
fail "branch ${branch} does not have a configured remote"
|
||||
git diff --quiet && git diff --cached --quiet ||
|
||||
fail "tracked local changes must be committed or stashed before updating"
|
||||
|
||||
printf 'Updating TAPM Deployment Broker from branch %s...\n' "$branch"
|
||||
git pull --ff-only
|
||||
printf 'Checking %s against %s...\n' "$branch" "$upstream"
|
||||
git fetch --prune "$remote"
|
||||
|
||||
local_commit="$(git rev-parse HEAD)"
|
||||
upstream_commit="$(git rev-parse '@{upstream}')"
|
||||
if [[ "$local_commit" == "$upstream_commit" ]]; then
|
||||
printf 'TAPM Deployment Broker is already up to date; no changes were made.\n'
|
||||
exit 0
|
||||
fi
|
||||
if git merge-base --is-ancestor "$local_commit" "$upstream_commit"; then
|
||||
printf 'Updating TAPM Deployment Broker from %s...\n' "$upstream"
|
||||
git merge --ff-only "$upstream_commit"
|
||||
elif git merge-base --is-ancestor "$upstream_commit" "$local_commit"; then
|
||||
fail "local branch ${branch} is ahead of ${upstream}; refusing to rebuild"
|
||||
else
|
||||
fail "local branch ${branch} has diverged from ${upstream}"
|
||||
fi
|
||||
|
||||
# Restart from the newly pulled script so updates to this file take effect.
|
||||
exec "$SCRIPT_PATH" --post-pull
|
||||
fi
|
||||
|
||||
command -v docker >/dev/null 2>&1 || fail "docker is required"
|
||||
docker compose version >/dev/null 2>&1 || fail "Docker Compose v2 is required"
|
||||
[[ -f compose.yaml ]] || fail "compose.yaml was not found in ${SCRIPT_DIR}"
|
||||
[[ -f .env ]] || fail ".env was not found in ${SCRIPT_DIR}"
|
||||
|
||||
printf 'Building broker image...\n'
|
||||
docker compose build broker
|
||||
|
||||
|
||||
Reference in New Issue
Block a user