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: first docker container running #67

Merged
merged 8 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions bin/opup/src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ impl DependencyManager {
return Ok(());
}
let version = semver::Version::parse("0.8.17")?;
tracing::info!("Installing Solidity version {:?}", version);
tracing::info!("Installing Solidity version {}", version);
let _ = svm_lib::install(&version).await?;
tracing::info!("Solidity version {:?} installed", version);
svm_lib::use_version(&version)?;
refcell marked this conversation as resolved.
Show resolved Hide resolved
tracing::info!("Solidity version {} installed", version);
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion bin/opup/src/up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl UpCommand {
}

/// Entrypoint
#[instrument(name = "up", target = "run")]
#[instrument(name = "up", target = "run", skip(self))]
pub fn run(&self) -> Result<()> {
crate::runner::run_until_ctrl_c(async { self.execute().await })
}
Expand Down
29 changes: 22 additions & 7 deletions crates/composer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ use bollard::{
StartContainerOptions, StopContainerOptions,
},
exec::{CreateExecOptions, StartExecResults},
image::CreateImageOptions,
service::{ContainerCreateResponse, ContainerSummary},
Docker,
};
use eyre::{bail, Result};
use futures_util::{StreamExt, TryStreamExt};
use serde::Serialize;

pub use bollard::image::CreateImageOptions;
pub use bollard::service::ContainerConfig;

/// The Composer is responsible for managing the OP-UP docker containers.
Expand Down Expand Up @@ -85,13 +85,8 @@ impl Composer {
})
})
.try_collect::<Vec<_>>()
.await
.map_err(|e| {
tracing::error!(target: "composer", "Error creating docker image: {:?}", e);
e
})?;
.await?;

println!("res: {:?}", res);
tracing::debug!(target: "composer", "Created docker image: {:?}", res);

match res.get(0) {
Expand Down Expand Up @@ -120,6 +115,26 @@ impl Composer {
"op-up".to_string(),
);

// Check if a container already exists with the specified name.
// If so, return the existing container ID instead
let containers = self.list_containers(None).await?;
if let Some(container) = containers.iter().find(|container| {
container
.names
.as_ref()
.map(|names| names.iter().any(|n| n == name))
.unwrap_or(false)
}) {
tracing::debug!(target: "composer", "Container {} already exists", name);
return Ok(ContainerCreateResponse {
id: container
.id
.clone()
.ok_or_else(|| eyre::eyre!("No container ID found"))?,
warnings: vec![],
});
}

let res = self
.daemon
.create_container(Some(create_options), config.into())
Expand Down
4 changes: 0 additions & 4 deletions crates/composer/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ pub async fn test_basic_docker_composer() -> eyre::Result<()> {
let container = composer
.create_container("test_basic_docker_composer", container_config)
.await?;
println!("Created container: {:?}", container);

let all_containers = composer.list_containers(None).await?;
assert_eq!(all_containers.len(), 1);

// 3. Start running container
composer.start_container(&container.id).await?;
Expand Down
65 changes: 59 additions & 6 deletions crates/stages/src/stages/l1_exec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use eyre::Result;
use op_composer::CreateImageOptions;
use std::collections::HashMap;
use std::sync::Arc;

Expand All @@ -23,15 +24,23 @@ impl crate::Stage for Executor {
async fn execute(&self) -> Result<()> {
tracing::info!(target: "stages", "Executing l1 execution client stage");

let image_name = "ethereum/client-go:v1.12.2".to_string();
let working_dir = project_root::get_project_root()?.join("docker");
let l1_genesis = self.artifacts.l1_genesis();
let jwt_secret = self.artifacts.jwt_secret();

let image_config = CreateImageOptions {
from_image: image_name.as_str(),
..Default::default()
};
self.l1_exec.create_image(image_config).await?;

let config = ContainerConfig {
cmd: Some(vec![
"/bin/sh".to_string(),
"/bin/sh".to_string(), // TODO: fix this: we need to place here the actual geth start command
"geth-entrypoint.sh".to_string(),
]),
image: Some("ethereum/client-go:v1.12.2".to_string()),
image: Some(image_name),
working_dir: Some(working_dir.to_string_lossy().to_string()),
volumes: Some(HashMap::from([
("l1_data:/db".to_string(), HashMap::new()),
Expand All @@ -55,14 +64,22 @@ impl crate::Stage for Executor {
..Default::default()
};

let response = self
let container_id = self
.l1_exec
.create_container(&self.l1_client, config)
.await?;
tracing::info!(target: "stages", "l1 container created: {:?}", response);
.await?
.id;

let all_containers = self.l1_exec.list_containers(None).await?;
tracing::info!(target: "stages", "all containers: {:?}", all_containers);

tracing::info!(target: "stages", "l1 container created: {}", container_id);

self.l1_exec.start_container(&container_id).await?;

let l1_port = self.l1_port.unwrap_or(op_config::L1_PORT);
crate::net::wait_up(l1_port, 10, 1)?;
crate::net::wait_up(l1_port, 10, 3)?;
tracing::info!(target: "stages", "l1 container started on port: {}", l1_port);

// todo: do we need to do block here
// can we wait for the l1 client to be ready by polling?
Expand All @@ -88,3 +105,39 @@ impl Executor {
}
}
}

// For reference, here is the geth startup command in geth-entrypoint.sh:
//
// exec geth \
// --datadir="$GETH_DATA_DIR" \
// --verbosity="$VERBOSITY" \
// --http \
// --http.corsdomain="*" \
// --http.vhosts="*" \
// --http.addr=0.0.0.0 \
// --http.port="$RPC_PORT" \
// --http.api=web3,debug,eth,txpool,net,engine \
// --ws \
// --ws.addr=0.0.0.0 \
// --ws.port="$WS_PORT" \
// --ws.origins="*" \
// --ws.api=debug,eth,txpool,net,engine \
// --syncmode=full \
// --nodiscover \
// --maxpeers=1 \
// --networkid=$CHAIN_ID \
// --unlock=$BLOCK_SIGNER_ADDRESS \
// --mine \
// --miner.etherbase=$BLOCK_SIGNER_ADDRESS \
// --password="$GETH_DATA_DIR"/password \
// --allow-insecure-unlock \
// --rpc.allow-unprotected-txs \
// --authrpc.addr="0.0.0.0" \
// --authrpc.port="8551" \
// --authrpc.vhosts="*" \
// --authrpc.jwtsecret=/config/test-jwt-secret.txt \
// --gcmode=archive \
// --metrics \
// --metrics.addr=0.0.0.0 \
// --metrics.port=6060 \
// "$@"
Loading