Skip to content

Commit 982d2bf

Browse files
committed
chore: structure box and provisioner environments.
1 parent f6ed894 commit 982d2bf

File tree

15 files changed

+188
-382
lines changed

15 files changed

+188
-382
lines changed

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

environments/core/box/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ movement-signer-loader = { workspace = true }
3535
hex = { workspace = true }
3636
mtma-types = { workspace = true }
3737
movement-core = { workspace = true }
38+
mtma-environment-types = { workspace = true }
39+
kestrel = { workspace = true }
3840

3941
[lints]
4042
workspace = true
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// Contains the configuration structs and logic for the migration.
22
pub mod config;
33
/// Contains the logic for the migration.
4-
pub mod migrate;
4+
pub mod environment;
55

66
pub use config::*;
7-
pub use migrate::*;
7+
pub use environment::*;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use crate::BoxEnvironment;
2+
use clap::Parser;
3+
use serde::{Deserialize, Serialize};
4+
use std::fmt::Debug;
5+
6+
/// Errors thrown when working with the [Config].
7+
#[derive(Debug, thiserror::Error)]
8+
pub enum EnvironmentConfigError {
9+
#[error("failed to build from config: {0}")]
10+
Build(#[source] Box<dyn std::error::Error + Send + Sync>),
11+
}
12+
13+
/// The config for the [BoxEnvironment].
14+
///
15+
/// All fields should be easily statically encodable to a CLI argument.
16+
/// This is the frontend for the core API.
17+
#[derive(Parser, Debug, Serialize, Deserialize, Clone, Default)]
18+
#[clap(help_expected = true)]
19+
pub struct Config {}
20+
21+
impl Config {
22+
/// Builds the [BoxEnvironment] struct from the config.
23+
///
24+
/// Note: preserving faillibility here because we may add debug path configuration to the [BoxEnvironment] soon.
25+
pub fn build(&self) -> Result<BoxEnvironment, EnvironmentConfigError> {
26+
Ok(BoxEnvironment::new())
27+
}
28+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
use anyhow::Context;
2+
use movement_core::Overlays;
3+
use mtma_environment_types::{EnvironmentError, Environmentish};
4+
use mtma_migrator_types::migrator::MovementMigrator;
5+
use std::fmt::Debug;
6+
7+
/// Errors thrown when using the [BoxEnvironment].
8+
#[derive(Debug, thiserror::Error)]
9+
pub enum BoxEnvironmentError {
10+
#[error("Testing Environment: failed with an internal error: {0}")]
11+
Internal(#[source] Box<dyn std::error::Error + Send + Sync>),
12+
}
13+
14+
impl From<BoxEnvironmentError> for EnvironmentError {
15+
fn from(e: BoxEnvironmentError) -> Self {
16+
EnvironmentError::Internal(e.into())
17+
}
18+
}
19+
20+
pub struct BoxEnvironment {}
21+
22+
impl BoxEnvironment {
23+
pub fn new() -> Self {
24+
Self {}
25+
}
26+
}
27+
28+
impl Environmentish for BoxEnvironment {
29+
async fn build_movement_migrator(&self) -> Result<MovementMigrator, EnvironmentError> {
30+
// Form the migrator.
31+
let mut movement_migrator =
32+
MovementMigrator::try_temp().map_err(|e| BoxEnvironmentError::Internal(e.into()))?;
33+
movement_migrator.set_overlays(Overlays::default());
34+
35+
// Start the migrator so that it's running in the background.
36+
// In the future, some migrators may be for already running nodes.
37+
let movement_migrator_for_task = movement_migrator.clone();
38+
let movement_migrator_task = kestrel::task(async move {
39+
movement_migrator_for_task.run().await?;
40+
Ok::<_, anyhow::Error>(())
41+
});
42+
43+
// wait for the rest client to be ready
44+
// once we have this, there should also be a config, so we can then kill off the migrator and proceed
45+
movement_migrator
46+
.wait_for_rest_client_ready(tokio::time::Duration::from_secs(600)) // we wait for up to ten minutes because the nix flake in .vendors/movementcan be a bit slow the first time
47+
.await
48+
.context(
49+
"failed to wait for movement migrator rest client while running accounts equal manual prelude",
50+
).map_err(|e| BoxEnvironmentError::Internal(e.into()))?;
51+
52+
kestrel::end!(movement_migrator_task)
53+
.context("failed to end movement migrator task")
54+
.map_err(|e| BoxEnvironmentError::Internal(e.into()))?;
55+
56+
Ok(movement_migrator)
57+
}
58+
}

environments/core/box/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
pub mod migrate;
2-
pub use migrate::*;
1+
pub mod environment;
2+
pub use environment::*;

environments/core/box/src/migrate/config.rs

Lines changed: 0 additions & 103 deletions
This file was deleted.

environments/core/box/src/migrate/migrate.rs

Lines changed: 0 additions & 84 deletions
This file was deleted.

environments/core/provisioner/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ movement-signer-loader = { workspace = true }
3535
hex = { workspace = true }
3636
mtma-types = { workspace = true }
3737
movement-core = { workspace = true }
38+
mtma-environment-types = { workspace = true }
39+
kestrel = { workspace = true }
3840

3941
[lints]
4042
workspace = true
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// Contains the configuration structs and logic for the migration.
22
pub mod config;
33
/// Contains the logic for the migration.
4-
pub mod migrate;
4+
pub mod environment;
55

66
pub use config::*;
7-
pub use migrate::*;
7+
pub use environment::*;

0 commit comments

Comments
 (0)