-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into steph-s/devnet-run
- Loading branch information
Showing
20 changed files
with
331 additions
and
151 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,52 @@ | ||
use clap::{ArgAction, Parser}; | ||
use clap::{ArgAction, Parser, Subcommand}; | ||
use eyre::Result; | ||
use std::path::PathBuf; | ||
|
||
use crate::up::UpCommand; | ||
|
||
/// Command line arguments | ||
#[derive(Parser, Debug)] | ||
#[command(author, version, about)] | ||
#[command(author, version, about, long_about = None)] | ||
pub struct Args { | ||
/// Verbosity level (0-4) | ||
#[arg(long, short, action = ArgAction::Count, default_value = "2")] | ||
v: u8, | ||
/// An optional path to a stack config file. | ||
#[arg(long, short)] | ||
config: Option<PathBuf>, | ||
|
||
/// The subcommand to run | ||
#[clap(subcommand)] | ||
pub command: Option<Command>, | ||
} | ||
|
||
/// Possible CLI subcommands | ||
#[derive(Debug, Subcommand)] | ||
pub enum Command { | ||
/// Build and run the devnet stack | ||
Up(UpCommand), | ||
/// Bring the devnet stack down | ||
Down, | ||
/// Nuke the devnet stack | ||
Nuke, | ||
/// Clean all stack artifacts | ||
Clean, | ||
} | ||
|
||
pub fn run() -> Result<()> { | ||
let Args { v, config } = Args::parse(); | ||
let Args { v, command } = Args::parse(); | ||
|
||
crate::telemetry::init_tracing_subscriber(v)?; | ||
|
||
crate::banners::banner()?; | ||
|
||
// todo: switch on subcommands | ||
// default should be to run the devnet stack | ||
// should also allow nuking the devnet | ||
// and stopping an already running devnet | ||
match command { | ||
// 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"), | ||
}, | ||
} | ||
|
||
crate::stack::Stack::new(config).run() | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<PathBuf>, | ||
|
||
/// 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<PathBuf>, 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 | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/// Convenience [figment::Error] wrapper. | ||
/// Uses a custom [OpStackConfigError] under the hood. | ||
pub mod error; | ||
|
||
/// Extends a [figment::Provider] by warning about deprecated profile key usage. | ||
pub mod optional; | ||
|
||
/// Renames the [figment::Provider] `from` key to `to`. | ||
pub mod rename; | ||
|
||
/// Holds a [figment::Provider] that is used to retrieve a toml file. | ||
pub mod toml; | ||
|
||
/// Unwraps a profile reducing the key depth. | ||
pub mod unwraps; | ||
|
||
/// Wraps a profile increasing the key depth. | ||
pub mod wraps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.