Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into steph-s/devnet-run
Browse files Browse the repository at this point in the history
  • Loading branch information
steph-rs committed Oct 11, 2023
2 parents 43251e9 + f160592 commit 2e0fc32
Show file tree
Hide file tree
Showing 20 changed files with 331 additions and 151 deletions.
47 changes: 47 additions & 0 deletions Cargo.lock

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

25 changes: 0 additions & 25 deletions LICENSE

This file was deleted.

46 changes: 34 additions & 12 deletions bin/opup/src/cli.rs
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(())
}
6 changes: 3 additions & 3 deletions bin/opup/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
43 changes: 0 additions & 43 deletions bin/opup/src/stack.rs

This file was deleted.

56 changes: 56 additions & 0 deletions bin/opup/src/up.rs
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
}
})
}
}
2 changes: 2 additions & 0 deletions crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ tracing.workspace = true
hex-literal.workspace = true
once_cell.workspace = true

typetag = "0.2.13"
Inflector = "0.11.4"
figment = { version = "0.10", features = ["toml", "env"] }
toml = { version = "0.8.1", features = ["preserve_order"] }
Expand All @@ -36,3 +37,4 @@ dirs-next = "2"
pretty_assertions = "1"
figment = { version = "0.10", features = ["test"] }
tempfile = "3"
temp_testdir = "0.2.3"
39 changes: 17 additions & 22 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,28 @@
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

/// OP Stack [Config].
/// Stack Configuration
///
/// The [stack] module contains the core [Config] struct which is
/// responsible for holding the configuration of the OP stack.
///
/// ## Example
///
/// ```rust
/// use std::path::PathBuf;
/// use op_config::Config;
///
/// let config = Config::default();
/// assert_eq!(config.artifacts, PathBuf::from(Config::STACK_DIR_NAME));
/// ```
pub mod stack;
pub use stack::*;

/// [StageConfig] is a [figment::Provider] that holds the [Stage] configuration.
pub mod stage;
pub use stage::*;
pub mod stages;

/// Convenience [figment::Error] wrapper.
/// Uses a custom [OpStackConfigError] under the hood.
pub mod error;

/// Holds a [figment::Provider] that is used to retrieve a toml file.
pub mod toml;

/// Renames the [figment::Provider] `from` key to `to`.
pub mod rename;

/// Wraps a profile increasing the key depth.
pub mod wraps;

/// Extends a [figment::Provider] by warning about deprecated profile key usage.
pub mod optional;

/// Unwraps a profile reducing the key depth.
pub mod unwraps;
/// Providers are [figment::Provider]s used to retrieve configuration.
pub mod providers;

/// A wrapper for the root path used during toml config detection.
pub mod root;
pub use root::*;
File renamed without changes.
18 changes: 18 additions & 0 deletions crates/config/src/providers/mod.rs
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;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use figment::{
Error, Figment, Metadata, Profile, Provider,
};

use crate::unwraps::UnwrapProfileProvider;
use super::unwraps::UnwrapProfileProvider;

/// Extracts the profile from the `profile` key and using the original key as backup, merging
/// values where necessary
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 2e0fc32

Please sign in to comment.