mirror of
https://github.com/mag37/dockcheck.git
synced 2026-04-19 19:07:50 +00:00
Compare commits
2 Commits
9c44a5176d
...
644cbaedd1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
644cbaedd1 | ||
|
|
eeb719296d |
58
dockcheck.sh
58
dockcheck.sh
@@ -554,13 +554,9 @@ if [[ -n "${GotUpdates:-}" ]]; then
|
||||
for i in "${SelectedUpdates[@]}"; do
|
||||
((CurrentQue+=1))
|
||||
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 .}}')
|
||||
ContImage=$($jqbin -r '."Config"."Image"' <<< "$ContConfig") # OLD? Remove if replaced with ContFull
|
||||
ContImage=$($jqbin -r '."Config"."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" == "null" ]] && ContPath=""
|
||||
|
||||
@@ -598,8 +594,8 @@ if [[ -n "${GotUpdates:-}" ]]; then
|
||||
((CurrentQue+=1))
|
||||
unset CompleteConfs
|
||||
# Extract labels and metadata
|
||||
ContLabels=$(docker inspect "$i" --format '{{json .Config.Labels}}')
|
||||
ContImage=$(docker inspect "$i" --format='{{.Config.Image}}')
|
||||
ContConfig=$(docker inspect "$i" --format '{{json .}}')
|
||||
ContLabels=$($jqbin -r '."Config"."Labels"' <<< "$ContConfig")
|
||||
ContPath=$($jqbin -r '."com.docker.compose.project.working_dir"' <<< "$ContLabels")
|
||||
[[ "$ContPath" == "null" ]] && ContPath=""
|
||||
ContConfigFile=$($jqbin -r '."com.docker.compose.project.config_files"' <<< "$ContLabels")
|
||||
@@ -640,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
|
||||
@@ -647,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
|
||||
|
||||
Reference in New Issue
Block a user