mirror of
https://github.com/mag37/dockcheck.git
synced 2026-02-14 15:28:22 +01:00
moved the prune logic and made a forced prune with -k flag
This commit is contained in:
parent
eeb719296d
commit
644cbaedd1
1 changed files with 27 additions and 21 deletions
48
dockcheck.sh
48
dockcheck.sh
|
|
@ -636,6 +636,33 @@ if [[ -n "${GotUpdates:-}" ]]; then
|
|||
done
|
||||
fi
|
||||
printf "\n%bAll updates done!%b\n" "$c_green" "$c_reset"
|
||||
|
||||
# Clean up old backup image tags if -k is used
|
||||
if [[ -n "${DaysKept:-}" ]]; then
|
||||
IFS=$'\n'
|
||||
CleanupCount=0
|
||||
for backup_img in $(docker images --format "{{.Repository}} {{.Tag}}" | sed -n '/^dockcheck/p'); do
|
||||
repo_name=${backup_img% *}
|
||||
backup_tag=${backup_img#* }
|
||||
backup_date=${backup_tag%%_*}
|
||||
# UNTAGGING HERE
|
||||
if datecheck "$backup_date" "$DaysKept"; then
|
||||
[[ "$CleanupCount" == 0 ]] && echo "Removing backed up images older then $DaysKept days."
|
||||
docker rmi "${repo_name}:${backup_tag}" && ((CleanupCount+=1))
|
||||
fi
|
||||
done
|
||||
unset IFS
|
||||
if [[ "$CleanupCount" == 0 ]]; then
|
||||
printf "No backup images to remove.\n"
|
||||
else
|
||||
printf "%b%s%b backup images removed.%b\n" "$c_green" "$CleanupCount" "$c_teal" "$c_reset"
|
||||
docker image prune -f
|
||||
fi
|
||||
else
|
||||
if [[ "$AutoPrune" == false ]] && [[ "$AutoMode" == false ]]; then printf "\n"; read -rep "Would you like to prune all dangling images? y/[n]: " AutoPrune; fi
|
||||
if [[ "$AutoPrune" == true ]] || [[ "$AutoPrune" =~ [yY] ]]; then printf "\nAuto pruning.."; docker image prune -f; fi
|
||||
fi
|
||||
|
||||
else
|
||||
printf "\nNo updates installed.\n"
|
||||
fi
|
||||
|
|
@ -643,25 +670,4 @@ else
|
|||
printf "\nNo updates available.\n"
|
||||
fi
|
||||
|
||||
# Clean up old backup image tags if -k is used
|
||||
if [[ -n "${DaysKept:-}" ]]; then
|
||||
IFS=$'\n'
|
||||
CleanupCount=0
|
||||
for backup_img in $(docker images --format "{{.Repository}} {{.Tag}}" | sed -n '/^dockcheck/p'); do
|
||||
repo_name=${backup_img% *}
|
||||
backup_tag=${backup_img#* }
|
||||
backup_date=${backup_tag%%_*}
|
||||
# UNTAGGING HERE
|
||||
if datecheck "$backup_date" "$DaysKept"; then
|
||||
[[ "$CleanupCount" == 0 ]] && echo "Removing backed up images older then $DaysKept days."
|
||||
docker rmi "${repo_name}:${backup_tag}" && ((CleanupCount+=1))
|
||||
fi
|
||||
done
|
||||
[[ "$CleanupCount" == 0 ]] && printf "No backup images to remove.\n" || printf "%b%s%b backup images removed.%b\n" "$c_green" "$CleanupCount" "$c_teal" "$c_reset"
|
||||
unset IFS
|
||||
fi
|
||||
|
||||
if [[ "$AutoPrune" == false ]] && [[ "$AutoMode" == false ]]; then printf "\n"; read -rep "Would you like to prune all dangling images? y/[n]: " AutoPrune; fi
|
||||
if [[ "$AutoPrune" == true ]] || [[ "$AutoPrune" =~ [yY] ]]; then printf "\nAuto pruning.."; docker image prune -f; fi
|
||||
|
||||
exit 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue