Skip to content

Commit 1b117c3

Browse files
committed
Avoid build on linera net up --kubernetes
1 parent 3a4b51d commit 1b117c3

File tree

5 files changed

+40
-10
lines changed

5 files changed

+40
-10
lines changed

linera-client/src/client_options.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,16 @@ pub enum NetCommand {
10041004
#[arg(long, num_args=0..=1)]
10051005
binaries: Option<Option<PathBuf>>,
10061006

1007+
/// Don't build docker image. This assumes that the image is already built.
1008+
#[cfg(feature = "kubernetes")]
1009+
#[arg(long, default_value = "false")]
1010+
no_build: bool,
1011+
1012+
/// The name of the docker image to use.
1013+
#[cfg(feature = "kubernetes")]
1014+
#[arg(long, default_value = "linera:latest")]
1015+
docker_image_name: String,
1016+
10071017
/// Run with a specific path where the wallet and validator input files are.
10081018
/// If none, then a temporary directory is created.
10091019
#[arg(long)]

linera-service/src/cli_wrappers/docker.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl DockerImage {
1717
&self.name
1818
}
1919

20-
pub async fn build(name: String, binaries: &BuildArg, github_root: &PathBuf) -> Result<Self> {
20+
pub async fn build(name: &String, binaries: &BuildArg, github_root: &PathBuf) -> Result<Self> {
2121
let build_arg = match binaries {
2222
BuildArg::Directory(bin_path) => {
2323
// Get the binaries from the specified path
@@ -73,12 +73,7 @@ impl DockerImage {
7373
),
7474
]);
7575

76-
command
77-
.arg(".")
78-
.args(["-t", &name])
79-
.spawn_and_wait()
80-
.await?;
81-
76+
command.arg(".").args(["-t", name]).spawn_and_wait().await?;
8277
Ok(docker_image)
8378
}
8479
}

linera-service/src/cli_wrappers/local_kubernetes_net.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ pub struct LocalKubernetesNetConfig {
4646
pub num_initial_validators: usize,
4747
pub num_shards: usize,
4848
pub binaries: BuildArg,
49+
pub no_build: bool,
50+
pub docker_image_name: String,
4951
pub policy: ResourceControlPolicy,
5052
}
5153

@@ -62,6 +64,8 @@ pub struct LocalKubernetesNet {
6264
next_client_id: usize,
6365
tmp_dir: Arc<TempDir>,
6466
binaries: BuildArg,
67+
no_build: bool,
68+
docker_image_name: String,
6569
kubectl_instance: Arc<Mutex<KubectlInstance>>,
6670
kind_clusters: Vec<KindCluster>,
6771
num_initial_validators: usize,
@@ -96,6 +100,8 @@ impl SharedLocalKubernetesNetTestingConfig {
96100
num_initial_validators: 4,
97101
num_shards: 4,
98102
binaries,
103+
no_build: false,
104+
docker_image_name: String::from("linera:latest"),
99105
policy: ResourceControlPolicy::devnet(),
100106
})
101107
}
@@ -122,6 +128,8 @@ impl LineraNetConfig for LocalKubernetesNetConfig {
122128
self.network,
123129
self.testing_prng_seed,
124130
self.binaries,
131+
self.no_build,
132+
self.docker_image_name,
125133
KubectlInstance::new(Vec::new()),
126134
clusters,
127135
self.num_initial_validators,
@@ -300,10 +308,13 @@ impl LineraNet for LocalKubernetesNet {
300308
}
301309

302310
impl LocalKubernetesNet {
311+
#[allow(clippy::too_many_arguments)]
303312
fn new(
304313
network: Network,
305314
testing_prng_seed: Option<u64>,
306315
binaries: BuildArg,
316+
no_build: bool,
317+
docker_image_name: String,
307318
kubectl_instance: KubectlInstance,
308319
kind_clusters: Vec<KindCluster>,
309320
num_initial_validators: usize,
@@ -315,6 +326,8 @@ impl LocalKubernetesNet {
315326
next_client_id: 0,
316327
tmp_dir: Arc::new(tempdir()?),
317328
binaries,
329+
no_build,
330+
docker_image_name,
318331
kubectl_instance: Arc::new(Mutex::new(kubectl_instance)),
319332
kind_clusters,
320333
num_initial_validators,
@@ -394,8 +407,12 @@ impl LocalKubernetesNet {
394407
async fn run(&mut self) -> Result<()> {
395408
let github_root = get_github_root().await?;
396409
// Build Docker image
397-
let docker_image =
398-
DockerImage::build(String::from("linera:latest"), &self.binaries, &github_root).await?;
410+
let docker_image_name = if self.no_build {
411+
self.docker_image_name.clone()
412+
} else {
413+
DockerImage::build(&self.docker_image_name, &self.binaries, &github_root).await?;
414+
self.docker_image_name.clone()
415+
};
399416

400417
let base_dir = github_root
401418
.join("kubernetes")
@@ -412,13 +429,13 @@ impl LocalKubernetesNet {
412429

413430
let mut validators_initialization_futures = Vec::new();
414431
for (i, kind_cluster) in self.kind_clusters.iter().cloned().enumerate() {
415-
let docker_image_name = docker_image.name().to_string();
416432
let base_dir = base_dir.clone();
417433
let github_root = github_root.clone();
418434

419435
let kubectl_instance = kubectl_instance_clone.clone();
420436
let tmp_dir_path = tmp_dir_path_clone.clone();
421437

438+
let docker_image_name = docker_image_name.clone();
422439
let future = async move {
423440
let cluster_id = kind_cluster.id();
424441
kind_cluster.load_docker_image(&docker_image_name).await?;

linera-service/src/linera/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,8 @@ async fn run(options: &ClientOptions) -> Result<i32, anyhow::Error> {
15921592
policy_config,
15931593
kubernetes: true,
15941594
binaries,
1595+
no_build,
1596+
docker_image_name,
15951597
path: _,
15961598
storage: _,
15971599
external_protocol: _,
@@ -1604,6 +1606,8 @@ async fn run(options: &ClientOptions) -> Result<i32, anyhow::Error> {
16041606
*shards,
16051607
*testing_prng_seed,
16061608
binaries,
1609+
*no_build,
1610+
docker_image_name.clone(),
16071611
policy_config.into_policy(),
16081612
)
16091613
.boxed()

linera-service/src/linera/net_up_utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ pub async fn handle_net_up_kubernetes(
110110
num_shards: usize,
111111
testing_prng_seed: Option<u64>,
112112
binaries: &Option<Option<PathBuf>>,
113+
no_build: bool,
114+
docker_image_name: String,
113115
policy: ResourceControlPolicy,
114116
) -> anyhow::Result<()> {
115117
if num_initial_validators < 1 {
@@ -130,6 +132,8 @@ pub async fn handle_net_up_kubernetes(
130132
num_initial_validators,
131133
num_shards,
132134
binaries: binaries.clone().into(),
135+
no_build,
136+
docker_image_name,
133137
policy,
134138
};
135139
let (mut net, client1) = config.instantiate().await?;

0 commit comments

Comments
 (0)