ci: cache: Enforce tag length limit

Container tags can be a maximum of 128 characters long
so calculate the length of the arch suffix and then restrict
the tag to this length subtracted from 128

Signed-off-by: stevenhorsman <steven@uk.ibm.com>
This commit is contained in:
stevenhorsman 2024-05-21 18:03:45 +01:00
parent d6afd77eae
commit db4818fe1d

View File

@ -1148,9 +1148,11 @@ handle_build() {
echo "Pushing ${build_target} with tags: ${tags[*]}"
for tag in "${tags[@]}"; do
# tags can only contain lowercase and uppercase letters, digits, underscores, periods, and hyphens, so
# filter out non-printable characers and then replace invalid printable characters with underscode
tag=("$(echo ${tag} | tr -dc '[:print:]' | tr -c '[a-zA-Z0-9\_\.\-]' _)-$(uname -m)")
# tags can only contain lowercase and uppercase letters, digits, underscores, periods, and hyphens
# and limited to 128 characters, so filter out non-printable characers, replace invalid printable
# characters with underscode and trim down to leave enough space for the arch suffix
tag_length_limit=$(expr 128 - $(echo "-$(uname -m)" | wc -c))
tag=("$(echo ${tag} | tr -dc '[:print:]' | tr -c '[a-zA-Z0-9\_\.\-]' _ | head -c ${tag_length_limit})-$(uname -m)")
case ${build_target} in
kernel-nvidia-gpu)
sudo oras push \