-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #376 from neo4j/pipeline-improvements
Pipeline improvements
- Loading branch information
Showing
4 changed files
with
155 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This script cleans up GCP resources that might be left over from previous test runs | ||
|
||
set -o pipefail -o errtrace -o errexit -o nounset | ||
shopt -s inherit_errexit | ||
[[ -n "${TRACE:-}" ]] && set -o xtrace | ||
|
||
# Required env vars | ||
CLOUDSDK_COMPUTE_ZONE="${CLOUDSDK_COMPUTE_ZONE:?CLOUDSDK_COMPUTE_ZONE is required}" | ||
RESOURCE_PREFIX="${RESOURCE_PREFIX:-ghactions}" | ||
|
||
# Clean up any existing clusters | ||
echo "Cleaning up any existing clusters..." | ||
CLUSTERS=$(gcloud container clusters list --format="get(name)" --filter="name ~ ^${RESOURCE_PREFIX}-.*") | ||
if [ -n "$CLUSTERS" ]; then | ||
while read -r cluster; do | ||
if [ -n "$cluster" ]; then | ||
echo "Deleting cluster: $cluster" | ||
gcloud container clusters delete "$cluster" --zone="${CLOUDSDK_COMPUTE_ZONE}" --quiet || true | ||
fi | ||
done <<< "$CLUSTERS" | ||
fi | ||
|
||
# Clean up any orphaned persistent disks | ||
echo "Cleaning up orphaned persistent disks..." | ||
DISKS=$(gcloud compute disks list \ | ||
--filter="zone=${CLOUDSDK_COMPUTE_ZONE} AND (name:${RESOURCE_PREFIX}-* OR name:neo4j-data-disk-${RESOURCE_PREFIX}-*)" \ | ||
--format="get(name)") | ||
if [ -n "$DISKS" ]; then | ||
while read -r disk; do | ||
if [ -n "$disk" ]; then | ||
echo "Deleting disk: $disk" | ||
gcloud compute disks delete "$disk" --zone="${CLOUDSDK_COMPUTE_ZONE}" --quiet || true | ||
fi | ||
done <<< "$DISKS" | ||
fi | ||
|
||
# Clean up test-related container images older than 24 hours | ||
if [[ -n "${ARTIFACT_REGISTRY_REPO_NAME:-}" ]]; then | ||
echo "Cleaning up old test-related container images..." | ||
CUTOFF_TIME=$(date -u -d "24 hours ago" +"%Y-%m-%dT%H:%M:%SZ") | ||
|
||
# Define the test-related image patterns | ||
TEST_IMAGE_PATTERNS=( | ||
"reverseproxy" | ||
"neo4j-operations" | ||
"neo4j-admin" | ||
) | ||
|
||
for pattern in "${TEST_IMAGE_PATTERNS[@]}"; do | ||
|
||
IMAGES=$(gcloud container images list --repository="${ARTIFACT_REGISTRY_REPO_NAME}" \ | ||
--format="get(name)" --filter="name ~ .*${pattern}.*" 2>/dev/null || true) | ||
|
||
if [ -n "$IMAGES" ]; then | ||
while read -r image; do | ||
if [ -n "$image" ]; then | ||
OLD_TAGS=$(gcloud container images list-tags "$image" \ | ||
--filter="timestamp.datetime < '${CUTOFF_TIME}'" \ | ||
--format="get(digest)" 2>/dev/null || true) | ||
|
||
while read -r digest; do | ||
if [ -n "$digest" ]; then | ||
echo "Deleting old image: $image@$digest" | ||
gcloud container images delete --quiet "${image}@${digest}" 2>/dev/null || true | ||
fi | ||
done <<< "$OLD_TAGS" | ||
fi | ||
done <<< "$IMAGES" | ||
fi | ||
done | ||
else | ||
echo "Skipping image cleanup - ARTIFACT_REGISTRY_REPO_NAME not set" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.