Skip to content

Commit bcd44fa

Browse files
committed
feat(devtool): pull newest test artifacts
Instead of using fixed artifact path for a current FC version pull newest artifacts from S3. This way we can update them independently while keeping old versions around. Unfortunately there is no simple way to query newest added directory in S3, so do the next best thing of looking through all files in all directories and determining the `newest` directory be the `LastModified` status of files inside. Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
1 parent 8029b8a commit bcd44fa

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

tools/devtool

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,28 @@ TARGET_PREFIX="$(uname -m)-unknown-linux-"
133133
# Container path to directory where we store built CI artifacts.
134134
CTR_CI_ARTIFACTS_PATH="${CTR_FC_ROOT_DIR}/resources/$(uname -m)"
135135

136+
DEFAULT_ARTIFACTS_S3_BUCKET=s3://spec.ccfc.min/firecracker-ci
137+
138+
# Query default S3 bucket with artifacts and return the most recient path
139+
get_newest_s3_artifacts() {
140+
local bucket="spec.ccfc.min"
141+
local base_prefix="firecracker-ci/"
142+
143+
# Query all files in the `firecracker-ci` directory, sort them by the `LastModified` date
144+
# and return the first one.
145+
# Reasons for such complex operation:
146+
# - since S3 does not store `LastModified` info for directories, the next best approach of
147+
# determining the `newest` directory is to check which directory contains the most recently
148+
# modified file
149+
# - also awscli is paginated, so the command bellow can return multiple values, one for each page.
150+
# The very first entry though should be the correct one
151+
# - the end of the command filters out directory out of the output
152+
local newest_dir=$(aws s3api list-objects-v2 --bucket "$bucket" --prefix "$base_prefix" --no-sign-request --query 'reverse(sort_by(Contents, &LastModified))[0].Key' --output text | head -1 | sed "s|^$base_prefix||" | cut -d'/' -f1)
153+
154+
echo "$DEFAULT_ARTIFACTS_S3_BUCKET/$newest_dir"
155+
}
156+
157+
136158
# Check if Docker is available and exit if it's not.
137159
# Upon returning from this call, the caller can be certain Docker is available.
138160
#
@@ -571,9 +593,8 @@ ensure_ci_artifacts() {
571593
fi
572594

573595
# Fetch all the artifacts so they are local
574-
say "Fetching CI artifacts from S3"
575-
FC_VERSION=$(cmd_sh "cd src/firecracker/src; cargo pkgid | cut -d# -f2 | cut -d. -f1-2")
576-
S3_URL=s3://spec.ccfc.min/firecracker-ci/v$FC_VERSION/$(uname -m)
596+
S3_URL=$(get_newest_s3_artifacts)/$(uname -m)
597+
say "Fetching CI artifacts from S3: " $S3_URL
577598
ARTIFACTS=$MICROVM_IMAGES_DIR/$(uname -m)
578599
if [ ! -d "$ARTIFACTS" ]; then
579600
mkdir -pv $ARTIFACTS

0 commit comments

Comments
 (0)