Skip to content

Commit

Permalink
Merge pull request containers#294 from cevich/replace_clobbered_ec2_i…
Browse files Browse the repository at this point in the history
…mport_image

Replace clobbered ec2 import image
  • Loading branch information
cevich authored Aug 16, 2023
2 parents dcc416c + ec0c7b6 commit 0ac55b6
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ test_imgts_task: &imgts
fedora-aws-i${IMPORT_IMG_SFX}
fedora-aws-b${IMG_SFX}
fedora-aws-c${IMG_SFX}
fedora-aws-arm64-i${IMG_SFX}
fedora-aws-arm64-i${IMPORT_IMG_SFX}
fedora-aws-arm64-b${IMG_SFX}
fedora-podman-aws-arm64-c${IMG_SFX}
fedora-netavark-aws-arm64-c${IMG_SFX}
Expand Down
2 changes: 1 addition & 1 deletion IMG_SFX
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20230815t160849z-f38f37d13
20230816t191118z-f38f37d13
2 changes: 1 addition & 1 deletion IMPORT_IMG_SFX
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20230613t155237z-f38f37d13
20230816t191121z-f38f37d13
4 changes: 4 additions & 0 deletions cache_images/build-push_packaging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ INSTALL_PACKAGES=(\
git
jq
podman
python3-pip
qemu-user-static
skopeo
)
Expand All @@ -45,3 +46,6 @@ cd $REPO_DIRPATH/build-push
set -x
# Do not auto-update to allow testing inside a PR
$SUDO env BUILDPUSHAUTOUPDATED=1 bash ./.install.sh

# Install wait-for-copr
$SUDO pip3 install git+https://github.com/packit/wait-for-copr.git@main
18 changes: 17 additions & 1 deletion imgobsolete/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set -eo pipefail
# shellcheck source=imgts/lib_entrypoint.sh
source /usr/local/bin/lib_entrypoint.sh

req_env_vars GCPJSON GCPNAME GCPPROJECT AWSINI
req_env_vars GCPJSON GCPNAME GCPPROJECT AWSINI IMG_SFX IMPORT_IMG_SFX

gcloud_init

Expand Down Expand Up @@ -54,6 +54,14 @@ $GCLOUD compute images list --format="$FORMAT" --filter="$FILTER" | \
continue
fi

# Any image matching the currently in-use IMG_SFX must always be preserved
# Value is defined in cirrus.yml
# shellcheck disable=SC2154
if [[ "$name" =~ $IMG_SFX ]]; then
msg "Retaining current (latest) image $name | $labels"
continue
fi

# No label was set
if [[ -z "$last_used" ]]
then # image lacks any tracking labels
Expand Down Expand Up @@ -151,6 +159,14 @@ for (( i=nr_amis ; i ; i-- )); do
continue
fi

# Any image matching the currently in-use IMG_SFX or IMPORT_IMG_SFX
# must always be preserved. Values are defined in cirrus.yml
# shellcheck disable=SC2154
if [[ "$name" =~ $IMG_SFX ]] || [[ "$name" =~ $IMPORT_IMG_SFX ]]; then
msg "Retaining current (latest) image $name | $tags"
continue
fi

# For IAM (security) policy, an "automation" tag is always required
if [[ -z "$automation" ]]
then
Expand Down
24 changes: 23 additions & 1 deletion imgprune/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set -e
# shellcheck source=imgts/lib_entrypoint.sh
source /usr/local/bin/lib_entrypoint.sh

req_env_vars GCPJSON GCPNAME GCPPROJECT AWSINI
req_env_vars GCPJSON GCPNAME GCPPROJECT AWSINI IMG_SFX IMPORT_IMG_SFX

gcloud_init

Expand Down Expand Up @@ -44,6 +44,15 @@ $GCLOUD compute images list --show-deprecated \
die 1 "Refusing to delete a deprecated image labeled permanent=true. Please use gcloud utility to set image active, then research the cause of deprecation."
[[ "$dep_state" == "OBSOLETE" ]] || \
die 1 "Unexpected depreciation-state encountered for $name: $dep_state; labels: $labels"

# Any image matching the currently in-use IMG_SFX must always be preserved.
# Values are defined in cirrus.yml
# shellcheck disable=SC2154
if [[ "$name" =~ $IMG_SFX ]] || [[ "$name" =~ $IMPORT_IMG_SFX ]]; then
msg " Skipping current (latest) image $name"
continue
fi

reason="Obsolete as of $del_date; labels: $labels"
echo "GCP $name $reason" >> $TODELETE
done
Expand Down Expand Up @@ -77,6 +86,19 @@ for (( i=nr_amis ; i ; i-- )); do
continue
fi

unset name
if ! name=$(get_tag_value "Name" "$ami"); then
warn 0 " EC2 AMI ID '$ami_id' is missing a 'Name' tag"
fi

# Any image matching the currently in-use IMG_SFX or IMPORT_IMG_SFX
# must always be preserved.
if [[ "$name" =~ $IMG_SFX ]] || [[ "$name" =~ $IMPORT_IMG_SFX ]]; then
warn 0 " Retaining current (latest) image $name id $ami_id"
$AWS ec2 disable-image-deprecation --image-id "$ami_id" > /dev/null
continue
fi

if [[ $(echo -e "$ABOUTNOW\n$dep_ymd" | sort | tail -1) == "$ABOUTNOW" ]]; then
reason="Obsolete as of '$dep_ymd'; snap=$snap"
echo "EC2 $ami_id $reason" >> $TODELETE
Expand Down

0 comments on commit 0ac55b6

Please sign in to comment.