This repository has been archived by the owner on Feb 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow deploying latest build again (#114)
The current deployable check does not allow to redeploy the same deployment once again. Meaning if your deployment gets corrupted somehow you cannot delete it and deploy it again. As an example, Airflow (jobflow) currently as a bug due to missing support for certain kubernetes resources which can have it looses track of some of the resources it created in k8s. The only work around seem to delete and create again the deployment (_cf._ apache/airflow#21087).
- Loading branch information
Showing
2 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env sh | ||
|
||
set -eu | ||
|
||
fatal() { | ||
printf "$*\n" >/dev/stderr | ||
exit 1 | ||
} | ||
|
||
usage() { | ||
cat <<EOF | ||
usage: $0 OPTIONS <name> | ||
OPTIONS | ||
-h display help | ||
-p tag pattern (default: $pattern) | ||
EOF | ||
} | ||
|
||
pattern="*" | ||
|
||
OPTIND=1 | ||
while getopts 'hp:' arg; do | ||
case "$arg" in | ||
h) usage; exit 0 ;; | ||
p) pattern="$OPTARG" ;; | ||
?) fatal "unknown option" ;; | ||
esac | ||
done | ||
shift $((OPTIND - 1)) | ||
|
||
if [ ! -d ".git" ]; then | ||
fatal "no git repository found" | ||
fi | ||
|
||
last_tag=$(git tag --sort version:refname --list "$pattern" | tail -1) | ||
# There are no tags at all | ||
if [ -z "$last_tag" ]; then | ||
exit 0 | ||
fi | ||
|
||
deployed_sha1=$(git rev-parse "$last_tag") | ||
current_sha1=$(git rev-parse HEAD) | ||
|
||
# List commits behind the latest deployment tag, to see if the current commit is not behind. | ||
# Exclude the tagged commit itself so we can redeploy an already deployed, and thus tagged, | ||
# commit. | ||
# Why isn't it enough to check that "${deployed_sha1}" != "${current_sha1}"? | ||
if { git rev-list "^${deployed_sha1}" | grep -q "${current_sha1}" ; } | ||
then | ||
fatal "the current build is older than the deployed one" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters