-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/add container log tailing cmd (#1361)
* Add a command to tail logs from quickstart container * Move logs under a container subcommand: network container logs * Move start command under container: network container start network start will still work, it is marked as deprecated and should be removed at the next major release * Move stop command under container: network container stop `network stop` will still work, it is marked as deprecated and should be removed at the next major release --------- Co-authored-by: Leigh McCulloch <[email protected]>
- Loading branch information
1 parent
6ce6259
commit 9c6d23c
Showing
7 changed files
with
222 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
pub(crate) mod logs; | ||
mod shared; | ||
pub(crate) mod start; | ||
pub(crate) mod stop; | ||
|
||
// TODO: remove once `network start` is removed | ||
pub type StartCmd = start::Cmd; | ||
// TODO: remove once `network top` is removed | ||
pub type StopCmd = stop::Cmd; | ||
|
||
#[derive(Debug, clap::Subcommand)] | ||
pub enum Cmd { | ||
/// Tail logs of a running network container | ||
Logs(logs::Cmd), | ||
/// Start network | ||
/// | ||
/// Start a container running a Stellar node, RPC, API, and friendbot (faucet). | ||
/// | ||
/// soroban network 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 | ||
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(stop::Cmd), | ||
} | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error { | ||
#[error(transparent)] | ||
Logs(#[from] logs::Error), | ||
|
||
#[error(transparent)] | ||
Start(#[from] start::Error), | ||
|
||
#[error(transparent)] | ||
Stop(#[from] stop::Error), | ||
} | ||
|
||
impl Cmd { | ||
pub async fn run(&self) -> Result<(), Error> { | ||
match &self { | ||
Cmd::Logs(cmd) => cmd.run().await?, | ||
Cmd::Start(cmd) => cmd.run().await?, | ||
Cmd::Stop(cmd) => cmd.run().await?, | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use futures_util::TryStreamExt; | ||
|
||
use crate::commands::network::container::shared::{ | ||
connect_to_docker, Error as ConnectionError, Network, DOCKER_HOST_HELP, | ||
}; | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error { | ||
#[error(transparent)] | ||
ConnectionError(#[from] ConnectionError), | ||
|
||
#[error("⛔ ️Failed to tail container: {0}")] | ||
TailContainerError(#[from] bollard::errors::Error), | ||
} | ||
|
||
#[derive(Debug, clap::Parser, Clone)] | ||
pub struct Cmd { | ||
/// Network to tail | ||
pub network: Network, | ||
|
||
#[arg(short = 'd', long, help = DOCKER_HOST_HELP, env = "DOCKER_HOST")] | ||
pub docker_host: Option<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 logs_stream = &mut docker.logs( | ||
&container_name, | ||
Some(bollard::container::LogsOptions { | ||
follow: true, | ||
stdout: true, | ||
stderr: true, | ||
tail: "all", | ||
..Default::default() | ||
}), | ||
); | ||
|
||
while let Some(log) = logs_stream.try_next().await? { | ||
print!("{log}"); | ||
} | ||
Ok(()) | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
cmd/soroban-cli/src/commands/network/stop.rs → ...li/src/commands/network/container/stop.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters