Ver código fonte

fix: stop containers in single rm -f step

Previously stop used two commands: docker stop then docker rm.
With --rm (default), docker stop auto-removes the container, so the
follow-up docker rm found it already gone and raised a spurious error.

Fix: replace with a single .
docker rm -f force-stops and removes in one atomic step regardless
of --rm status, so --rm and --keep containers are both handled
cleanly.
Alexander Korolev 4 meses atrás
pai
commit
be65b44ddb
1 arquivos alterados com 10 adições e 32 exclusões
  1. 10 32
      src/docker/mod.rs

+ 10 - 32
src/docker/mod.rs

@@ -186,39 +186,17 @@ pub async fn stop_cluster(
     } else {
         cluster.nodes.iter().collect()
     };
-    let mut failures = Vec::new();
     for node in &nodes {
-        let stop_cmd = format!(
-            "docker ps -q --filter \"label=sm121.recipe={}\" | xargs -r docker stop",
-            recipe_name
-        );
-        if let Err(e) = run_ssh(config, node, stop_cmd, dry_run).await {
-            tracing::warn!(
-                "{}",
-                fluent_i18n::t!("stop-failed", { "name" => &node.name, "error" => e.to_string() })
-            );
-            failures.push((node.name.clone(), "stop".to_string(), e));
-        }
-        let rm_cmd = format!(
-            "docker ps -qa --filter \"label=sm121.recipe={}\" | xargs -r docker rm",
-            recipe_name
-        );
-        if let Err(e) = run_ssh(config, node, rm_cmd, dry_run).await {
-            tracing::warn!(
-                "{}",
-                fluent_i18n::t!("remove-failed", { "name" => &node.name, "error" => e.to_string() })
-            );
-            failures.push((node.name.clone(), "rm".to_string(), e));
-        }
-    }
-    if !failures.is_empty() {
-        for (name, action, e) in &failures {
-            tracing::warn!(
-                "{}",
-                fluent_i18n::t!("failed-to", { "action" => action, "name" => name, "error" => e.to_string() })
-            );
-        }
-        anyhow::bail!("Failed to stop containers on {} node(s)", failures.len());
+        run_ssh(
+            config,
+            node,
+            format!(
+                "docker ps -qa --filter \"label=sm121.recipe={}\" | xargs -r docker rm -f",
+                recipe_name
+            ),
+            dry_run,
+        )
+        .await?;
     }
     info!("{}", fluent_i18n::t!("cluster-all-stopped"));
     Ok(())