|
82 | 82 | echo "url=$URL" >> $GITHUB_OUTPUT |
83 | 83 | echo "GCF deployed at: $URL" |
84 | 84 |
|
| 85 | + - name: Cleanup — Artifact Registry (keep last 3 images) |
| 86 | + run: | |
| 87 | + # Set cleanup policy on the GCF container repo — keep only 3 most recent, |
| 88 | + # delete anything older than 7 days. Stays well within 0.5 GB free tier. |
| 89 | + REPO="us-east1-docker.pkg.dev/rootaccessctf/gcf-artifacts" |
| 90 | +
|
| 91 | + # Wait briefly for the repo to exist after first deploy |
| 92 | + sleep 5 |
| 93 | +
|
| 94 | + gcloud artifacts repositories set-cleanup-policies gcf-artifacts \ |
| 95 | + --project=rootaccessctf \ |
| 96 | + --location=us-east1 \ |
| 97 | + --policy=<(cat <<'EOF' |
| 98 | + [ |
| 99 | + { |
| 100 | + "name": "keep-last-3", |
| 101 | + "action": {"type": "Keep"}, |
| 102 | + "mostRecentVersions": {"keepCount": 3} |
| 103 | + }, |
| 104 | + { |
| 105 | + "name": "delete-older-than-7d", |
| 106 | + "action": {"type": "Delete"}, |
| 107 | + "condition": {"olderThan": "604800s"} |
| 108 | + } |
| 109 | + ] |
| 110 | + EOF |
| 111 | + ) 2>&1 || echo "Cleanup policy skipped (repo may not exist yet on first deploy)" |
| 112 | +
|
| 113 | + - name: Cleanup — Cloud Build GCS artifacts (keep 3 days) |
| 114 | + run: | |
| 115 | + # Find the Cloud Build staging bucket and set a 3-day lifecycle rule |
| 116 | + BUCKET=$(gcloud storage buckets list \ |
| 117 | + --project=rootaccessctf \ |
| 118 | + --filter="name~gcf" \ |
| 119 | + --format="value(name)" 2>/dev/null | head -1) |
| 120 | +
|
| 121 | + if [ -n "$BUCKET" ]; then |
| 122 | + echo "Setting lifecycle on gs://$BUCKET" |
| 123 | + gcloud storage buckets update "gs://$BUCKET" \ |
| 124 | + --lifecycle-file=<(cat <<'EOF' |
| 125 | + { |
| 126 | + "rule": [ |
| 127 | + { |
| 128 | + "action": {"type": "Delete"}, |
| 129 | + "condition": {"age": 3} |
| 130 | + } |
| 131 | + ] |
| 132 | + } |
| 133 | + EOF |
| 134 | + ) |
| 135 | + else |
| 136 | + echo "No GCF build bucket found yet — skipping." |
| 137 | + fi |
| 138 | +
|
85 | 139 | - name: Update Cloudflare Worker GCF_BASE secret |
86 | 140 | env: |
87 | 141 | CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }} |
|
0 commit comments