-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ci): add lock for Swift slot preemption
- Loading branch information
1 parent
9eccbaa
commit 3f3cf06
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash -e | ||
|
||
# Source Swift config | ||
source $(dirname $0)/../configs/swift.public.novarc | ||
|
||
set -x | ||
|
||
IMAGE_NAME=$1 | ||
# Timeout and sleep time in seconds | ||
TIMEOUT=${2:-300} | ||
SLEEP_TIME=5 | ||
|
||
staging_area=$(mktemp -d) | ||
|
||
mkdir -p "${staging_area}/${IMAGE_NAME}" | ||
|
||
touch "${staging_area}/${IMAGE_NAME}/lockfile.lock" | ||
|
||
pushd "${staging_area}" | ||
|
||
# check if the ${IMAGE_NAME}/lockfile.lock exists in the swift container | ||
# if it does, wait until the timeout is reached and emit an error | ||
# if it does not, upload the lockfile.lock to the swift container | ||
# and exit | ||
while [ $TIMEOUT -gt 0 ]; do | ||
swift list $SWIFT_CONTAINER_NAME -p $IMAGE_NAME | grep "lockfile.lock" && sleep $SLEEP_TIME || break | ||
TIMEOUT=$(( $TIMEOUT - $SLEEP_TIME )) | ||
if [ $TIMEOUT -eq 0 ]; then | ||
echo "Timeout reached while waiting for lockfile.lock to be removed from the swift container" | ||
exit 1 | ||
fi | ||
done | ||
|
||
# SWIFT_CONTAINER_NAME comes from env | ||
swift upload "$SWIFT_CONTAINER_NAME" "${IMAGE_NAME}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash -e | ||
|
||
# Source Swift config | ||
source $(dirname $0)/../configs/swift.public.novarc | ||
|
||
set -x | ||
|
||
IMAGE_NAME=$1 | ||
|
||
# check if the ${IMAGE_NAME}/lockfile.lock exists in the swift container | ||
# if it does, remove it | ||
# 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 delete $SWIFT_CONTAINER_NAME "$LOCKFILE" && echo "Lock file removed successfully.") || \ | ||
echo "Lock file does not exist." |