diff --git a/LICENSE b/LICENSE deleted file mode 100644 index db44f24..0000000 --- a/LICENSE +++ /dev/null @@ -1,25 +0,0 @@ -The MIT License (MIT) -===================== - -Copyright © `2023` `Anton Systems` - -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the “Software”), to deal in the Software without -restriction, including without limitation the rights to use, -copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/bin/opup/src/cli.rs b/bin/opup/src/cli.rs index aa7ad65..cc01978 100644 --- a/bin/opup/src/cli.rs +++ b/bin/opup/src/cli.rs @@ -1,6 +1,7 @@ use clap::{ArgAction, Parser, Subcommand}; use eyre::Result; -use std::path::PathBuf; + +use crate::up::UpCommand; /// Command line arguments #[derive(Parser, Debug)] @@ -13,17 +14,13 @@ pub struct Args { /// The subcommand to run #[clap(subcommand)] pub command: Option, - - /// An optional path to a stack config file. - #[arg(long, short)] - config: Option, } /// Possible CLI subcommands #[derive(Debug, Subcommand)] pub enum Command { /// Build and run the devnet stack - Up, + Up(UpCommand), /// Bring the devnet stack down Down, /// Nuke the devnet stack @@ -33,17 +30,22 @@ pub enum Command { } pub fn run() -> Result<()> { - let Args { v, config, command } = Args::parse(); + let Args { v, command } = Args::parse(); crate::telemetry::init_tracing_subscriber(v)?; crate::banners::banner()?; match command { - Some(Command::Up) | None => crate::stack::Stack::new(config).run()?, - Some(Command::Down) => unimplemented!("down command not yet implemented"), - Some(Command::Nuke) => unimplemented!("nuke command not yet implemented"), - Some(Command::Clean) => unimplemented!("clean command not yet implemented"), + // If no subcommand is provided, run the Up command with default config. + None => UpCommand::new(None, false).run()?, + + Some(command) => match command { + Command::Up(up_command) => up_command.run()?, + Command::Down => unimplemented!("down command not yet implemented"), + Command::Nuke => unimplemented!("nuke command not yet implemented"), + Command::Clean => unimplemented!("clean command not yet implemented"), + }, } Ok(()) diff --git a/bin/opup/src/lib.rs b/bin/opup/src/lib.rs index 750525e..34ca6b2 100644 --- a/bin/opup/src/lib.rs +++ b/bin/opup/src/lib.rs @@ -1,9 +1,6 @@ /// The CLI entrypoint for the binary. pub mod cli; -/// Module containing stack packages. -pub mod stack; - /// Command banners. pub mod banners; @@ -12,3 +9,6 @@ pub mod telemetry; /// Runner contains asynchronous helpers for running commands. pub mod runner; + +/// The Up subcommand module that contains the logic for bringing up the stack. +pub mod up; diff --git a/bin/opup/src/stack.rs b/bin/opup/src/stack.rs deleted file mode 100644 index 32937f2..0000000 --- a/bin/opup/src/stack.rs +++ /dev/null @@ -1,43 +0,0 @@ -use bollard::Docker; -use eyre::Result; -use std::path::{Path, PathBuf}; - -use op_config::Config; -use op_stages::Stages; - -/// The Stack CLI Command. -#[derive(Debug)] -pub struct Stack { - /// An optional path to a stack config file. - pub config: Option, -} - -impl Stack { - /// Create a new Stack CLI Command. - pub fn new(config: Option) -> Self { - Self { config } - } - - /// Run the Stack CLI Command. - pub fn run(&self) -> Result<()> { - crate::runner::run_until_ctrl_c(async { - tracing::info!(target: "cli", "bootstrapping op stack"); - - // todo: remove this once we have a proper stage docker component - // for now, this placeholds use of [bollard]. - let docker = Docker::connect_with_local_defaults()?; - let version = docker.version().await?; - tracing::info!(target: "cli", "docker version: {:?}", version); - - // Get the directory of the config file if it exists. - let config_dir = self.config.as_ref().and_then(|p| p.parent()); - let config_dir = config_dir.unwrap_or_else(|| Path::new(".")); - - // Build a config from the parsed config directory. - tracing::info!(target: "cli", "Loading op-stack config from {:?}", config_dir); - let stack = Config::load_with_root(config_dir); - - Stages::from(stack).execute().await - }) - } -} diff --git a/bin/opup/src/up.rs b/bin/opup/src/up.rs new file mode 100644 index 0000000..f8441b8 --- /dev/null +++ b/bin/opup/src/up.rs @@ -0,0 +1,56 @@ +use bollard::Docker; +use clap::Args; +use eyre::Result; +use std::path::{Path, PathBuf}; + +use op_config::Config; +use op_stages::Stages; + +/// The Up CLI Subcommand. +#[derive(Debug, Args)] +pub struct UpCommand { + /// An optional path to a stack config file. + #[arg(long, short)] + pub config: Option, + + /// Whether to build a hard-coded default devnet stack, ignoring the config file. + #[arg(long, short)] + pub devnet: bool, +} + +impl UpCommand { + /// Create a new Up CLI Subcommand. + pub fn new(config: Option, devnet: bool) -> Self { + Self { config, devnet } + } + + /// Run the Up CLI Subcommand. + pub fn run(&self) -> Result<()> { + crate::runner::run_until_ctrl_c(async { + tracing::info!(target: "cli", "bootstrapping op stack"); + + // todo: remove this once we have a proper stage docker component + // for now, this placeholds use of [bollard]. + let docker = Docker::connect_with_local_defaults()?; + let version = docker.version().await?; + tracing::info!(target: "cli", "docker version: {:?}", version); + + if self.devnet { + tracing::info!(target: "cli", "Building default devnet stack"); + Stages::from(Config::default()).execute().await + } else { + // Get the directory of the config file if it exists. + let config_dir = self.config.as_ref().and_then(|p| p.parent()); + let config_dir = config_dir.unwrap_or_else(|| Path::new(".")); + + // Build a config from the parsed config directory. + tracing::info!(target: "cli", "Loading op-stack config from {:?}", config_dir); + let stack = Config::load_with_root(config_dir); + + tracing::info!(target: "cli", "Stack: {:#?}", stack); + + Stages::from(stack).execute().await + } + }) + } +} diff --git a/crates/config/tests/config.rs b/crates/config/tests/config.rs index 441fba8..ac9d0de 100644 --- a/crates/config/tests/config.rs +++ b/crates/config/tests/config.rs @@ -13,8 +13,8 @@ fn test_default_config() { assert_eq!(config.rollup_client, RollupClient::default()); assert_eq!(config.challenger, ChallengerAgent::default()); - assert_eq!(config.enable_sequencing, false); - assert_eq!(config.enable_fault_proofs, false); + assert!(!config.enable_sequencing); + assert!(!config.enable_fault_proofs); } #[test]