Skip to content

Commit

Permalink
[buildkite] Delete all but most recent 50 PR staging subdirs (elastic…
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen authored and mgadewoll committed May 3, 2024
1 parent b8813fb commit de42633
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions .buildkite/scripts/pipelines/pipeline_prune_staging_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ BUCKET=${GPROJECT}-${EUI_DOCS_PROJECT}
# https://cloud.google.com/storage/docs/gsutil/commands/ls
ls_options=(
-d # only list directories
-l # Print additional details about the subdir
-l # include additional details about the subdir, notably the date as a second field
)
echo "Listing all PR staging links"
gsutil ls "${ls_options[@]}" "gs://${BUCKET}/pr_*" # | sort -k 2 # sort by the 2nd field returned by -l which is the 'created by' timestamp

# https://cloud.google.com/storage/docs/gsutil/commands/rm
rm_options=(
-r # recursive, delete everything inside subdir
-m # enables multi-threading for large numbers of objects
echo "Getting all but the most recent 50 PR staging links..."
list=$(gsutil ls "${ls_options[@]}" "gs://${BUCKET}/pr_*" \
| sort -k 2 `# sort by the 2nd field returned by -l which is a timestamp` \
| head -n -50 `# remove the last 50 items, so basically keep the latest 50 staging docs` \
)
# gsutil rm "${rm_options[@]}" "gs://${BUCKET}/pr_TODO"
while IFS= read -r line || [[ -n $line ]]; do
url="$(echo -e "${line}" | tr -d '[:space:]')" # trim the leading whitespaces
url=${url%/} # trim the trailing slash
echo "Deleting $url"
# https://cloud.google.com/storage/docs/gsutil/commands/rm
gsutil -m rm -r "$url"
done < <(printf '%s' "$list")

0 comments on commit de42633

Please sign in to comment.