Skip to content

Commit

Permalink
fix: enhance docker.sh facilities with release promotion related func…
Browse files Browse the repository at this point in the history
…tions

Signed-off-by: Kevin O'Donnell <kevin@blockchaintp.com>
  • Loading branch information
scealiontach committed Jan 19, 2021
1 parent b2a4f03 commit fa97d1f
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions bash/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,76 @@ function docker::cp() {
return 1
fi
}

function docker::login() {
local docker_user=${1:?}
local docker_pass=${2:?}
local registry=${3}

echo "$docker_pass" | docker::cmd login -u "$docker_user" --password-stdin \
"$registry"
}

function docker::registrycmd {
local url=${1:?}
local registry=${2:?}
local basic_token
basic_token=$(jq -r ".auths.\"$registry\".auth" ~/.docker/config.json)
$(commands::use curl) -s -H "Authorization: Basic $basic_token" "https://$registry/v2/$url"
}

function docker::list_repositories {
local registry=${1:?}
docker::registrycmd _catalog "$registry" | jq -r '.repositories[]' |
sort
}

function docker::list_tags {
local repository=${1:?}
local registry=${2?}
docker::registrycmd "$repository/tags/list" "$registry" | jq -r '.tags[]' |
sort -V
}

function docker::list_versions {
local repository=${1:?}
local registry=${2?}
docker::list_tags "$repository" "$registry" |
grep -E 'BTP[0-9]+.[0-9]+.[0-9]+(rc[0-9]+)?(-[0-9]+-[a-z0-9]{8,10})?(-[0-9]+.[0-9]+.[0-9]+(p[0-9]+(-[0-9]+-[a-z0-9]{8,10})?)?)?' |
sort -V
}

function docker::list_official_versions {
local repository=${1:?}
local registry=${2?}
docker::list_tags "$repository" "$registry" | grep -E \
'^BTP[0-9]+.[0-9]+.[0-9]+(rc[0-9]+)?(-[0-9]+.[0-9]+.[0-9]+(p[0-9]+)?)?$' |
sort -V
}

function docker::promote_latest() {
local organization=${1:?}
local registry=${2?}
local target_tag=${3:?}
shift 3

for repo in $(docker::list_repositories "$registry" |
grep "^${organization}/"); do
local src_version
src_version=$(docker::list_official_versions "$repo" "$registry" | grep "^${target_tag}-" | sort -V |
tail -1)
if [ -z "$src_version" ]; then
log::warn "$repo has no official version in $target_tag"
continue
fi
docker::cp "$registry/$repo:$src_version" "$registry/$repo:$target_tag"
for extra_registry in "$@"; do
docker::tag "$registry/$repo:$src_version" "$extra_registry/$repo:$src_version"
docker::tag "$registry/$repo:$target_tag" "$extra_registry/$repo:$target_tag"
done
for extra_registry in "$@"; do
docker::push "$extra_registry/$repo:$src_version"0
docker::push "$extra_registry/$repo:$target_tag"
done
done
}

0 comments on commit fa97d1f

Please sign in to comment.