Skip to content

Commit

Permalink
Use network name as the container name
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman committed Feb 7, 2024
1 parent 8457ecb commit 6687e37
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
10 changes: 2 additions & 8 deletions cmd/soroban-cli/src/commands/network/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use futures_util::TryStreamExt;
use std::collections::HashMap;

const DEFAULT_PORT_MAPPING: &str = "8000:8000";
const CONTAINER_NAME: &str = "stellar";
const DOCKER_IMAGE: &str = "docker.io/stellar/quickstart";

// DEFAULT_TIMEOUT and API_DEFAULT_VERSION are from the bollard crate
Expand Down Expand Up @@ -57,10 +56,6 @@ pub struct Cmd {
#[arg(short = 'l', long)]
pub limit: Option<String>,

/// argument to specify the container name
#[arg(short = 'n', long, default_value = CONTAINER_NAME)]
pub container_name: String,

/// argument to specify the HOST_PORT:CONTAINER_PORT mapping
#[arg(short = 'p', long, num_args = 1.., default_value = DEFAULT_PORT_MAPPING)]
pub ports_mapping: Vec<String>,
Expand Down Expand Up @@ -117,10 +112,9 @@ async fn run_docker_command(cmd: &Cmd) {
..Default::default()
};

println!("CONFIG: {:#?}", config);

let container_name = format!("stellar-{}", cmd.network);
let options = Some(CreateContainerOptions {
name: cmd.container_name.clone(),
name: container_name,
platform: None,
});

Expand Down
53 changes: 32 additions & 21 deletions cmd/soroban-cli/src/commands/network/stop.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,47 @@
use core::fmt;

use bollard::{ClientVersion, Docker};
use clap::ValueEnum;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("Failed to stop container: {0}")]
StopContainerError(#[from] bollard::errors::Error),
}

const CONTAINER_NAME: &str = "stellar";
// DEFAULT_TIMEOUT and API_DEFAULT_VERSION are from the bollard crate
const DEFAULT_TIMEOUT: u64 = 120;
const API_DEFAULT_VERSION: &ClientVersion = &ClientVersion {
major_version: 1,
minor_version: 40,
};

// TODO: move to a shared module
#[derive(ValueEnum, Debug, Clone, PartialEq)]
pub enum Network {
Local,
Testnet,
Futurenet,
Pubnet,
}

impl fmt::Display for Network {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let variant_str = match self {
Network::Local => "local",
Network::Testnet => "testnet",
Network::Futurenet => "futurenet",
Network::Pubnet => "pubnet",
};

write!(f, "{}", variant_str)
}
}

#[derive(Debug, clap::Parser, Clone)]
pub struct Cmd {
/// container to stop, defaults to "stellar"
pub container_name: Option<String>,
/// network container to stop
pub network: Network,

/// optional argument to override the default docker socket path
#[arg(short = 'd', long)]
Expand All @@ -26,26 +50,13 @@ pub struct Cmd {

impl Cmd {
pub async fn run(&self) -> Result<(), Error> {
let container_name = self
.container_name
.clone()
.unwrap_or(String::from(CONTAINER_NAME));

let container_name = format!("stellar-{}", self.network);
let docker = connect_to_docker(self);
println!("Stopping container: {container_name}");
run_docker_command(self).await
}
}
docker.stop_container(&container_name, None).await.unwrap();

async fn run_docker_command(cmd: &Cmd) -> Result<(), Error> {
let docker = connect_to_docker(cmd);
let container_name = cmd
.container_name
.clone()
.unwrap_or(String::from(CONTAINER_NAME));

docker.stop_container(&container_name, None).await.unwrap();

Ok(())
Ok(())
}
}

//TODO: move to a shared module
Expand Down

0 comments on commit 6687e37

Please sign in to comment.