Skip to content

Commit 16f8f6d

Browse files
Uttam-Mahataclaude
andcommitted
chore: add Artifact Registry + GCS cleanup policies post-deploy
- Artifact Registry: keep last 3 images, delete anything >7 days old - Cloud Build GCS bucket: 3-day object lifecycle rule Keeps storage well within free tier (0.5 GB AR, 5 GB GCS). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 0306f49 commit 16f8f6d

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

.github/workflows/backend-deploy-gcf.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,60 @@ jobs:
8282
echo "url=$URL" >> $GITHUB_OUTPUT
8383
echo "GCF deployed at: $URL"
8484
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+
85139
- name: Update Cloudflare Worker GCF_BASE secret
86140
env:
87141
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }}

0 commit comments

Comments
 (0)