@@ -30,31 +30,57 @@ delete_old_tags() {
30
30
# Function to start garbage collection
31
31
start_garbage_collection () {
32
32
echo " Starting garbage collection..."
33
- doctl registry garbage-collection start --include-untagged-manifests --force
33
+ if doctl registry garbage-collection start --include-untagged-manifests --force; then
34
+ echo " Garbage collection started successfully."
35
+ return 0
36
+ else
37
+ echo " Failed to start garbage collection."
38
+ return 1
39
+ fi
34
40
}
35
41
36
42
# Function to check garbage collection status
37
43
check_garbage_collection_status () {
38
44
local status
39
- status=$( doctl registry garbage-collection get-active --format Status --no-header)
40
- echo " $status "
45
+ status=$( doctl registry garbage-collection get-active --format Status --no-header 2> /dev/null) || true
46
+ if [ -z " $status " ]; then
47
+ echo " no_active_gc"
48
+ else
49
+ echo " $status "
50
+ fi
41
51
}
42
52
43
53
# Function to wait for garbage collection to complete
44
54
wait_for_garbage_collection () {
45
- echo " Waiting for garbage collection to complete..."
46
- while true ; do
55
+ echo " Checking garbage collection status..."
56
+ local max_attempts=30
57
+ local attempt=1
58
+ while [ $attempt -le $max_attempts ]; do
47
59
local status
48
60
status=$( check_garbage_collection_status)
49
- if [ " $status " = " succeeded" ]; then
50
- echo " Garbage collection completed successfully."
51
- break
52
- elif [ " $status " = " failed" ]; then
53
- echo " Garbage collection failed."
54
- exit 1
55
- fi
56
- echo " Garbage collection is still in progress. Waiting..."
57
- sleep 60 # Wait for 60 seconds before checking again
61
+ case " $status " in
62
+ " succeeded" )
63
+ echo " Garbage collection completed successfully."
64
+ return 0
65
+ ;;
66
+ " failed" )
67
+ echo " Garbage collection failed."
68
+ return 1
69
+ ;;
70
+ " no_active_gc" )
71
+ echo " No active garbage collection found. It may have completed quickly."
72
+ return 0
73
+ ;;
74
+ * )
75
+ if [ $attempt -eq $max_attempts ]; then
76
+ echo " Garbage collection is still in progress after maximum attempts. Please check manually."
77
+ return 1
78
+ fi
79
+ echo " Garbage collection is still in progress. Waiting... (Attempt $attempt /$max_attempts )"
80
+ sleep 30 # Wait for 30 seconds before checking again
81
+ ;;
82
+ esac
83
+ attempt=$(( attempt + 1 ))
58
84
done
59
85
}
60
86
@@ -73,9 +99,11 @@ while IFS= read -r repo; do
73
99
done <<< " $REPOS"
74
100
75
101
# Start garbage collection
76
- start_garbage_collection
77
-
78
- # Wait for garbage collection to complete
79
- wait_for_garbage_collection
102
+ if start_garbage_collection; then
103
+ # Wait for garbage collection to complete
104
+ wait_for_garbage_collection
105
+ else
106
+ echo " Skipping garbage collection wait due to start failure."
107
+ fi
80
108
81
- echo " Cleanup and garbage collection completed."
109
+ echo " Cleanup process completed."
0 commit comments