From 8c7597f546b5dd313158253fe673e2cb5b52a182 Mon Sep 17 00:00:00 2001 From: Casper Date: Fri, 12 Jun 2020 01:33:30 +0200 Subject: [PATCH 1/3] Improve container/image name detection Problem: `setup.sh` fails, if more than one container uses `CMD ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]` Current container/image name detection: List all containers, grep for "supervisor". New approach: List container, with label `org.label-schema.name="docker-mailserver"` --- setup.sh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/setup.sh b/setup.sh index 029813ec..6913e86e 100755 --- a/setup.sh +++ b/setup.sh @@ -25,13 +25,10 @@ if [ -z "$CRI" ]; then fi fi -INFO=$($CRI ps \ - --no-trunc \ - --format="{{.Image}} {{.Names}} {{.Command}}" | \ - grep "supervisord -c /etc/supervisor/supervisord.conf") +INFO=$($CRI ps --no-trunc --format "{{.Image}};{{.Names}}" --filter label=org.label-schema.name="docker-mailserver") -IMAGE_NAME=$(echo $INFO | awk '{print $1}') -CONTAINER_NAME=$(echo $INFO | awk '{print $2}') +IMAGE_NAME=${INFO%;*} +CONTAINER_NAME=${INFO#*;} DEFAULT_CONFIG_PATH="$(pwd)/config" USE_CONTAINER=false From 29406ff34d988dc304cfdaa5474eb7bd70e19e0a Mon Sep 17 00:00:00 2001 From: Casper Date: Fri, 12 Jun 2020 18:52:32 +0200 Subject: [PATCH 2/3] Return only one result, if there are multiple matches Among other things, this is the case, when running tests with multiple containers. --- setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index 6913e86e..1dfd612d 100755 --- a/setup.sh +++ b/setup.sh @@ -25,7 +25,7 @@ if [ -z "$CRI" ]; then fi fi -INFO=$($CRI ps --no-trunc --format "{{.Image}};{{.Names}}" --filter label=org.label-schema.name="docker-mailserver") +INFO=$($CRI ps --no-trunc --format "{{.Image}};{{.Names}}" --filter label=org.label-schema.name="docker-mailserver" | tail -1) IMAGE_NAME=${INFO%;*} CONTAINER_NAME=${INFO#*;} From e95bd156a57c647ca88d2c08e357b2b3f4aa97d9 Mon Sep 17 00:00:00 2001 From: Casper Date: Sun, 14 Jun 2020 04:34:25 +0200 Subject: [PATCH 3/3] Multi-line format --- setup.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index 1dfd612d..ac2d7e29 100755 --- a/setup.sh +++ b/setup.sh @@ -25,7 +25,11 @@ if [ -z "$CRI" ]; then fi fi -INFO=$($CRI ps --no-trunc --format "{{.Image}};{{.Names}}" --filter label=org.label-schema.name="docker-mailserver" | tail -1) +INFO=$($CRI ps \ + --no-trunc \ + --format "{{.Image}};{{.Names}}" \ + --filter label=org.label-schema.name="docker-mailserver" | \ + tail -1) IMAGE_NAME=${INFO%;*} CONTAINER_NAME=${INFO#*;}