Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement bootstrap in meroctl #1016

Merged
merged 13 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ dist/
lib/
node_modules/
certs/
output/*
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/meroctl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "meroctl"
version = "0.2.0"
version = "0.2.1"
authors.workspace = true
edition.workspace = true
repository.workspace = true
Expand All @@ -20,6 +20,7 @@ eyre.workspace = true
futures-util.workspace = true
libp2p.workspace = true
notify.workspace = true
rand.workspace = true
reqwest = { workspace = true, features = ["json"] }
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
Expand Down
14 changes: 14 additions & 0 deletions crates/meroctl/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::process::ExitCode;

use bootstrap::BootstrapCommand;
use camino::Utf8PathBuf;
use clap::{Parser, Subcommand};
use const_format::concatcp;
Expand All @@ -11,6 +12,7 @@ use crate::defaults;
use crate::output::{Format, Output, Report};

mod app;
mod bootstrap;
mod call;
mod context;
mod identity;
Expand Down Expand Up @@ -54,6 +56,7 @@ pub enum SubCommands {
JsonRpc(CallCommand),
Proxy(ProxyCommand),
Call(CallCommand),
Bootstrap(BootstrapCommand),
}

#[derive(Debug, Parser)]
Expand All @@ -71,6 +74,16 @@ pub struct RootArgs {
pub output_format: Format,
}

impl RootArgs {
pub const fn new(home: Utf8PathBuf, node_name: String, output_format: Format) -> Self {
Self {
home,
node_name,
output_format,
}
}
}

pub struct Environment {
pub args: RootArgs,
pub output: Output,
Expand All @@ -94,6 +107,7 @@ impl RootCommand {
SubCommands::JsonRpc(jsonrpc) => jsonrpc.run(&environment).await,
SubCommands::Proxy(proxy) => proxy.run(&environment).await,
SubCommands::Call(call) => call.run(&environment).await,
SubCommands::Bootstrap(call) => call.run(&environment).await,
};

if let Err(err) = result {
Expand Down
2 changes: 1 addition & 1 deletion crates/meroctl/src/cli/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::cli::Environment;
use crate::output::Report;

mod get;
mod install;
pub mod install;
mod list;

pub const EXAMPLES: &str = r"
Expand Down
9 changes: 8 additions & 1 deletion crates/meroctl/src/cli/app/install.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use calimero_primitives::application::ApplicationId;
use calimero_primitives::hash::Hash;
use calimero_server_primitives::admin::{
InstallApplicationRequest, InstallApplicationResponse, InstallDevApplicationRequest,
Expand Down Expand Up @@ -36,6 +37,12 @@ impl Report for InstallApplicationResponse {

impl InstallCommand {
pub async fn run(self, environment: &Environment) -> Result<()> {
let _ignored = self.install_app(environment).await;

Ok(())
}

pub async fn install_app(self, environment: &Environment) -> Result<ApplicationId> {
let config = load_config(&environment.args.home, &environment.args.node_name)?;
let mut is_dev_installation = false;
let metadata = self.metadata.map(String::into_bytes).unwrap_or_default();
Expand Down Expand Up @@ -76,6 +83,6 @@ impl InstallCommand {

environment.output.write(&response);

Ok(())
Ok(response.data.application_id)
}
}
41 changes: 41 additions & 0 deletions crates/meroctl/src/cli/bootstrap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use clap::{Parser, Subcommand};
use const_format::concatcp;
use eyre::Result as EyreResult;
use start::StartBootstrapCommand;

use super::Environment;

mod start;

pub const EXAMPLES: &str = r"
# Setup and run 2 nodes with demo app
$ meroctl -- --node-name node1 bootstrap start --merod-path /path/to/merod
MatejVukosav marked this conversation as resolved.
Show resolved Hide resolved

# Setup and run 2 nodes with provided app
$ meroctl -- --node-name node1 bootstrap start --merod-path /path/to/merod --app-path /path/to/app

";

#[derive(Debug, Parser)]
#[command(about = "Command for starting bootstrap")]
#[command(after_help = concatcp!(
"Examples:",
EXAMPLES
))]
pub struct BootstrapCommand {
#[command(subcommand)]
pub subcommand: BootstrapSubCommands,
}

#[derive(Debug, Subcommand)]
pub enum BootstrapSubCommands {
Start(StartBootstrapCommand),
}

impl BootstrapCommand {
pub async fn run(self, environment: &Environment) -> EyreResult<()> {
match self.subcommand {
BootstrapSubCommands::Start(generate) => generate.run(environment).await,
}
}
}
Loading
Loading