Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
Allow deploying latest build again (#114)
Browse files Browse the repository at this point in the history
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
cansjt authored Mar 28, 2022
1 parent 5e84245 commit be0a21c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
53 changes: 53 additions & 0 deletions orbs/helm-runner/deployable
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
8 changes: 7 additions & 1 deletion orbs/helm/deployable
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,19 @@ if [ ! -d ".git" ]; then
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)

if [ "$(git rev-list $deployed_sha1 | grep $current_sha1)" ]; then
# 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

0 comments on commit be0a21c

Please sign in to comment.