From 3fbf97913ef6393a43eb8303a7ff1affd85f36c4 Mon Sep 17 00:00:00 2001 From: Elizabeth Engelman <4752801+elizabethengelman@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:18:21 -0400 Subject: [PATCH] Fix/network container improvements (#1423) * Return a better error message when stopping container that doesn't exist * Fix doc strings for network container commands * Allow for overwriting the default container name with -c --------- Co-authored-by: Willem Wyndham --- FULL_HELP_DOCS.md | 41 ++- .../src/commands/network/container.rs | 10 +- .../src/commands/network/container/logs.rs | 18 +- .../src/commands/network/container/shared.rs | 137 +++++---- .../src/commands/network/container/start.rs | 261 ++++++++++-------- .../src/commands/network/container/stop.rs | 57 +++- cmd/soroban-cli/src/commands/network/mod.rs | 2 +- 7 files changed, 295 insertions(+), 231 deletions(-) diff --git a/FULL_HELP_DOCS.md b/FULL_HELP_DOCS.md index 689ce3036..035175ad6 100644 --- a/FULL_HELP_DOCS.md +++ b/FULL_HELP_DOCS.md @@ -1060,7 +1060,7 @@ Start a container running a Stellar node, RPC, API, and friendbot (faucet). By default, when starting a testnet container, without any optional arguments, it will run the equivalent of the following docker command: -`docker run --rm -p 8000:8000 --name stellar stellar/quickstart:testing --testnet --enable-soroban-rpc` +`docker run --rm -p 8000:8000 --name stellar stellar/quickstart:testing --testnet --enable rpc,horizon` **Usage:** `stellar network start [OPTIONS] ` @@ -1074,6 +1074,7 @@ By default, when starting a testnet container, without any optional arguments, i ###### **Options:** * `-d`, `--docker-host ` — Optional argument to override the default docker host. This is useful when you are using a non-standard docker host path for your Docker-compatible container runtime, e.g. Docker Desktop defaults to $HOME/.docker/run/docker.sock instead of /var/run/docker.sock +* `--name ` — Optional argument to specify the container name * `-l`, `--limits ` — Optional argument to specify the limits for the local network only * `-p`, `--ports-mapping ` — Argument to specify the `HOST_PORT:CONTAINER_PORT` mapping @@ -1089,14 +1090,11 @@ By default, when starting a testnet container, without any optional arguments, i Stop a network started with `network start`. For example, if you ran `stellar network start local`, you can use `stellar network stop local` to stop it. -**Usage:** `stellar network stop [OPTIONS] ` +**Usage:** `stellar network stop [OPTIONS] ` ###### **Arguments:** -* `` — Network to stop - - Possible values: `local`, `testnet`, `futurenet`, `pubnet` - +* `` — Container to stop ###### **Options:** @@ -1112,24 +1110,21 @@ Commands to start, stop and get logs for a quickstart container ###### **Subcommands:** -* `logs` — Tail logs of a running network container -* `start` — Start network -* `stop` — Stop a network started with `network container start`. For example, if you ran `network container start local`, you can use `network container stop local` to stop it +* `logs` — Get logs from a running network container +* `start` — Start a container running a Stellar node, RPC, API, and friendbot (faucet) +* `stop` — Stop a network container started with `network container start` ## `stellar network container logs` -Tail logs of a running network container +Get logs from a running network container -**Usage:** `stellar network container logs [OPTIONS] ` +**Usage:** `stellar network container logs [OPTIONS] ` ###### **Arguments:** -* `` — Network to tail - - Possible values: `local`, `testnet`, `futurenet`, `pubnet` - +* `` — Container to get logs from ###### **Options:** @@ -1139,15 +1134,13 @@ Tail logs of a running network container ## `stellar network container start` -Start network - Start a container running a Stellar node, RPC, API, and friendbot (faucet). -`stellar network start NETWORK [OPTIONS]` +`stellar network container start NETWORK [OPTIONS]` By default, when starting a testnet container, without any optional arguments, it will run the equivalent of the following docker command: -`docker run --rm -p 8000:8000 --name stellar stellar/quickstart:testing --testnet --enable-soroban-rpc` +`docker run --rm -p 8000:8000 --name stellar stellar/quickstart:testing --testnet --enable rpc,horizon` **Usage:** `stellar network container start [OPTIONS] ` @@ -1161,6 +1154,7 @@ By default, when starting a testnet container, without any optional arguments, i ###### **Options:** * `-d`, `--docker-host ` — Optional argument to override the default docker host. This is useful when you are using a non-standard docker host path for your Docker-compatible container runtime, e.g. Docker Desktop defaults to $HOME/.docker/run/docker.sock instead of /var/run/docker.sock +* `--name ` — Optional argument to specify the container name * `-l`, `--limits ` — Optional argument to specify the limits for the local network only * `-p`, `--ports-mapping ` — Argument to specify the `HOST_PORT:CONTAINER_PORT` mapping @@ -1172,16 +1166,13 @@ By default, when starting a testnet container, without any optional arguments, i ## `stellar network container stop` -Stop a network started with `network container start`. For example, if you ran `network container start local`, you can use `network container stop local` to stop it +Stop a network container started with `network container start` -**Usage:** `stellar network container stop [OPTIONS] ` +**Usage:** `stellar network container stop [OPTIONS] ` ###### **Arguments:** -* `` — Network to stop - - Possible values: `local`, `testnet`, `futurenet`, `pubnet` - +* `` — Container to stop ###### **Options:** diff --git a/cmd/soroban-cli/src/commands/network/container.rs b/cmd/soroban-cli/src/commands/network/container.rs index 16e5d73be..511c0e11b 100644 --- a/cmd/soroban-cli/src/commands/network/container.rs +++ b/cmd/soroban-cli/src/commands/network/container.rs @@ -10,19 +10,17 @@ pub type StopCmd = stop::Cmd; #[derive(Debug, clap::Subcommand)] pub enum Cmd { - /// Tail logs of a running network container + /// Get logs from a running network container Logs(logs::Cmd), - /// Start network - /// /// Start a container running a Stellar node, RPC, API, and friendbot (faucet). /// - /// `stellar network start NETWORK [OPTIONS]` + /// `stellar network container start NETWORK [OPTIONS]` /// /// By default, when starting a testnet container, without any optional arguments, it will run the equivalent of the following docker command: /// - /// `docker run --rm -p 8000:8000 --name stellar stellar/quickstart:testing --testnet --enable-soroban-rpc` + /// `docker run --rm -p 8000:8000 --name stellar stellar/quickstart:testing --testnet --enable rpc,horizon` Start(start::Cmd), - /// Stop a network started with `network container start`. For example, if you ran `network container start local`, you can use `network container stop local` to stop it. + /// Stop a network container started with `network container start`. Stop(stop::Cmd), } diff --git a/cmd/soroban-cli/src/commands/network/container/logs.rs b/cmd/soroban-cli/src/commands/network/container/logs.rs index e37ceb098..99b36af9b 100644 --- a/cmd/soroban-cli/src/commands/network/container/logs.rs +++ b/cmd/soroban-cli/src/commands/network/container/logs.rs @@ -1,8 +1,8 @@ use futures_util::TryStreamExt; -use crate::commands::network::container::shared::{ - connect_to_docker, Error as ConnectionError, Network, DOCKER_HOST_HELP, -}; +use crate::commands::network::container::shared::Error as ConnectionError; + +use super::shared::{Args, Name}; #[derive(thiserror::Error, Debug)] pub enum Error { @@ -15,17 +15,17 @@ pub enum Error { #[derive(Debug, clap::Parser, Clone)] pub struct Cmd { - /// Network to tail - pub network: Network, + #[command(flatten)] + pub container_args: Args, - #[arg(short = 'd', long, help = DOCKER_HOST_HELP, env = "DOCKER_HOST")] - pub docker_host: Option, + /// Container to get logs from + pub name: String, } impl Cmd { pub async fn run(&self) -> Result<(), Error> { - let container_name = format!("stellar-{}", self.network); - let docker = connect_to_docker(&self.docker_host).await?; + let container_name = Name(self.name.clone()).get_internal_container_name(); + let docker = self.container_args.connect_to_docker().await?; let logs_stream = &mut docker.logs( &container_name, Some(bollard::container::LogsOptions { diff --git a/cmd/soroban-cli/src/commands/network/container/shared.rs b/cmd/soroban-cli/src/commands/network/container/shared.rs index 9da8a1bea..f819f3ed3 100644 --- a/cmd/soroban-cli/src/commands/network/container/shared.rs +++ b/cmd/soroban-cli/src/commands/network/container/shared.rs @@ -31,7 +31,81 @@ pub enum Error { UnsupportedURISchemeError { uri: String }, } -#[derive(ValueEnum, Debug, Clone, PartialEq)] +#[derive(Debug, clap::Parser, Clone)] +pub struct Args { + /// Optional argument to override the default docker host. This is useful when you are using a non-standard docker host path for your Docker-compatible container runtime, e.g. Docker Desktop defaults to $HOME/.docker/run/docker.sock instead of /var/run/docker.sock + #[arg(short = 'd', long, help = DOCKER_HOST_HELP, env = "DOCKER_HOST")] + pub docker_host: Option, +} + +impl Args { + pub(crate) fn get_additional_flags(&self) -> String { + self.docker_host + .as_ref() + .map(|docker_host| format!("--docker-host {docker_host}")) + .unwrap_or_default() + } + + pub(crate) async fn connect_to_docker(&self) -> Result { + // if no docker_host is provided, use the default docker host: + // "unix:///var/run/docker.sock" on unix machines + // "npipe:////./pipe/docker_engine" on windows machines + let host = self.docker_host.as_ref().map_or_else( + || DEFAULT_DOCKER_HOST.to_string(), + std::string::ToString::to_string, + ); + + // this is based on the `connect_with_defaults` method which has not yet been released in the bollard crate + // https://github.com/fussybeaver/bollard/blob/0972b1aac0ad5c08798e100319ddd0d2ee010365/src/docker.rs#L660 + let connection = match host.clone() { + // if tcp or http, use connect_with_http_defaults + // if unix and host starts with "unix://" use connect_with_unix + // if windows and host starts with "npipe://", use connect_with_named_pipe + // else default to connect_with_unix + h if h.starts_with("tcp://") || h.starts_with("http://") => { + Docker::connect_with_http_defaults() + } + #[cfg(unix)] + h if h.starts_with("unix://") => { + Docker::connect_with_unix(&h, DEFAULT_TIMEOUT, API_DEFAULT_VERSION) + } + #[cfg(windows)] + h if h.starts_with("npipe://") => { + Docker::connect_with_named_pipe(&h, DEFAULT_TIMEOUT, API_DEFAULT_VERSION) + } + _ => { + return Err(Error::UnsupportedURISchemeError { + uri: host.to_string(), + }); + } + }?; + + match check_docker_connection(&connection).await { + Ok(()) => Ok(connection), + // If we aren't able to connect with the defaults, or with the provided docker_host + // try to connect with the default docker desktop socket since that is a common use case for devs + #[allow(unused_variables)] + Err(e) => { + // if on unix, try to connect to the default docker desktop socket + #[cfg(unix)] + { + let docker_desktop_connection = try_docker_desktop_socket(&host)?; + match check_docker_connection(&docker_desktop_connection).await { + Ok(()) => Ok(docker_desktop_connection), + Err(err) => Err(err)?, + } + } + + #[cfg(windows)] + { + Err(e)? + } + } + } + } +} + +#[derive(ValueEnum, Debug, Copy, Clone, PartialEq)] pub enum Network { Local, Testnet, @@ -52,61 +126,14 @@ impl fmt::Display for Network { } } -pub async fn connect_to_docker(docker_host: &Option) -> Result { - // if no docker_host is provided, use the default docker host: - // "unix:///var/run/docker.sock" on unix machines - // "npipe:////./pipe/docker_engine" on windows machines - - let host = docker_host - .clone() - .unwrap_or(DEFAULT_DOCKER_HOST.to_string()); - - // this is based on the `connect_with_defaults` method which has not yet been released in the bollard crate - // https://github.com/fussybeaver/bollard/blob/0972b1aac0ad5c08798e100319ddd0d2ee010365/src/docker.rs#L660 - let connection = match host.clone() { - // if tcp or http, use connect_with_http_defaults - // if unix and host starts with "unix://" use connect_with_unix - // if windows and host starts with "npipe://", use connect_with_named_pipe - // else default to connect_with_unix - h if h.starts_with("tcp://") || h.starts_with("http://") => { - Docker::connect_with_http_defaults() - } - #[cfg(unix)] - h if h.starts_with("unix://") => { - Docker::connect_with_unix(&h, DEFAULT_TIMEOUT, API_DEFAULT_VERSION) - } - #[cfg(windows)] - h if h.starts_with("npipe://") => { - Docker::connect_with_named_pipe(&h, DEFAULT_TIMEOUT, API_DEFAULT_VERSION) - } - _ => { - return Err(Error::UnsupportedURISchemeError { - uri: host.to_string(), - }); - } - }?; - - match check_docker_connection(&connection).await { - Ok(()) => Ok(connection), - // If we aren't able to connect with the defaults, or with the provided docker_host - // try to connect with the default docker desktop socket since that is a common use case for devs - #[allow(unused_variables)] - Err(e) => { - // if on unix, try to connect to the default docker desktop socket - #[cfg(unix)] - { - let docker_desktop_connection = try_docker_desktop_socket(&host)?; - match check_docker_connection(&docker_desktop_connection).await { - Ok(()) => Ok(docker_desktop_connection), - Err(err) => Err(err)?, - } - } +pub struct Name(pub String); +impl Name { + pub fn get_internal_container_name(&self) -> String { + format!("stellar-{}", self.0) + } - #[cfg(windows)] - { - Err(e)? - } - } + pub fn get_external_container_name(&self) -> String { + self.0.to_string() } } diff --git a/cmd/soroban-cli/src/commands/network/container/start.rs b/cmd/soroban-cli/src/commands/network/container/start.rs index cc9619f1d..46348c297 100644 --- a/cmd/soroban-cli/src/commands/network/container/start.rs +++ b/cmd/soroban-cli/src/commands/network/container/start.rs @@ -7,9 +7,9 @@ use bollard::{ }; use futures_util::TryStreamExt; -use crate::commands::network::container::shared::{ - connect_to_docker, Error as ConnectionError, Network, DOCKER_HOST_HELP, -}; +use crate::commands::network::container::shared::{Error as ConnectionError, Network}; + +use super::shared::{Args, Name}; const DEFAULT_PORT_MAPPING: &str = "8000:8000"; const DOCKER_IMAGE: &str = "docker.io/stellar/quickstart"; @@ -17,19 +17,23 @@ const DOCKER_IMAGE: &str = "docker.io/stellar/quickstart"; #[derive(thiserror::Error, Debug)] pub enum Error { #[error("⛔ ️Failed to connect to docker: {0}")] - ConnectionError(#[from] ConnectionError), + DockerConnectionFailed(#[from] ConnectionError), #[error("⛔ ️Failed to create container: {0}")] - BollardErr(#[from] bollard::errors::Error), + CreateContainerFailed(#[from] bollard::errors::Error), } #[derive(Debug, clap::Parser, Clone)] pub struct Cmd { + #[command(flatten)] + pub container_args: Args, + /// Network to start pub network: Network, - #[arg(short = 'd', long, help = DOCKER_HOST_HELP, env = "DOCKER_HOST")] - pub docker_host: Option, + /// Optional argument to specify the container name + #[arg(long)] + pub name: Option, /// Optional argument to specify the limits for the local network only #[arg(short = 'l', long)] @@ -51,137 +55,152 @@ pub struct Cmd { impl Cmd { pub async fn run(&self) -> Result<(), Error> { println!("ℹ️ Starting {} network", &self.network); - run_docker_command(self).await + self.run_docker_command().await } -} -async fn run_docker_command(cmd: &Cmd) -> Result<(), Error> { - let docker = connect_to_docker(&cmd.docker_host).await?; - - let image = get_image_name(cmd); - docker - .create_image( - Some(CreateImageOptions { - from_image: image.clone(), + async fn run_docker_command(&self) -> Result<(), Error> { + let docker = self.container_args.connect_to_docker().await?; + + let image = self.get_image_name(); + docker + .create_image( + Some(CreateImageOptions { + from_image: image.clone(), + ..Default::default() + }), + None, + None, + ) + .try_collect::>() + .await?; + + let config = Config { + image: Some(image), + cmd: Some(self.get_container_args()), + attach_stdout: Some(true), + attach_stderr: Some(true), + host_config: Some(HostConfig { + auto_remove: Some(true), + port_bindings: Some(self.get_port_mapping()), ..Default::default() }), - None, - None, - ) - .try_collect::>() - .await?; - - let container_args = get_container_args(cmd); - let port_mapping = get_port_mapping(cmd); - - let config = Config { - image: Some(image), - cmd: Some(container_args), - attach_stdout: Some(true), - attach_stderr: Some(true), - host_config: Some(HostConfig { - auto_remove: Some(true), - port_bindings: Some(port_mapping), ..Default::default() - }), - ..Default::default() - }; - - let container_name = format!("stellar-{}", cmd.network); - let create_container_response = docker - .create_container( - Some(CreateContainerOptions { - name: container_name.clone(), - ..Default::default() - }), - config, - ) - .await?; - - docker - .start_container( - &create_container_response.id, - None::>, - ) - .await?; - println!("✅ Container started: {container_name}"); - let stop_message = format!( - "ℹ️ To stop this container run: stellar network stop {network} {additional_flags}", - network = &cmd.network, - additional_flags = if cmd.docker_host.is_some() { - format!("--docker-host {}", cmd.docker_host.as_ref().unwrap()) - } else { - String::new() + }; + + let create_container_response = docker + .create_container( + Some(CreateContainerOptions { + name: self.container_name().get_internal_container_name(), + ..Default::default() + }), + config, + ) + .await?; + + docker + .start_container( + &create_container_response.id, + None::>, + ) + .await?; + println!( + "✅ Container started: {}", + self.container_name().get_external_container_name() + ); + self.print_log_message(); + self.print_stop_message(); + Ok(()) + } + + fn get_image_name(&self) -> String { + // this can be overriden with the `-t` flag + let mut image_tag = match &self.network { + Network::Pubnet => "latest", + Network::Futurenet => "future", + _ => "testing", // default to testing for local and testnet + }; + + if let Some(image_override) = &self.image_tag_override { + println!( + "Overriding docker image tag to use '{image_override}' instead of '{image_tag}'" + ); + image_tag = image_override; } - ); - println!("{stop_message}"); - Ok(()) -} + format!("{DOCKER_IMAGE}:{image_tag}") + } -fn get_container_args(cmd: &Cmd) -> Vec { - [ - format!("--{}", cmd.network), - "--enable rpc,horizon".to_string(), - get_protocol_version_arg(cmd), - get_limits_arg(cmd), - ] - .iter() - .filter(|&s| !s.is_empty()) - .cloned() - .collect() -} + fn get_container_args(&self) -> Vec { + [ + format!("--{}", self.network), + "--enable rpc,horizon".to_string(), + self.get_protocol_version_arg(), + self.get_limits_arg(), + ] + .iter() + .filter(|&s| !s.is_empty()) + .cloned() + .collect() + } + + // The port mapping in the bollard crate is formatted differently than the docker CLI. In the docker CLI, we usually specify exposed ports as `-p HOST_PORT:CONTAINER_PORT`. But with the bollard crate, it is expecting the port mapping to be a map of the container port (with the protocol) to the host port. + fn get_port_mapping(&self) -> HashMap>> { + let mut port_mapping_hash = HashMap::new(); + for port_mapping in &self.ports_mapping { + let ports_vec: Vec<&str> = port_mapping.split(':').collect(); + let from_port = ports_vec[0]; + let to_port = ports_vec[1]; + + port_mapping_hash.insert( + format!("{to_port}/tcp"), + Some(vec![PortBinding { + host_ip: None, + host_port: Some(from_port.to_string()), + }]), + ); + } -fn get_image_name(cmd: &Cmd) -> String { - // this can be overriden with the `-t` flag - let mut image_tag = match cmd.network { - Network::Pubnet => "latest", - Network::Futurenet => "future", - _ => "testing", // default to testing for local and testnet - }; - - if let Some(image_override) = &cmd.image_tag_override { - println!("Overriding docker image tag to use '{image_override}' instead of '{image_tag}'"); - image_tag = image_override; + port_mapping_hash } - format!("{DOCKER_IMAGE}:{image_tag}") -} + fn container_name(&self) -> Name { + Name(self.name.clone().unwrap_or(self.network.to_string())) + } -// The port mapping in the bollard crate is formatted differently than the docker CLI. In the docker CLI, we usually specify exposed ports as `-p HOST_PORT:CONTAINER_PORT`. But with the bollard crate, it is expecting the port mapping to be a map of the container port (with the protocol) to the host port. -fn get_port_mapping(cmd: &Cmd) -> HashMap>> { - let mut port_mapping_hash = HashMap::new(); - for port_mapping in &cmd.ports_mapping { - let ports_vec: Vec<&str> = port_mapping.split(':').collect(); - let from_port = ports_vec[0]; - let to_port = ports_vec[1]; - - port_mapping_hash.insert( - format!("{to_port}/tcp"), - Some(vec![PortBinding { - host_ip: None, - host_port: Some(from_port.to_string()), - }]), + fn print_log_message(&self) { + let log_message = format!( + "ℹ️ To see the logs for this container run: stellar network container logs {container_name} {additional_flags}", + container_name = self.container_name().get_external_container_name(), + additional_flags = self.container_args.get_additional_flags(), ); + println!("{log_message}"); } - port_mapping_hash -} + fn print_stop_message(&self) { + let stop_message = + format!( + "ℹ️ To stop this container run: stellar network container stop {container_name} {additional_flags}", + container_name = self.container_name().get_external_container_name(), + additional_flags = self.container_args.get_additional_flags(), + ); + println!("{stop_message}"); + } -fn get_protocol_version_arg(cmd: &Cmd) -> String { - if cmd.network == Network::Local && cmd.protocol_version.is_some() { - let version = cmd.protocol_version.as_ref().unwrap(); - format!("--protocol-version {version}") - } else { - String::new() + fn get_protocol_version_arg(&self) -> String { + if self.network == Network::Local && self.protocol_version.is_some() { + let version = self.protocol_version.as_ref().unwrap(); + format!("--protocol-version {version}") + } else { + String::new() + } } -} -fn get_limits_arg(cmd: &Cmd) -> String { - if cmd.network == Network::Local && cmd.limits.is_some() { - let limits = cmd.limits.as_ref().unwrap(); - format!("--limits {limits}") - } else { - String::new() + fn get_limits_arg(&self) -> String { + if self.network == Network::Local && self.limits.is_some() { + let limits = self.limits.as_ref().unwrap(); + format!("--limits {limits}") + } else { + String::new() + } } } diff --git a/cmd/soroban-cli/src/commands/network/container/stop.rs b/cmd/soroban-cli/src/commands/network/container/stop.rs index c511b5e4d..733c86436 100644 --- a/cmd/soroban-cli/src/commands/network/container/stop.rs +++ b/cmd/soroban-cli/src/commands/network/container/stop.rs @@ -1,29 +1,58 @@ -use crate::commands::network::container::shared::{ - connect_to_docker, Error as ConnectionError, Network, DOCKER_HOST_HELP, -}; +use crate::commands::network::container::shared::Error as BollardConnectionError; + +use super::shared::{Args, Name}; #[derive(thiserror::Error, Debug)] pub enum Error { - #[error("Failed to stop container: {0}")] - StopContainerError(#[from] ConnectionError), + #[error("⛔ Failed to connect to docker: {0}")] + DockerConnectionFailed(#[from] BollardConnectionError), + + #[error("⛔ Container {container_name} not found")] + ContainerNotFound { + container_name: String, + #[source] + source: bollard::errors::Error, + }, + + #[error("⛔ Failed to stop container: {0}")] + ContainerStopFailed(#[from] bollard::errors::Error), } #[derive(Debug, clap::Parser, Clone)] pub struct Cmd { - /// Network to stop - pub network: Network, + #[command(flatten)] + pub container_args: Args, - #[arg(short = 'd', long, help = DOCKER_HOST_HELP, env = "DOCKER_HOST")] - pub docker_host: Option, + /// Container to stop + pub name: String, } impl Cmd { pub async fn run(&self) -> Result<(), Error> { - let container_name = format!("stellar-{}", self.network); - let docker = connect_to_docker(&self.docker_host).await?; - println!("ℹ️ Stopping container: {container_name}"); - docker.stop_container(&container_name, None).await.unwrap(); - println!("✅ Container stopped: {container_name}"); + let container_name = Name(self.name.clone()); + let docker = self.container_args.connect_to_docker().await?; + println!( + "ℹ️ Stopping container: {}", + container_name.get_external_container_name() + ); + docker + .stop_container(&container_name.get_internal_container_name(), None) + .await + .map_err(|e| { + let msg = e.to_string(); + if msg.contains("No such container") { + Error::ContainerNotFound { + container_name: container_name.get_external_container_name(), + source: e, + } + } else { + Error::ContainerStopFailed(e) + } + })?; + println!( + "✅ Container stopped: {}", + container_name.get_external_container_name() + ); Ok(()) } } diff --git a/cmd/soroban-cli/src/commands/network/mod.rs b/cmd/soroban-cli/src/commands/network/mod.rs index 435492295..1c34f92c8 100644 --- a/cmd/soroban-cli/src/commands/network/mod.rs +++ b/cmd/soroban-cli/src/commands/network/mod.rs @@ -38,7 +38,7 @@ pub enum Cmd { /// /// By default, when starting a testnet container, without any optional arguments, it will run the equivalent of the following docker command: /// - /// `docker run --rm -p 8000:8000 --name stellar stellar/quickstart:testing --testnet --enable-soroban-rpc` + /// `docker run --rm -p 8000:8000 --name stellar stellar/quickstart:testing --testnet --enable rpc,horizon` Start(container::StartCmd), /// ⚠️ Deprecated: use `stellar container stop` instead ///