Skip to content

Commit abc175e

Browse files
committed
fixes to localnet purge
1 parent 23ad51c commit abc175e

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

tools/internal/localnet-orchestrator/src/cli/purge.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use crate::cli::CommonArgs;
55
use crate::orchestrator::LocalnetOrchestrator;
66
use crate::orchestrator::setup::purge;
7+
use clap::ArgAction;
78
use std::path::PathBuf;
89
use tracing::debug;
910

@@ -13,11 +14,11 @@ pub(crate) struct Args {
1314
common: CommonArgs,
1415

1516
/// Remove any built docker and container images
16-
#[clap(long, default_value_t = true)]
17+
#[clap(long, action = ArgAction::Set, default_value_t = true)]
1718
remove_images: bool,
1819

1920
/// Remove any cached build data
20-
#[clap(long, default_value_t = true)]
21+
#[clap(long, action = ArgAction::Set, default_value_t = true)]
2122
remove_cache: bool,
2223

2324
/// Custom path to root of the monorepo in case this binary has been executed from a different location.

tools/internal/localnet-orchestrator/src/orchestrator/setup/purge.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Copyright 2025 - Nym Technologies SA <[email protected]>
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use crate::constants::LOCALNET_NYXD_IMAGE_NAME;
54
use crate::helpers::monorepo_root_path;
65
use crate::orchestrator::LocalnetOrchestrator;
76
use crate::orchestrator::container_helpers::{
87
default_nym_binaries_image_tag, remove_container_image,
98
};
109
use crate::orchestrator::context::LocalnetContext;
10+
use anyhow::Context;
1111
use std::path::PathBuf;
1212

1313
struct LocalnetPurge {
@@ -41,12 +41,16 @@ impl LocalnetOrchestrator {
4141
) -> anyhow::Result<()> {
4242
ctx.begin_next_step("removing all built images", "🔥");
4343
if !ctx.data.remove_images {
44-
ctx.println("\t NOT ENABLED - SKIPPING")
44+
ctx.println("\t NOT ENABLED - SKIPPING");
45+
return Ok(());
4546
}
4647

4748
let nym_binaries_tag = default_nym_binaries_image_tag(&ctx.data.monorepo_root)?;
4849

49-
for tag in [nym_binaries_tag, LOCALNET_NYXD_IMAGE_NAME.to_string()] {
50+
// TODO: we need to dynamically determine tag for this
51+
// LOCALNET_NYXD_IMAGE_NAME.to_string()
52+
53+
for tag in [nym_binaries_tag] {
5054
ctx.execute_cmd_with_stdout("docker", ["image", "rm", &tag])
5155
.await?;
5256
remove_container_image(ctx, &tag).await?;
@@ -58,7 +62,8 @@ impl LocalnetOrchestrator {
5862
fn remove_build_cache(&self, ctx: &mut LocalnetContext<LocalnetPurge>) -> anyhow::Result<()> {
5963
ctx.begin_next_step("removing build cache", "🔥");
6064
if !ctx.data.remove_cache {
61-
ctx.println("\t NOT ENABLED - SKIPPING")
65+
ctx.println("\t NOT ENABLED - SKIPPING");
66+
return Ok(());
6267
}
6368

6469
self.storage.data_cache().clear()
@@ -70,17 +75,18 @@ impl LocalnetOrchestrator {
7075
) -> anyhow::Result<()> {
7176
ctx.begin_next_step("removing storage data", "🔥");
7277

73-
std::fs::remove_dir_all(self.storage.localnet_directory())?;
78+
std::fs::remove_dir_all(self.storage.localnet_directory())
79+
.context("missing main storage directory")?;
7480
let storage_db = self.storage.into_orchestrator_storage();
7581
let db_path = storage_db.stop().await?;
76-
std::fs::remove_dir_all(db_path)?;
82+
std::fs::remove_file(db_path).context("missing database path")?;
7783

7884
Ok(())
7985
}
8086

8187
pub(crate) async fn purge_localnet(self, config: Config) -> anyhow::Result<()> {
8288
let purge = LocalnetPurge::new(config)?;
83-
let mut ctx = LocalnetContext::new(purge, 4, "\npurging localnet");
89+
let mut ctx = LocalnetContext::new(purge, 3, "\npurging localnet");
8490

8591
// 1. stop the localnet
8692
self.stop_localnet().await?;

tools/internal/localnet-orchestrator/src/serde_helpers/linux.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ impl TryFrom<ContainersList> for super::ContainersList {
8484
containers: value
8585
.0
8686
.into_iter()
87+
.filter(|c| c.names.contains("localnet"))
8788
.map(TryInto::try_into)
8889
.collect::<anyhow::Result<Vec<_>>>()?,
8990
})

tools/internal/localnet-orchestrator/src/serde_helpers/macos.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ impl TryFrom<ContainersList> for super::ContainersList {
1818
containers: value
1919
.0
2020
.into_iter()
21+
.filter(|c| c.configuration.id.contains("localnet"))
2122
.map(TryInto::try_into)
2223
.collect::<anyhow::Result<Vec<_>>>()?,
2324
})
@@ -138,12 +139,23 @@ pub struct ContainerNetwork {
138139
impl TryFrom<ContainerInformation> for PlaceholderCommonContainerInformation {
139140
type Error = anyhow::Error;
140141

142+
#[track_caller]
141143
fn try_from(value: ContainerInformation) -> Result<Self, Self::Error> {
144+
let status = value.status.to_lowercase();
145+
let ip_address = if status == "running" {
146+
Some(value.container_ip().context(format!(
147+
"invalid container {} ({})",
148+
value.configuration.id, value.configuration.image.reference
149+
))?)
150+
} else {
151+
None
152+
};
153+
142154
Ok(PlaceholderCommonContainerInformation {
143-
ip_address: Some(value.container_ip()?),
155+
ip_address,
144156
name: value.configuration.id,
145157
image: value.configuration.image.reference,
146-
status: value.status.to_lowercase(),
158+
status,
147159
})
148160
}
149161
}

0 commit comments

Comments
 (0)