Skip to content

Commit

Permalink
add docker startup logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ratankaliani committed Sep 4, 2024
1 parent d4ddbb1 commit ba430fd
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions proposer/succinct/bin/cost_estimator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::{
env, fs,
future::Future,
path::PathBuf,
process::Command,
time::Instant,
};
use tokio::task::block_in_place;
Expand Down Expand Up @@ -290,17 +291,58 @@ fn aggregate_execution_stats(execution_stats: &[ExecutionStats]) -> ExecutionSta
aggregate_stats
}

/// Build and manage the Docker container for the span batch server.
fn manage_span_batch_server_container() -> Result<()> {
// Build the Docker container if it doesn't exist.
let build_status = Command::new("docker")
.args(&[

Check failure on line 298 in proposer/succinct/bin/cost_estimator.rs

View workflow job for this annotation

GitHub Actions / Formatting & Clippy

the borrowed expression implements the required traits
"build",
"-t",
"span_batch_server",
"-f",
"proposer/op/Dockerfile.span_batch_server",
".",
])
.status()?;
if !build_status.success() {
return Err(anyhow::anyhow!("Failed to build Docker container"));
}

// Start the Docker container.
let run_status = Command::new("docker")
.args(&["run", "-p", "8080:8080", "-d", "span_batch_server"])

Check failure on line 313 in proposer/succinct/bin/cost_estimator.rs

View workflow job for this annotation

GitHub Actions / Formatting & Clippy

the borrowed expression implements the required traits
.status()?;
if !run_status.success() {
return Err(anyhow::anyhow!("Failed to start Docker container"));
}
Ok(())
}

/// Shut down Docker container.
fn shutdown_span_batch_server_container() -> Result<()> {
let stop_status = Command::new("docker").args(&["stop", "span_batch_server"]).status()?;

Check failure on line 323 in proposer/succinct/bin/cost_estimator.rs

View workflow job for this annotation

GitHub Actions / Formatting & Clippy

the borrowed expression implements the required traits
if !stop_status.success() {
return Err(anyhow::anyhow!("Failed to stop Docker container"));
}
Ok(())
}

#[tokio::main]
async fn main() -> Result<()> {
dotenv::dotenv().ok();
utils::setup_logger();

let args = HostArgs::parse();
let data_fetcher = OPSuccinctDataFetcher::new();

let l2_chain_id = data_fetcher.get_chain_id(ChainMode::L2).await?;
let rollup_config = RollupConfig::from_l2_chain_id(l2_chain_id).unwrap();

// TODO: Modify fetch_span_batch_ranges to start up the Docker container and shut it down at the end of the process.
// Check if the Docker image span_batch_server exists.
manage_span_batch_server_container()?;

// TODO: Modify fetch_span_batch_ranges to start up the Docker container and shut it down at the
// end of the process.
let span_batch_ranges = get_span_batch_ranges_from_server(
&data_fetcher,
args.start,
Expand All @@ -322,5 +364,7 @@ async fn main() -> Result<()> {
let aggregate_execution_stats = aggregate_execution_stats(&execution_stats);
println!("Aggregate Execution Stats\n: {}", aggregate_execution_stats);

shutdown_span_batch_server_container()?;

Ok(())
}

0 comments on commit ba430fd

Please sign in to comment.