From a872d175e8216ee558e7d6c069e4d5eeac839164 Mon Sep 17 00:00:00 2001 From: Andre da Silva Date: Thu, 28 Nov 2024 23:24:26 -0300 Subject: [PATCH] Avoid build on linera net up --kubernetes --- linera-client/src/client_options.rs | 10 ++++++++ linera-service/src/cli_wrappers/docker.rs | 9 ++------ .../src/cli_wrappers/local_kubernetes_net.rs | 23 ++++++++++++++++--- linera-service/src/linera/main.rs | 4 ++++ linera-service/src/linera/net_up_utils.rs | 4 ++++ 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/linera-client/src/client_options.rs b/linera-client/src/client_options.rs index 8abc1ae3e3b8..ff98fbafcb1e 100644 --- a/linera-client/src/client_options.rs +++ b/linera-client/src/client_options.rs @@ -1004,6 +1004,16 @@ pub enum NetCommand { #[arg(long, num_args=0..=1)] binaries: Option>, + /// Don't build docker image. This assumes that the image is already built. + #[cfg(feature = "kubernetes")] + #[arg(long, default_value = "false")] + no_build: bool, + + /// The name of the docker image to use. + #[cfg(feature = "kubernetes")] + #[arg(long, default_value = "linera:latest")] + docker_image_name: String, + /// Run with a specific path where the wallet and validator input files are. /// If none, then a temporary directory is created. #[arg(long)] diff --git a/linera-service/src/cli_wrappers/docker.rs b/linera-service/src/cli_wrappers/docker.rs index 4a7bc34e3257..b9f5fe1e6dd1 100644 --- a/linera-service/src/cli_wrappers/docker.rs +++ b/linera-service/src/cli_wrappers/docker.rs @@ -17,7 +17,7 @@ impl DockerImage { &self.name } - pub async fn build(name: String, binaries: &BuildArg, github_root: &PathBuf) -> Result { + pub async fn build(name: &String, binaries: &BuildArg, github_root: &PathBuf) -> Result { let build_arg = match binaries { BuildArg::Directory(bin_path) => { // Get the binaries from the specified path @@ -73,12 +73,7 @@ impl DockerImage { ), ]); - command - .arg(".") - .args(["-t", &name]) - .spawn_and_wait() - .await?; - + command.arg(".").args(["-t", name]).spawn_and_wait().await?; Ok(docker_image) } } diff --git a/linera-service/src/cli_wrappers/local_kubernetes_net.rs b/linera-service/src/cli_wrappers/local_kubernetes_net.rs index f5c922a331b6..92c9af39f44e 100644 --- a/linera-service/src/cli_wrappers/local_kubernetes_net.rs +++ b/linera-service/src/cli_wrappers/local_kubernetes_net.rs @@ -46,6 +46,8 @@ pub struct LocalKubernetesNetConfig { pub num_initial_validators: usize, pub num_shards: usize, pub binaries: BuildArg, + pub no_build: bool, + pub docker_image_name: String, pub policy: ResourceControlPolicy, } @@ -62,6 +64,8 @@ pub struct LocalKubernetesNet { next_client_id: usize, tmp_dir: Arc, binaries: BuildArg, + no_build: bool, + docker_image_name: String, kubectl_instance: Arc>, kind_clusters: Vec, num_initial_validators: usize, @@ -96,6 +100,8 @@ impl SharedLocalKubernetesNetTestingConfig { num_initial_validators: 4, num_shards: 4, binaries, + no_build: false, + docker_image_name: String::from("linera:latest"), policy: ResourceControlPolicy::devnet(), }) } @@ -122,6 +128,8 @@ impl LineraNetConfig for LocalKubernetesNetConfig { self.network, self.testing_prng_seed, self.binaries, + self.no_build, + self.docker_image_name, KubectlInstance::new(Vec::new()), clusters, self.num_initial_validators, @@ -300,10 +308,13 @@ impl LineraNet for LocalKubernetesNet { } impl LocalKubernetesNet { + #[allow(clippy::too_many_arguments)] fn new( network: Network, testing_prng_seed: Option, binaries: BuildArg, + no_build: bool, + docker_image_name: String, kubectl_instance: KubectlInstance, kind_clusters: Vec, num_initial_validators: usize, @@ -315,6 +326,8 @@ impl LocalKubernetesNet { next_client_id: 0, tmp_dir: Arc::new(tempdir()?), binaries, + no_build, + docker_image_name, kubectl_instance: Arc::new(Mutex::new(kubectl_instance)), kind_clusters, num_initial_validators, @@ -394,8 +407,12 @@ impl LocalKubernetesNet { async fn run(&mut self) -> Result<()> { let github_root = get_github_root().await?; // Build Docker image - let docker_image = - DockerImage::build(String::from("linera:latest"), &self.binaries, &github_root).await?; + let docker_image_name = if self.no_build { + self.docker_image_name.clone() + } else { + DockerImage::build(&self.docker_image_name, &self.binaries, &github_root).await?; + self.docker_image_name.clone() + }; let base_dir = github_root .join("kubernetes") @@ -412,13 +429,13 @@ impl LocalKubernetesNet { let mut validators_initialization_futures = Vec::new(); for (i, kind_cluster) in self.kind_clusters.iter().cloned().enumerate() { - let docker_image_name = docker_image.name().to_string(); let base_dir = base_dir.clone(); let github_root = github_root.clone(); let kubectl_instance = kubectl_instance_clone.clone(); let tmp_dir_path = tmp_dir_path_clone.clone(); + let docker_image_name = docker_image_name.clone(); let future = async move { let cluster_id = kind_cluster.id(); kind_cluster.load_docker_image(&docker_image_name).await?; diff --git a/linera-service/src/linera/main.rs b/linera-service/src/linera/main.rs index 89a7b7acc323..bef2749c3cd0 100644 --- a/linera-service/src/linera/main.rs +++ b/linera-service/src/linera/main.rs @@ -1592,6 +1592,8 @@ async fn run(options: &ClientOptions) -> Result { policy_config, kubernetes: true, binaries, + no_build, + docker_image_name, path: _, storage: _, external_protocol: _, @@ -1604,6 +1606,8 @@ async fn run(options: &ClientOptions) -> Result { *shards, *testing_prng_seed, binaries, + *no_build, + docker_image_name.clone(), policy_config.into_policy(), ) .boxed() diff --git a/linera-service/src/linera/net_up_utils.rs b/linera-service/src/linera/net_up_utils.rs index b47861d952fa..669527bc2e4a 100644 --- a/linera-service/src/linera/net_up_utils.rs +++ b/linera-service/src/linera/net_up_utils.rs @@ -110,6 +110,8 @@ pub async fn handle_net_up_kubernetes( num_shards: usize, testing_prng_seed: Option, binaries: &Option>, + no_build: bool, + docker_image_name: String, policy: ResourceControlPolicy, ) -> anyhow::Result<()> { if num_initial_validators < 1 { @@ -130,6 +132,8 @@ pub async fn handle_net_up_kubernetes( num_initial_validators, num_shards, binaries: binaries.clone().into(), + no_build, + docker_image_name, policy, }; let (mut net, client1) = config.instantiate().await?;