Skip to content

Commit

Permalink
fix: revision name collision bug
Browse files Browse the repository at this point in the history
  • Loading branch information
clay-lake committed Dec 18, 2024
1 parent 3400ce6 commit b2ab433
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/image/define_image_revision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand Down
2 changes: 1 addition & 1 deletion src/image/get_canonical_tags_from_swift.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/uploads/swift_lockfile_lock.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}."
Expand Down
2 changes: 1 addition & 1 deletion src/uploads/swift_lockfile_unlock.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 <IMAGE_NAME>/<TRACK>/<REVISION>/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,
)
)
Expand Down

0 comments on commit b2ab433

Please sign in to comment.