Compare commits

...

2 Commits

Author SHA1 Message Date
mag37
644cbaedd1 moved the prune logic and made a forced prune with -k flag 2025-11-24 22:18:07 +01:00
mag37
eeb719296d cleaned up the config info queries 2025-11-24 22:07:25 +01:00

View File

@@ -554,13 +554,9 @@ if [[ -n "${GotUpdates:-}" ]]; then
for i in "${SelectedUpdates[@]}"; do for i in "${SelectedUpdates[@]}"; do
((CurrentQue+=1)) ((CurrentQue+=1))
printf "\n%bNow updating (%s/%s): %b%s%b\n" "$c_teal" "$CurrentQue" "$NumberofUpdates" "$c_blue" "$i" "$c_reset" printf "\n%bNow updating (%s/%s): %b%s%b\n" "$c_teal" "$CurrentQue" "$NumberofUpdates" "$c_blue" "$i" "$c_reset"
# ContLabels=$(docker inspect "$i" --format '{{json .Config.Labels}}')
# ContImage=$(docker inspect "$i" --format='{{.Config.Image}}')
# ContPath=$($jqbin -r '."com.docker.compose.project.working_dir"' <<< "$ContLabels")
ContConfig=$(docker inspect "$i" --format '{{json .}}') ContConfig=$(docker inspect "$i" --format '{{json .}}')
ContImage=$($jqbin -r '."Config"."Image"' <<< "$ContConfig") # OLD? Remove if replaced with ContFull ContImage=$($jqbin -r '."Config"."Image"' <<< "$ContConfig")
ImageId=$($jqbin -r '."Image"' <<< "$ContConfig") ImageId=$($jqbin -r '."Image"' <<< "$ContConfig")
# ContFull=$(docker image inspect "$ImageId" --format "{{index .RepoTags 0}}")
ContPath=$($jqbin -r '."Config"."Labels"."com.docker.compose.project.working_dir"' <<< "$ContConfig") ContPath=$($jqbin -r '."Config"."Labels"."com.docker.compose.project.working_dir"' <<< "$ContConfig")
[[ "$ContPath" == "null" ]] && ContPath="" [[ "$ContPath" == "null" ]] && ContPath=""
@@ -598,8 +594,8 @@ if [[ -n "${GotUpdates:-}" ]]; then
((CurrentQue+=1)) ((CurrentQue+=1))
unset CompleteConfs unset CompleteConfs
# Extract labels and metadata # Extract labels and metadata
ContLabels=$(docker inspect "$i" --format '{{json .Config.Labels}}') ContConfig=$(docker inspect "$i" --format '{{json .}}')
ContImage=$(docker inspect "$i" --format='{{.Config.Image}}') ContLabels=$($jqbin -r '."Config"."Labels"' <<< "$ContConfig")
ContPath=$($jqbin -r '."com.docker.compose.project.working_dir"' <<< "$ContLabels") ContPath=$($jqbin -r '."com.docker.compose.project.working_dir"' <<< "$ContLabels")
[[ "$ContPath" == "null" ]] && ContPath="" [[ "$ContPath" == "null" ]] && ContPath=""
ContConfigFile=$($jqbin -r '."com.docker.compose.project.config_files"' <<< "$ContLabels") ContConfigFile=$($jqbin -r '."com.docker.compose.project.config_files"' <<< "$ContLabels")
@@ -640,6 +636,33 @@ if [[ -n "${GotUpdates:-}" ]]; then
done done
fi fi
printf "\n%bAll updates done!%b\n" "$c_green" "$c_reset" 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 else
printf "\nNo updates installed.\n" printf "\nNo updates installed.\n"
fi fi
@@ -647,25 +670,4 @@ else
printf "\nNo updates available.\n" printf "\nNo updates available.\n"
fi 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 exit 0