Skip to content

Commit 6205564

Browse files
authored
UnixPB: Add additional docker housekeeping (#4122)
* UnixPB: Add additional docker housekeeping * GHA: Fix Ansible Linter By Pinning Python
1 parent be0044d commit 6205564

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

.github/workflows/linter.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ on:
55
paths:
66
- ansible/**
77
- .ansible-lint
8-
branches:
8+
branches:
99
- master
1010
push:
1111
paths:
1212
- ansible/**
13-
branches:
13+
branches:
1414
- master
1515

1616
permissions:
@@ -44,7 +44,7 @@ jobs:
4444
- name: Set up Python 3.x
4545
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
4646
with:
47-
python-version: '3.x'
47+
python-version: '3.13' # Pin To 3.13 until ansible 2.20 is supported
4848

4949
- name: Install dependencies
5050
run: pip install ansible ansible-lint

ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/housekeeping/files/housekeep_docker.sh

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ check_until_filter_support() {
127127
SIX_MONTHS=4320h
128128
TWO_WEEKS=336h
129129
ONE_WEEK=168h
130+
FIVE_DAYS=120h
131+
THREE_DAYS=72h
130132

131133
# Define Macros For Temp files
132134
IMAGES=$(mktemp)
@@ -234,7 +236,40 @@ fi
234236
echo
235237

236238
##########################################################
237-
# 7. Other prune operations (skip image prune if exclusions present)
239+
# 7. Remove images where TAG is <none>
240+
##########################################################
241+
echo "Scanning for images where TAG is <none> and older than 5 days ..."
242+
243+
if [ "${USE_UNTIL_FILTER:-false}" = true ]; then
244+
_imglist=$($CLI images --filter "until=$FIVE_DAYS" --format '{{.Repository}} {{.Tag}} {{.ID}}')
245+
else
246+
echo "Skipping age filter for <none>-tag images (unsupported 'until' filter)."
247+
_imglist=$($CLI images --format '{{.Repository}} {{.Tag}} {{.ID}}')
248+
fi
249+
250+
none_tag_images=$(printf '%s\n' "$_imglist" | awk '$2=="<none>" {print $3}' | sort -u)
251+
252+
if [ -n "$none_tag_images" ]; then
253+
count=$(printf '%s\n' "$none_tag_images" | wc -l | tr -d ' ')
254+
echo "Found $count image(s) with <none> tag older than 5 days."
255+
256+
if [ "$ACTION" = "delete" ]; then
257+
echo "Removing images with <none> tag..."
258+
# shellcheck disable=SC2086
259+
run rmi -f $none_tag_images
260+
else
261+
echo "CHECK mode: would remove images with <none> tag."
262+
for iid in $none_tag_images; do
263+
printf 'Would run: %s rmi -f %s %s\n' "$CLI" "$iid" "$EXTRA_ARGS"
264+
done
265+
fi
266+
else
267+
echo "No <none> tag images older than 5 days found."
268+
fi
269+
echo
270+
271+
##########################################################
272+
# 8. Other prune operations (skip image prune if exclusions present)
238273
##########################################################
239274
echo "Pruning builder cache older than $TWO_WEEKS ..."
240275
if [ "$USE_UNTIL_FILTER" = true ]; then
@@ -263,6 +298,6 @@ run network prune -f
263298
echo
264299

265300
##########################################################
266-
# 8. Summary
301+
# 9. Summary
267302
##########################################################
268303
echo "Housekeeping finished in $ACTION mode."

0 commit comments

Comments
 (0)