feat: Vendor pezkuwi-subxt and pezkuwi-zombienet-sdk into monorepo
- Add pezkuwi-subxt crates to vendor/pezkuwi-subxt - Add pezkuwi-zombienet-sdk crates to vendor/pezkuwi-zombienet-sdk - Convert git dependencies to path dependencies - Add vendor crates to workspace members - Remove test/example crates from vendor (not needed for SDK) - Fix feature propagation issues detected by zepter - Fix workspace inheritance for internal dependencies - All 606 crates now in workspace - All 6919 internal dependency links verified correct - No git dependencies remaining
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
//! Helpers functions to get configuration (e.g. Provider and images) from the env vars
|
||||
use std::{env, future::Future, path::PathBuf, pin::Pin};
|
||||
|
||||
use crate::{
|
||||
AttachToLive, AttachToLiveNetwork, LocalFileSystem, Network, NetworkConfig, NetworkConfigExt,
|
||||
OrchestratorError,
|
||||
};
|
||||
|
||||
const DEFAULT_POLKADOT_IMAGE: &str = "docker.io/parity/polkadot:latest";
|
||||
const DEFAULT_CUMULUS_IMAGE: &str = "docker.io/parity/polkadot-parachain:latest";
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Images {
|
||||
pub polkadot: String,
|
||||
pub cumulus: String,
|
||||
}
|
||||
|
||||
impl Images {
|
||||
/// Alias for polkadot field - returns reference to pezkuwi/polkadot image
|
||||
pub fn pezkuwi(&self) -> &str {
|
||||
&self.polkadot
|
||||
}
|
||||
|
||||
/// Alias for cumulus field - returns reference to pezcumulus/cumulus image
|
||||
pub fn pezcumulus(&self) -> &str {
|
||||
&self.cumulus
|
||||
}
|
||||
}
|
||||
|
||||
pub enum Provider {
|
||||
Native,
|
||||
K8s,
|
||||
Docker,
|
||||
}
|
||||
|
||||
impl Provider {
|
||||
pub fn get_spawn_fn(
|
||||
&self,
|
||||
) -> fn(NetworkConfig) -> Pin<Box<dyn Future<Output = SpawnResult> + Send>> {
|
||||
match self {
|
||||
Provider::Native => NetworkConfigExt::spawn_native,
|
||||
Provider::K8s => NetworkConfigExt::spawn_k8s,
|
||||
Provider::Docker => NetworkConfigExt::spawn_docker,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Use `docker` as default provider
|
||||
impl From<String> for Provider {
|
||||
fn from(value: String) -> Self {
|
||||
match value.to_ascii_lowercase().as_ref() {
|
||||
"native" => Provider::Native,
|
||||
"k8s" => Provider::K8s,
|
||||
_ => Provider::Docker, // default provider
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_images_from_env() -> Images {
|
||||
let polkadot = env::var("POLKADOT_IMAGE").unwrap_or(DEFAULT_POLKADOT_IMAGE.into());
|
||||
let cumulus = env::var("CUMULUS_IMAGE").unwrap_or(DEFAULT_CUMULUS_IMAGE.into());
|
||||
Images { polkadot, cumulus }
|
||||
}
|
||||
|
||||
pub fn get_provider_from_env() -> Provider {
|
||||
env::var("ZOMBIE_PROVIDER").unwrap_or_default().into()
|
||||
}
|
||||
|
||||
pub type SpawnResult = Result<Network<LocalFileSystem>, OrchestratorError>;
|
||||
pub fn get_spawn_fn() -> fn(NetworkConfig) -> Pin<Box<dyn Future<Output = SpawnResult> + Send>> {
|
||||
let provider = get_provider_from_env();
|
||||
|
||||
match provider {
|
||||
Provider::Native => NetworkConfigExt::spawn_native,
|
||||
Provider::K8s => NetworkConfigExt::spawn_k8s,
|
||||
Provider::Docker => NetworkConfigExt::spawn_docker,
|
||||
}
|
||||
}
|
||||
|
||||
pub type AttachResult = Result<Network<LocalFileSystem>, OrchestratorError>;
|
||||
|
||||
pub fn get_attach_fn() -> fn(PathBuf) -> Pin<Box<dyn Future<Output = AttachResult> + Send>> {
|
||||
let provider = get_provider_from_env();
|
||||
|
||||
match provider {
|
||||
Provider::Native => AttachToLiveNetwork::attach_native,
|
||||
Provider::K8s => AttachToLiveNetwork::attach_k8s,
|
||||
Provider::Docker => AttachToLiveNetwork::attach_docker,
|
||||
}
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use async_trait::async_trait;
|
||||
pub use configuration::{
|
||||
GlobalSettings, GlobalSettingsBuilder, NetworkConfig, NetworkConfigBuilder,
|
||||
RegistrationStrategy, WithRelaychain,
|
||||
};
|
||||
pub use orchestrator::{
|
||||
errors::OrchestratorError,
|
||||
network::{node::NetworkNode, Network},
|
||||
sc_chain_spec, AddCollatorOptions, AddNodeOptions, Orchestrator,
|
||||
};
|
||||
|
||||
// Helpers used for interact with the network
|
||||
pub mod tx_helper {
|
||||
pub use orchestrator::{
|
||||
network::chain_upgrade::ChainUpgrade, shared::types::RuntimeUpgradeOptions,
|
||||
};
|
||||
}
|
||||
|
||||
use provider::{DockerProvider, KubernetesProvider, NativeProvider};
|
||||
pub use support::fs::local::LocalFileSystem;
|
||||
|
||||
pub mod environment;
|
||||
pub const PROVIDERS: [&str; 3] = ["k8s", "native", "docker"];
|
||||
|
||||
// re-export pezkuwi-subxt (with subxt alias for backwards compatibility)
|
||||
pub use pezkuwi_subxt;
|
||||
pub use pezkuwi_subxt as subxt;
|
||||
pub use pezkuwi_subxt_signer;
|
||||
pub use pezkuwi_subxt_signer as subxt_signer;
|
||||
|
||||
#[async_trait]
|
||||
pub trait NetworkConfigExt {
|
||||
/// Spawns a network using the native or k8s provider.
|
||||
///
|
||||
/// # Example:
|
||||
/// ```rust
|
||||
/// # use zombienet_sdk::{NetworkConfig, NetworkConfigExt};
|
||||
/// # async fn example() -> Result<(), zombienet_sdk::OrchestratorError> {
|
||||
/// let network = NetworkConfig::load_from_toml("config.toml")?
|
||||
/// .spawn_native()
|
||||
/// .await?;
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
async fn spawn_native(self) -> Result<Network<LocalFileSystem>, OrchestratorError>;
|
||||
async fn spawn_k8s(self) -> Result<Network<LocalFileSystem>, OrchestratorError>;
|
||||
async fn spawn_docker(self) -> Result<Network<LocalFileSystem>, OrchestratorError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait AttachToLive {
|
||||
/// Attaches to a running live network using the native, docker or k8s provider.
|
||||
///
|
||||
/// # Example:
|
||||
/// ```rust
|
||||
/// # use zombienet_sdk::{AttachToLive, AttachToLiveNetwork};
|
||||
/// # use std::path::PathBuf;
|
||||
/// # async fn example() -> Result<(), zombienet_sdk::OrchestratorError> {
|
||||
/// let zombie_json_path = PathBuf::from("some/path/zombie.json");
|
||||
/// let network = AttachToLiveNetwork::attach_native(zombie_json_path).await?;
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
async fn attach_native(
|
||||
zombie_json_path: PathBuf,
|
||||
) -> Result<Network<LocalFileSystem>, OrchestratorError>;
|
||||
async fn attach_k8s(
|
||||
zombie_json_path: PathBuf,
|
||||
) -> Result<Network<LocalFileSystem>, OrchestratorError>;
|
||||
async fn attach_docker(
|
||||
zombie_json_path: PathBuf,
|
||||
) -> Result<Network<LocalFileSystem>, OrchestratorError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl NetworkConfigExt for NetworkConfig {
|
||||
async fn spawn_native(self) -> Result<Network<LocalFileSystem>, OrchestratorError> {
|
||||
let filesystem = LocalFileSystem;
|
||||
let provider = NativeProvider::new(filesystem.clone());
|
||||
let orchestrator = Orchestrator::new(filesystem, provider);
|
||||
orchestrator.spawn(self).await
|
||||
}
|
||||
|
||||
async fn spawn_k8s(self) -> Result<Network<LocalFileSystem>, OrchestratorError> {
|
||||
let filesystem = LocalFileSystem;
|
||||
let provider = KubernetesProvider::new(filesystem.clone()).await;
|
||||
let orchestrator = Orchestrator::new(filesystem, provider);
|
||||
orchestrator.spawn(self).await
|
||||
}
|
||||
|
||||
async fn spawn_docker(self) -> Result<Network<LocalFileSystem>, OrchestratorError> {
|
||||
let filesystem = LocalFileSystem;
|
||||
let provider = DockerProvider::new(filesystem.clone()).await;
|
||||
let orchestrator = Orchestrator::new(filesystem, provider);
|
||||
orchestrator.spawn(self).await
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AttachToLiveNetwork;
|
||||
|
||||
#[async_trait]
|
||||
impl AttachToLive for AttachToLiveNetwork {
|
||||
async fn attach_native(
|
||||
zombie_json_path: PathBuf,
|
||||
) -> Result<Network<LocalFileSystem>, OrchestratorError> {
|
||||
let filesystem = LocalFileSystem;
|
||||
let provider = NativeProvider::new(filesystem.clone());
|
||||
let orchestrator = Orchestrator::new(filesystem, provider);
|
||||
orchestrator.attach_to_live(zombie_json_path.as_ref()).await
|
||||
}
|
||||
|
||||
async fn attach_k8s(
|
||||
zombie_json_path: PathBuf,
|
||||
) -> Result<Network<LocalFileSystem>, OrchestratorError> {
|
||||
let filesystem = LocalFileSystem;
|
||||
let provider = KubernetesProvider::new(filesystem.clone()).await;
|
||||
let orchestrator = Orchestrator::new(filesystem, provider);
|
||||
orchestrator.attach_to_live(zombie_json_path.as_ref()).await
|
||||
}
|
||||
|
||||
async fn attach_docker(
|
||||
zombie_json_path: PathBuf,
|
||||
) -> Result<Network<LocalFileSystem>, OrchestratorError> {
|
||||
let filesystem = LocalFileSystem;
|
||||
let provider = DockerProvider::new(filesystem.clone()).await;
|
||||
let orchestrator = Orchestrator::new(filesystem, provider);
|
||||
orchestrator.attach_to_live(zombie_json_path.as_ref()).await
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user