From cd319a3939a532784204e51a1a98f0301c0b6e88 Mon Sep 17 00:00:00 2001 From: Adrian Clay Lake Date: Thu, 19 Dec 2024 13:46:20 +0100 Subject: [PATCH 1/2] Fix image name collision in Swift (#319) * fix: revision name collision bug --------- Co-authored-by: clay-lake --- oci/mock-rock/_releases.json | 14 ++-- oci/prometheus/_releases.json | 75 +++++++++++++++++++ src/image/define_image_revision.sh | 4 +- src/image/get_canonical_tags_from_swift.sh | 2 +- src/uploads/swift_lockfile_lock.sh | 2 +- src/uploads/swift_lockfile_unlock.sh | 2 +- .../activities/find_images_to_update.py | 14 ++-- 7 files changed, 94 insertions(+), 19 deletions(-) diff --git a/oci/mock-rock/_releases.json b/oci/mock-rock/_releases.json index 441aab99..25d4811f 100644 --- a/oci/mock-rock/_releases.json +++ b/oci/mock-rock/_releases.json @@ -35,31 +35,31 @@ "1.1-22.04": { "end-of-life": "2030-05-01T00:00:00Z", "candidate": { - "target": "987" + "target": "996" }, "beta": { - "target": "987" + "target": "996" }, "edge": { - "target": "987" + "target": "996" } }, "1-22.04": { "end-of-life": "2030-05-01T00:00:00Z", "candidate": { - "target": "987" + "target": "996" }, "beta": { - "target": "987" + "target": "996" }, "edge": { - "target": "987" + "target": "996" } }, "1.2-22.04": { "end-of-life": "2030-05-01T00:00:00Z", "beta": { - "target": "988" + "target": "997" }, "edge": { "target": "1.2-22.04_beta" diff --git a/oci/prometheus/_releases.json b/oci/prometheus/_releases.json index aec8fe42..f4a9ed54 100644 --- a/oci/prometheus/_releases.json +++ b/oci/prometheus/_releases.json @@ -268,5 +268,80 @@ "edge": { "target": "2.45-22.04_beta" } + }, + "2.53-24.04": { + "end-of-life": "2025-03-14T00:00:00Z", + "stable": { + "target": "111" + }, + "candidate": { + "target": "2.53-24.04_stable" + }, + "beta": { + "target": "2.53-24.04_candidate" + }, + "edge": { + "target": "2.53-24.04_beta" + } + }, + "2.53.3-24.04": { + "end-of-life": "2025-03-14T00:00:00Z", + "stable": { + "target": "111" + }, + "candidate": { + "target": "2.53.3-24.04_stable" + }, + "beta": { + "target": "2.53.3-24.04_candidate" + }, + "edge": { + "target": "2.53.3-24.04_beta" + } + }, + "2-24.04": { + "end-of-life": "2025-03-14T00:00:00Z", + "stable": { + "target": "112" + }, + "candidate": { + "target": "2-24.04_stable" + }, + "beta": { + "target": "2-24.04_candidate" + }, + "edge": { + "target": "2-24.04_beta" + } + }, + "2.55-24.04": { + "end-of-life": "2025-03-14T00:00:00Z", + "stable": { + "target": "112" + }, + "candidate": { + "target": "2.55-24.04_stable" + }, + "beta": { + "target": "2.55-24.04_candidate" + }, + "edge": { + "target": "2.55-24.04_beta" + } + }, + "2.55.1-24.04": { + "end-of-life": "2025-03-14T00:00:00Z", + "stable": { + "target": "112" + }, + "candidate": { + "target": "2.55.1-24.04_stable" + }, + "beta": { + "target": "2.55.1-24.04_candidate" + }, + "edge": { + "target": "2.55.1-24.04_beta" + } } } \ No newline at end of file diff --git a/src/image/define_image_revision.sh b/src/image/define_image_revision.sh index 00dad985..dc49f830 100755 --- a/src/image/define_image_revision.sh +++ b/src/image/define_image_revision.sh @@ -7,11 +7,11 @@ set -x # Does image already exist in Swift? # If not, then this is immediately revision number 1 -swift list $SWIFT_CONTAINER_NAME -p $IMAGE_NAME | grep $IMAGE_NAME || \ +swift list $SWIFT_CONTAINER_NAME -p $IMAGE_NAME/ | grep $IMAGE_NAME || \ (echo "revision=1" >> "$GITHUB_OUTPUT" && exit 0) # If the script gets here, then it means this image already has revisions -highest_revision=$(swift list $SWIFT_CONTAINER_NAME -p $IMAGE_NAME \ +highest_revision=$(swift list $SWIFT_CONTAINER_NAME -p $IMAGE_NAME/ \ | sort -t / -k 3 -V \ | tail -1 \ | awk -F'/' '{print $3}') diff --git a/src/image/get_canonical_tags_from_swift.sh b/src/image/get_canonical_tags_from_swift.sh index 6cad6e61..330fb499 100755 --- a/src/image/get_canonical_tags_from_swift.sh +++ b/src/image/get_canonical_tags_from_swift.sh @@ -5,7 +5,7 @@ source $(dirname $0)/../configs/swift.public.novarc set -x -canonical_tags=$(swift list $SWIFT_CONTAINER_NAME -p $IMAGE_NAME \ +canonical_tags=$(swift list $SWIFT_CONTAINER_NAME -p $IMAGE_NAME/ \ | awk -F '/' '{print $2"_"$3}' | uniq | sort | tr '\n' ',') echo "canonical-tags=${canonical_tags}" >> "$GITHUB_OUTPUT" diff --git a/src/uploads/swift_lockfile_lock.sh b/src/uploads/swift_lockfile_lock.sh index e3da5d4f..6e2f776c 100755 --- a/src/uploads/swift_lockfile_lock.sh +++ b/src/uploads/swift_lockfile_lock.sh @@ -26,7 +26,7 @@ pushd "${staging_area}" # are waiting for the lockfile to get removed, and they may exit # the while loop at the same time, getting into a race condition. while [ $TIMEOUT -gt 0 ]; do - swift list $SWIFT_CONTAINER_NAME -p $IMAGE_NAME | grep "lockfile.lock" && sleep $SLEEP_TIME || break + swift list $SWIFT_CONTAINER_NAME -p $IMAGE_NAME/ | grep "lockfile.lock" && sleep $SLEEP_TIME || break TIMEOUT=$(( $TIMEOUT - $SLEEP_TIME )) if [ $TIMEOUT -lt 1 ]; then echo "Timeout reached while waiting to write lockfile into the Swift container for ${IMAGE_NAME}." diff --git a/src/uploads/swift_lockfile_unlock.sh b/src/uploads/swift_lockfile_unlock.sh index 629c1f62..07260ebc 100755 --- a/src/uploads/swift_lockfile_unlock.sh +++ b/src/uploads/swift_lockfile_unlock.sh @@ -12,6 +12,6 @@ IMAGE_NAME=$1 # if it does not, emit an error # SWIFT_CONTAINER_NAME comes from env LOCKFILE="${IMAGE_NAME}/lockfile.lock" -swift list $SWIFT_CONTAINER_NAME -p $IMAGE_NAME | grep "$LOCKFILE" && \ +swift list $SWIFT_CONTAINER_NAME -p $IMAGE_NAME/ | grep "$LOCKFILE" && \ (swift delete $SWIFT_CONTAINER_NAME "$LOCKFILE" && echo "Lock file removed successfully.") || \ echo "Lock file does not exist." diff --git a/tools/workflow-engine/charms/temporal-worker/oci_factory/activities/find_images_to_update.py b/tools/workflow-engine/charms/temporal-worker/oci_factory/activities/find_images_to_update.py index 5e6f10dc..3b187ec0 100755 --- a/tools/workflow-engine/charms/temporal-worker/oci_factory/activities/find_images_to_update.py +++ b/tools/workflow-engine/charms/temporal-worker/oci_factory/activities/find_images_to_update.py @@ -15,15 +15,16 @@ import json import logging import os -from datetime import datetime, timezone -import requests -import swiftclient import sys import tempfile import time -import yaml import zipfile +from datetime import datetime, timezone +from fnmatch import fnmatchcase +import requests +import swiftclient +import yaml if __name__ == "__main__": logging.basicConfig(stream=sys.stderr, level=logging.INFO) @@ -103,11 +104,10 @@ def find_released_revisions(releases_json: dict) -> list: ) # This is the metadata file we want to get from Swift - build_metadata_file = "build_metadata.json" + # match objects with name ///build_metadata.json img_objs = list( filter( - lambda o: o["name"].startswith(image) - and o["name"].endswith(build_metadata_file), + lambda o: fnmatchcase(o["name"], f"{image}/*/*/build_metadata.json"), swift_oci_factory_objs, ) ) From aab644bb4b7721ca6f3f1ec0c4a3a2816996beca Mon Sep 17 00:00:00 2001 From: clay-lake Date: Thu, 19 Dec 2024 13:02:23 +0000 Subject: [PATCH 2/2] ci: automatically update oci/mock-rock/_releases.json, from https://github.com/canonical/oci-factory/actions/runs/12412970389 --- oci/mock-rock/_releases.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/oci/mock-rock/_releases.json b/oci/mock-rock/_releases.json index 25d4811f..edc455e6 100644 --- a/oci/mock-rock/_releases.json +++ b/oci/mock-rock/_releases.json @@ -35,31 +35,31 @@ "1.1-22.04": { "end-of-life": "2030-05-01T00:00:00Z", "candidate": { - "target": "996" + "target": "1002" }, "beta": { - "target": "996" + "target": "1002" }, "edge": { - "target": "996" + "target": "1002" } }, "1-22.04": { "end-of-life": "2030-05-01T00:00:00Z", "candidate": { - "target": "996" + "target": "1002" }, "beta": { - "target": "996" + "target": "1002" }, "edge": { - "target": "996" + "target": "1002" } }, "1.2-22.04": { "end-of-life": "2030-05-01T00:00:00Z", "beta": { - "target": "997" + "target": "1003" }, "edge": { "target": "1.2-22.04_beta"