Skip to content

Commit

Permalink
feat: alias clarinet integrate to devnet start (#1244)
Browse files Browse the repository at this point in the history
* integrate is now 'devnet start'

* add --package flag temporarily

* add --package flag to devnet start

* add integrate warning on use

* change integrate references in docs

* fmt

* move DevnetStart stuff in proximity

* conflict with other subcommands

* fix ConfigurationPackage load

* better description for --package
  • Loading branch information
tippenein committed Nov 23, 2023
1 parent d77d27e commit 28ae908
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 116 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ You can use Clarinet to deploy your contracts to your own local offline environm
evaluation on a blockchain by using the following command:

```bash
clarinet integrate
clarinet devnet start
```

**Note** Make sure you have a working installation of Docker running locally.
Expand Down Expand Up @@ -474,7 +474,7 @@ trusted_caller = false
callee_filter = false
```

As a next step we can generate a deployment plan for this project. If you are running `clarinet integrate` for the first time, this file should be created by Clarinet. In addition, you can run `clarinet deployment generate --devnet` to create or overwrite the file.
As a next step we can generate a deployment plan for this project. If you are running `clarinet devnet start` for the first time, this file should be created by Clarinet. In addition, you can run `clarinet deployment generate --devnet` to create or overwrite the file.

```yaml
---
Expand Down Expand Up @@ -680,7 +680,7 @@ This same file may also be used for customizing the subnet-node (miner, etc).
When running the command:

```bash
clarinet integrate
clarinet devnet start
```

Clarinet will spin-up a subnet node. More documentation on how to use and interact with this incoming L2 can be found on the [Hyperchain repository](https://github.com/hirosystems/stacks-subnets).
Expand Down
2 changes: 1 addition & 1 deletion components/clarinet-cli/examples/cbtc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This protocol was meant to illustrate possible interactions between Bitcoin and
Start a local Devnet with the command:

```bash
clarinet integrate
clarinet devnet start
```

In another console, change the directory to `./serverless/`. After running
Expand Down
1 change: 0 additions & 1 deletion components/clarinet-cli/src/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ mod deployments;
mod devnet;
mod frontend;
mod generate;
pub mod integrate;
mod lsp;

use frontend::cli;
Expand Down
1 change: 1 addition & 0 deletions components/clarinet-cli/src/devnet/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod package;
pub mod start;
4 changes: 2 additions & 2 deletions components/clarinet-cli/src/devnet/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use clarinet_files::chainhook_types::StacksNetwork;
use clarinet_files::{NetworkManifest, ProjectManifest};

#[derive(Serialize, Deserialize, Debug)]
struct ConfigurationPackage {
deployment_plan: DeploymentSpecification,
pub struct ConfigurationPackage {
pub deployment_plan: DeploymentSpecification,
network_manifest: NetworkManifest,
project_manifest: ProjectManifest,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use stacks_network::{
};
use std::fs::OpenOptions;

pub fn run_devnet(
pub fn start(
devnet: DevnetOrchestrator,
deployment: DeploymentSpecification,
log_tx: Option<Sender<LogData>>,
Expand Down
240 changes: 134 additions & 106 deletions components/clarinet-cli/src/frontend/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use crate::deployments::{
self, check_deployments, generate_default_deployment, get_absolute_deployment_path,
write_deployment,
};
use crate::devnet::package as Package;
use crate::devnet::package::{self as Package, ConfigurationPackage};
use crate::devnet::start::start;
use crate::generate::{
self,
changes::{Changes, TOMLEdition},
};
use crate::integrate;
use crate::lsp::run_lsp;

use clap::builder::ValueParser;
Expand Down Expand Up @@ -93,7 +93,10 @@ enum Command {
Run(Run),
/// Start a local Devnet network for interacting with your contracts from your browser
#[clap(name = "integrate", bin_name = "integrate")]
Integrate(Integrate),
Integrate(DevnetStart),
/// Subcommands for Devnet usage
#[clap(subcommand, name = "devnet")]
Devnet(Devnet),
/// Get Clarity autocompletion and inline errors from your code editor (VSCode, vim, emacs, etc)
#[clap(name = "lsp", bin_name = "lsp")]
LSP,
Expand All @@ -103,9 +106,18 @@ enum Command {
/// Generate shell completions scripts
#[clap(name = "completions", bin_name = "completions")]
Completions(Completions),
/// Subcommands for Devnet usage
#[clap(subcommand, name = "devnet")]
Devnet(Devnet),
}

#[derive(Subcommand, PartialEq, Clone, Debug)]
#[clap(bin_name = "devnet")]
enum Devnet {
/// Generate package of all required devnet artifacts
#[clap(name = "package", bin_name = "package")]
Package(DevnetPackage),

/// Start a local Devnet network for interacting with your contracts from your browser
#[clap(name = "start", bin_name = "start")]
DevnetStart(DevnetStart),
}

#[derive(Subcommand, PartialEq, Clone, Debug)]
Expand Down Expand Up @@ -154,14 +166,6 @@ enum Chainhooks {
DeployChainhook(DeployChainhook),
}

#[derive(Subcommand, PartialEq, Clone, Debug)]
#[clap(bin_name = "devnet")]
enum Devnet {
/// Generate package of all required devnet artifacts
#[clap(name = "package", bin_name = "package")]
Package(DevnetPackage),
}

#[derive(Parser, PartialEq, Clone, Debug)]
struct DevnetPackage {
/// Output json file name
Expand Down Expand Up @@ -398,7 +402,7 @@ struct Console {
}

#[derive(Parser, PartialEq, Clone, Debug)]
struct Integrate {
struct DevnetStart {
/// Path to Clarinet.toml
#[clap(long = "manifest-path", short = 'm')]
pub manifest_path: Option<String>,
Expand All @@ -422,6 +426,13 @@ struct Integrate {
conflicts_with = "use-on-disk-deployment-plan"
)]
pub use_computed_deployment_plan: bool,
/// Path to Package.json produced by 'clarinet devnet package'
#[clap(
long = "package",
conflicts_with = "use-computed-deployment-plan",
conflicts_with = "manifest-path"
)]
pub package: Option<String>,
}

#[derive(Parser, PartialEq, Clone, Debug)]
Expand Down Expand Up @@ -1213,97 +1224,11 @@ pub fn main() {
std::process::exit(exit_code);
}
Command::Integrate(cmd) => {
let manifest = load_manifest_or_exit(cmd.manifest_path);
println!("Computing deployment plan");
let result = match cmd.deployment_plan_path {
None => {
let res = load_deployment_if_exists(
&manifest,
&StacksNetwork::Devnet,
cmd.use_on_disk_deployment_plan,
cmd.use_computed_deployment_plan,
);
match res {
Some(Ok(deployment)) => {
println!(
"{} using existing deployments/default.devnet-plan.yaml",
yellow!("note:")
);
// TODO(lgalabru): Think more about the desired DX.
// Compute the latest version, display differences and propose overwrite?
Ok(deployment)
}
Some(Err(e)) => Err(e),
None => {
let default_deployment_path =
get_default_deployment_path(&manifest, &StacksNetwork::Devnet)
.unwrap();
let (deployment, _) = match generate_default_deployment(
&manifest,
&StacksNetwork::Devnet,
false,
) {
Ok(deployment) => deployment,
Err(message) => {
println!("{}", red!(message));
std::process::exit(1);
}
};
let res = write_deployment(&deployment, &default_deployment_path, true);
if let Err(message) = res {
Err(message)
} else {
println!(
"{} {}",
green!("Generated file"),
default_deployment_path.get_relative_location().unwrap()
);
Ok(deployment)
}
}
}
}
Some(deployment_plan_path) => {
let deployment_path =
get_absolute_deployment_path(&manifest, &deployment_plan_path)
.expect("unable to retrieve deployment");
load_deployment(&manifest, &deployment_path)
}
};

let deployment = match result {
Ok(deployment) => deployment,
Err(e) => {
println!("{}", format_err!(e));
std::process::exit(1);
}
};

let orchestrator = match DevnetOrchestrator::new(manifest, None, None, true) {
Ok(orchestrator) => orchestrator,
Err(e) => {
println!("{}", format_err!(e));
process::exit(1);
}
};

if orchestrator.manifest.project.telemetry {
#[cfg(feature = "telemetry")]
telemetry_report_event(DeveloperUsageEvent::DevnetExecuted(
DeveloperUsageDigest::new(
&orchestrator.manifest.project.name,
&orchestrator.manifest.project.authors,
),
));
}
if let Err(e) = integrate::run_devnet(orchestrator, deployment, None, !cmd.no_dashboard)
{
println!("{}", format_err!(e));
process::exit(1);
}
if global_settings.enable_hints.unwrap_or(true) {
display_deploy_hint();
}
println!(
"{}",
format_warn!("This command is deprecated. Use 'clarinet devnet start' instead"),
);
devnet_start(cmd, global_settings)
}
Command::LSP => run_lsp(),
Command::DAP => match super::dap::run_dap() {
Expand Down Expand Up @@ -1341,6 +1266,7 @@ pub fn main() {
process::exit(1);
}
}
Devnet::DevnetStart(cmd) => devnet_start(cmd, global_settings),
},

Command::Test(_) => {
Expand Down Expand Up @@ -1870,3 +1796,105 @@ fn display_deploy_hint() {
);
display_hint_footer();
}

fn devnet_start(cmd: DevnetStart, global_settings: GlobalSettings) -> () {
let manifest = load_manifest_or_exit(cmd.manifest_path);
println!("Computing deployment plan");
let result = match cmd.deployment_plan_path {
None => {
let res = if let Some(package) = cmd.package {
let package_file = match File::open(&package) {
Ok(file) => file,
Err(_) => {
println!("{} package file not found", red!("error:"));
std::process::exit(1);
}
};
let deployment: ConfigurationPackage = serde_json::from_reader(package_file)
.expect("error while reading deployment specification");
Some(Ok(deployment.deployment_plan))
} else {
load_deployment_if_exists(
&manifest,
&StacksNetwork::Devnet,
cmd.use_on_disk_deployment_plan,
cmd.use_computed_deployment_plan,
)
};
match res {
Some(Ok(deployment)) => {
println!(
"{} using existing deployments/default.devnet-plan.yaml",
yellow!("note:")
);
// TODO(lgalabru): Think more about the desired DX.
// Compute the latest version, display differences and propose overwrite?
Ok(deployment)
}
Some(Err(e)) => Err(e),
None => {
let default_deployment_path =
get_default_deployment_path(&manifest, &StacksNetwork::Devnet).unwrap();
let (deployment, _) =
match generate_default_deployment(&manifest, &StacksNetwork::Devnet, false)
{
Ok(deployment) => deployment,
Err(message) => {
println!("{}", red!(message));
std::process::exit(1);
}
};
let res = write_deployment(&deployment, &default_deployment_path, true);
if let Err(message) = res {
Err(message)
} else {
println!(
"{} {}",
green!("Generated file"),
default_deployment_path.get_relative_location().unwrap()
);
Ok(deployment)
}
}
}
}
Some(deployment_plan_path) => {
let deployment_path = get_absolute_deployment_path(&manifest, &deployment_plan_path)
.expect("unable to retrieve deployment");
load_deployment(&manifest, &deployment_path)
}
};

let deployment = match result {
Ok(deployment) => deployment,
Err(e) => {
println!("{}", format_err!(e));
std::process::exit(1);
}
};

let orchestrator = match DevnetOrchestrator::new(manifest, None, None, true) {
Ok(orchestrator) => orchestrator,
Err(e) => {
println!("{}", format_err!(e));
process::exit(1);
}
};

if orchestrator.manifest.project.telemetry {
#[cfg(feature = "telemetry")]
telemetry_report_event(DeveloperUsageEvent::DevnetExecuted(
DeveloperUsageDigest::new(
&orchestrator.manifest.project.name,
&orchestrator.manifest.project.authors,
),
));
}
if let Err(e) = start(orchestrator, deployment, None, !cmd.no_dashboard) {
println!("{}", format_err!(e));
process::exit(1);
}
if global_settings.enable_hints.unwrap_or(true) {
display_deploy_hint();
}
}
1 change: 0 additions & 1 deletion components/clarinet-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ pub extern crate clarity_repl;

pub mod deployments;
pub mod generate;
pub mod integrate;

pub mod devnet;
#[cfg(feature = "cli")]
Expand Down
2 changes: 1 addition & 1 deletion components/clarinet-deployments/src/onchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ pub fn apply_on_chain_deployment(
let epoch = match batch_spec.epoch {
Some(epoch) => {
if network != StacksNetwork::Devnet {
println!("warning: 'epoch' specified for a deployment batch is ignored when applying a deployment plan. This field should only be specified for deployments plans used to launch a devnet with 'clarinet integrate'.");
println!("warning: 'epoch' specified for a deployment batch is ignored when applying a deployment plan. This field should only be specified for deployments plans used to launch a devnet with 'clarinet devnet start'.");
}
epoch
}
Expand Down

0 comments on commit 28ae908

Please sign in to comment.