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(bin): up command scaffolding #38

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 0 additions & 25 deletions LICENSE

This file was deleted.

24 changes: 13 additions & 11 deletions bin/opup/src/cli.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -13,17 +14,13 @@ pub struct Args {
/// The subcommand to run
#[clap(subcommand)]
pub command: Option<Command>,

/// An optional path to a stack config file.
#[arg(long, short)]
config: Option<PathBuf>,
}

/// 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
Expand All @@ -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(())
Expand Down
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
}
})
}
}
4 changes: 2 additions & 2 deletions crates/config/tests/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down