Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/cleanup-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ on:
description: "🗑️ Clean up AWS AMIs (deregister + delete snapshots)"
default: true
type: boolean
cleanup_gce:
description: "🗑️ Clean up GCE images and GCS tarballs"
default: false
type: boolean
gcp_project:
description: "GCP project ID for GCE cleanup"
type: string
default: "pelagic-logic-394811"
gcs_bucket:
description: "GCS bucket for GCE tarball cleanup"
type: string
default: "ubicloud-gce-images"
aws_ami_regions:
description: "AWS regions to clean up AMIs from (comma-separated)"
type: string
Expand Down Expand Up @@ -286,6 +298,63 @@ jobs:
fi
done

- name: Authenticate to GCP
if: ${{ inputs.cleanup_gce }}
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


- name: Set up Cloud SDK
if: ${{ inputs.cleanup_gce }}
uses: google-github-actions/setup-gcloud@v2

- name: Cleanup GCE images
if: ${{ inputs.cleanup_gce }}
run: |
project="${{ inputs.gcp_project }}"
bucket="${{ inputs.gcs_bucket }}"

echo "### GCE Cleanup" >> $GITHUB_STEP_SUMMARY

cleanup_gce_image() {
local image_name=$1
local arch=$2

if gcloud compute images describe "${image_name}" --project="${project}" &>/dev/null; then
if [ "${{ inputs.dry_run }}" = "true" ]; then
echo "[DRY RUN] Would delete GCE image: ${image_name}"
echo "- [DRY RUN] Would delete ${arch} image: ${image_name}" >> $GITHUB_STEP_SUMMARY
else
gcloud compute images delete "${image_name}" --project="${project}" --quiet
echo "Deleted GCE image: ${image_name}"
echo "- Deleted ${arch} image: ${image_name}" >> $GITHUB_STEP_SUMMARY
fi
else
echo "GCE image not found: ${image_name}"
echo "- ${arch} image not found: ${image_name}" >> $GITHUB_STEP_SUMMARY
fi

local tar_file="${image_name}.tar.gz"
if gcloud storage ls "gs://${bucket}/${tar_file}" &>/dev/null; then
if [ "${{ inputs.dry_run }}" = "true" ]; then
echo "[DRY RUN] Would delete tarball: gs://${bucket}/${tar_file}"
echo "- [DRY RUN] Would delete ${arch} tarball: ${tar_file}" >> $GITHUB_STEP_SUMMARY
else
gcloud storage rm "gs://${bucket}/${tar_file}"
echo "Deleted tarball: gs://${bucket}/${tar_file}"
echo "- Deleted ${arch} tarball: ${tar_file}" >> $GITHUB_STEP_SUMMARY
fi
fi
}

if [ "${{ inputs.architecture }}" = "x64" ] || [ "${{ inputs.architecture }}" = "both" ]; then
cleanup_gce_image "${{ steps.set_image_names.outputs.x64_image_name }}" "x64"
fi

if [ "${{ inputs.architecture }}" = "arm64" ] || [ "${{ inputs.architecture }}" = "both" ]; then
cleanup_gce_image "${{ steps.set_image_names.outputs.arm64_image_name }}" "arm64"
fi

- name: Summary
run: |
echo "" >> $GITHUB_STEP_SUMMARY
Expand Down
Loading