From 5dd42b7336593ddd0f6ff32d8919d4a88894ad9a Mon Sep 17 00:00:00 2001 From: mag37 Date: Mon, 18 Nov 2024 21:01:13 +0100 Subject: [PATCH] changed to jq metadata check --- extras/errorCheck.sh | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/extras/errorCheck.sh b/extras/errorCheck.sh index 327f454..172186f 100755 --- a/extras/errorCheck.sh +++ b/extras/errorCheck.sh @@ -2,12 +2,21 @@ SearchName="$1" for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do echo "------------ $i ------------" - ContPath=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.project.working_dir" }}') - [ -z "$ContPath" ] && { "$i has no compose labels - skipping" ; continue ; } - ContConfigFile=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.project.config_files" }}') - ContName=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.service" }}') - ContEnv=$(docker inspect "$i" --format '{{index .Config.Labels "com.docker.compose.project.environment_file" }}') + ContLabels=$(docker inspect "$i" --format '{{json .Config.Labels}}') ContImage=$(docker inspect "$i" --format='{{.Config.Image}}') + ContPath=$(jq -r '."com.docker.compose.project.working_dir"' <<< "$ContLabels") + [ "$ContPath" == "null" ] && ContPath="" + [ -z "$ContPath" ] && { "$i has no compose labels - skipping" ; continue ; } + ContConfigFile=$(jq -r '."com.docker.compose.project.config_files"' <<< "$ContLabels") + [ "$ContConfigFile" == "null" ] && ContConfigFile="" + ContName=$(jq -r '."com.docker.compose.service"' <<< "$ContLabels") + [ "$ContName" == "null" ] && ContName="" + ContEnv=$(jq -r '."com.docker.compose.project.environment_file"' <<< "$ContLabels") + [ "$ContEnv" == "null" ] && ContEnv="" + ContUpdateLabel=$(jq -r '."mag37.dockcheck.update"' <<< "$ContLabels") + [ "$ContUpdateLabel" == "null" ] && ContUpdateLabel="" + ContRestartStack=$(jq -r '."mag37.dockcheck.restart-stack"' <<< "$ContLabels") + [ "$ContRestartStack" == "null" ] && ContRestartStack="" if [[ $ContConfigFile = '/'* ]] ; then ComposeFile="$ContConfigFile" @@ -20,6 +29,8 @@ for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do echo -e "Compose files:\t\t$ComposeFile" echo -e "Environment files:\t$ContEnv" echo -e "Container image:\t$ContImage" + echo -e "Update label:\t$ContUpdateLabel" + echo -e "Restart Stack label:\t$ContRestartStack" echo echo "Mounts:" docker inspect -f '{{ range .Mounts }}{{ .Source }}:{{ .Destination }}{{ printf "\n" }}{{ end }}' "$i"