From e9cf7313bf9a57775a573ae534de43f9d8a7166c Mon Sep 17 00:00:00 2001 From: 3wc <3wc.git@doesthisthing.work> Date: Fri, 25 Sep 2020 23:45:50 +0200 Subject: [PATCH 1/5] Tweak nuclear destroy-all-secrets command --- plugin.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin.sh b/plugin.sh index f766efd..3141f47 100755 --- a/plugin.sh +++ b/plugin.sh @@ -75,7 +75,8 @@ run_cleanup() { # See https://github.com/moby/moby/issues/30942#issuecomment-540699206 until [ -z "$(docker stack ps "$PLUGIN_STACK" -q)" ]; do sleep 1; done docker -H "$DOCKER_HOST" system prune --all --volumes --force - docker -H "$DOCKER_HOST" secret rm "$(docker -H "$DOCKER_HOST" secret ls -q)" || true + # try and remove all secrets; Docker will leave ones which are in use + docker -H "$DOCKER_HOST" secret ls --format '{{ .Name }}' | xargs -i sh -c "echo {}; docker secret -H \"$DOCKER_HOST\" rm {} || true" echo "--- end cleanup ---" } From 1c437714001b86d9f2e74a0c87439d2835b397f0 Mon Sep 17 00:00:00 2001 From: 3wc <3wc.git@doesthisthing.work> Date: Fri, 25 Sep 2020 23:54:12 +0200 Subject: [PATCH 2/5] Fix docker argument order Fixes #5 --- plugin.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.sh b/plugin.sh index 3141f47..154d1dc 100755 --- a/plugin.sh +++ b/plugin.sh @@ -76,7 +76,7 @@ run_cleanup() { until [ -z "$(docker stack ps "$PLUGIN_STACK" -q)" ]; do sleep 1; done docker -H "$DOCKER_HOST" system prune --all --volumes --force # try and remove all secrets; Docker will leave ones which are in use - docker -H "$DOCKER_HOST" secret ls --format '{{ .Name }}' | xargs -i sh -c "echo {}; docker secret -H \"$DOCKER_HOST\" rm {} || true" + docker -H "$DOCKER_HOST" secret ls --format '{{ .Name }}' | xargs -i sh -c "echo {}; docker -H \"$DOCKER_HOST\" secret rm {} || true" echo "--- end cleanup ---" } From 061f8e8732c536d2c720820b0441d21033f100ae Mon Sep 17 00:00:00 2001 From: 3wc <3wc.git@doesthisthing.work> Date: Sat, 26 Sep 2020 16:02:20 +0200 Subject: [PATCH 3/5] Set DOCKER_HOST to try and prevent hang --- plugin.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.sh b/plugin.sh index 154d1dc..1f6f724 100755 --- a/plugin.sh +++ b/plugin.sh @@ -73,7 +73,7 @@ run_purge() { run_cleanup() { echo "--- start cleanup ---" # See https://github.com/moby/moby/issues/30942#issuecomment-540699206 - until [ -z "$(docker stack ps "$PLUGIN_STACK" -q)" ]; do sleep 1; done + until [ -z "$(docker -H "$DOCKER_HOST" stack ps "$PLUGIN_STACK" -q)" ]; do sleep 1; done docker -H "$DOCKER_HOST" system prune --all --volumes --force # try and remove all secrets; Docker will leave ones which are in use docker -H "$DOCKER_HOST" secret ls --format '{{ .Name }}' | xargs -i sh -c "echo {}; docker -H \"$DOCKER_HOST\" secret rm {} || true" From 314d9dd611dd0721eb1e5bb53d480e040d301bca Mon Sep 17 00:00:00 2001 From: 3wc <3wc.git@doesthisthing.work> Date: Sat, 26 Sep 2020 16:13:47 +0200 Subject: [PATCH 4/5] Revert "Set DOCKER_HOST to try and prevent hang" This reverts commit 061f8e8732c536d2c720820b0441d21033f100ae. --- plugin.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.sh b/plugin.sh index 1f6f724..154d1dc 100755 --- a/plugin.sh +++ b/plugin.sh @@ -73,7 +73,7 @@ run_purge() { run_cleanup() { echo "--- start cleanup ---" # See https://github.com/moby/moby/issues/30942#issuecomment-540699206 - until [ -z "$(docker -H "$DOCKER_HOST" stack ps "$PLUGIN_STACK" -q)" ]; do sleep 1; done + until [ -z "$(docker stack ps "$PLUGIN_STACK" -q)" ]; do sleep 1; done docker -H "$DOCKER_HOST" system prune --all --volumes --force # try and remove all secrets; Docker will leave ones which are in use docker -H "$DOCKER_HOST" secret ls --format '{{ .Name }}' | xargs -i sh -c "echo {}; docker -H \"$DOCKER_HOST\" secret rm {} || true" From f57f7b2a8c5ca350cbd6d691cbcb53401e2b7eb6 Mon Sep 17 00:00:00 2001 From: 3wc <3wc.git@doesthisthing.work> Date: Sat, 26 Sep 2020 16:14:32 +0200 Subject: [PATCH 5/5] Better approach: only run cleanup during purge --- plugin.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/plugin.sh b/plugin.sh index 154d1dc..a2da71c 100755 --- a/plugin.sh +++ b/plugin.sh @@ -67,14 +67,11 @@ run_stack_wait() { run_purge() { echo "--- start purge ---" docker -H "$DOCKER_HOST" stack rm "$PLUGIN_STACK" - echo "--- end purge ---" -} -run_cleanup() { - echo "--- start cleanup ---" # See https://github.com/moby/moby/issues/30942#issuecomment-540699206 until [ -z "$(docker stack ps "$PLUGIN_STACK" -q)" ]; do sleep 1; done docker -H "$DOCKER_HOST" system prune --all --volumes --force + # try and remove all secrets; Docker will leave ones which are in use docker -H "$DOCKER_HOST" secret ls --format '{{ .Name }}' | xargs -i sh -c "echo {}; docker -H \"$DOCKER_HOST\" secret rm {} || true" echo "--- end cleanup ---" @@ -96,7 +93,6 @@ run_plugin() { run_purge fi - run_cleanup echo "--- end ssh-stack-deploy ---" }