File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change 9999function cleanup_container {
100100 # Delete the container locally and remotely
101101 docker rmi $CONTAINER :$TAG || echo " Built container image was not removed. Possibly, it was not not saved locally."
102- for image in $( docker images --format ' {{.Repository}}:{{.Tag}}' | grep $PREBUILD_SDK_CONTAINER_REGISTRY_PATH )
102+
103+ for image in $( docker images --format ' {{.Repository}}:{{.Tag}}' | grep $PREBUILD_SDK_CONTAINER_REGISTRY_PATH | grep -E " (beam_python_prebuilt_sdk|$TAG )" )
103104 do
104105 echo " Deleting Docker image: $image "
105106 docker rmi $image || echo " Failed to remove prebuilt sdk container image"
106107 image_tag=" ${image##*: } "
108+
107109 digest=$( gcloud container images list-tags $PREBUILD_SDK_CONTAINER_REGISTRY_PATH /beam_python_prebuilt_sdk --filter=" tags=$image_tag " --format=" get(digest)" )
108- echo " Deleting from GCloud an image with digest: $digest "
109- gcloud container images delete $PREBUILD_SDK_CONTAINER_REGISTRY_PATH /beam_python_prebuilt_sdk@$digest --force-delete-tags --quiet || echo " Failed to remove prebuilt sdk container image"
110+
111+ echo " Looking for digest for tag '$image_tag ', found: '$digest '"
112+
113+ if [[ -n " $digest " && " $digest " =~ ^sha256:[a-f0-9]{64}$ ]]; then
114+ echo " Deleting from GCloud an image with digest: $digest "
115+ gcloud container images delete $PREBUILD_SDK_CONTAINER_REGISTRY_PATH /beam_python_prebuilt_sdk@$digest --force-delete-tags --quiet || echo " Failed to remove prebuilt sdk container image"
116+ else
117+ echo " Skipping deletion of image with invalid or empty digest: '$digest '"
118+ fi
110119 done
120+
111121 # Note: we don't delete the multi-arch containers here because this command only deletes the manifest list with the tag,
112122 # the associated container images can't be deleted because they are not tagged. However, multi-arch containers that are
113123 # older than 6 weeks old are deleted by stale_dataflow_prebuilt_image_cleaner.sh that runs daily.
You can’t perform that action at this time.
0 commit comments