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

Granular docker support #28

Merged
merged 1 commit into from
Oct 16, 2024
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
4 changes: 2 additions & 2 deletions src/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ impl NodeT for BitcoinNode {

async fn spawn(config: &Self::Config, docker: &Arc<Option<DockerEnv>>) -> Result<SpawnOutput> {
match docker.as_ref() {
Some(docker) => docker.spawn(config.into()).await,
None => Self::spawn(config),
Some(docker) if docker.bitcoin() => docker.spawn(config.into()).await,
_ => Self::spawn(config),
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/config/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,10 @@ where
ports: vec![config.rollup.rpc.bind_port],
image: config.docker_image.clone().unwrap_or_else(|| {
let base_img = DEFAULT_CITREA_DOCKER_IMAGE;
let img = match std::env::var("SHORT_PREFIX") {
match std::env::var("SHORT_PREFIX") {
Ok(v) if v == "1" || v == "true" => format!("{base_img}-short-prefix"),
_ => base_img.to_string(),
};
println!("img : {:?}", img);
img
}
}),
cmd: args,
log_path: config.dir.join("stdout.log"),
Expand Down
16 changes: 14 additions & 2 deletions src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use futures::StreamExt;
use tokio::{fs::File, io::AsyncWriteExt, sync::Mutex, task::JoinHandle};
use tracing::{debug, error, info};

use crate::node::NodeKind;
use crate::{config::TestCaseDockerConfig, node::NodeKind};

use super::{config::DockerConfig, traits::SpawnOutput, utils::generate_test_id};

Expand All @@ -40,10 +40,11 @@ pub struct DockerEnv {
id: String,
volumes: Mutex<HashSet<String>>,
container_ids: Mutex<HashSet<String>>,
test_case_config: TestCaseDockerConfig,
}

impl DockerEnv {
pub async fn new() -> Result<Self> {
pub async fn new(test_case_config: TestCaseDockerConfig) -> Result<Self> {
let docker =
Docker::connect_with_local_defaults().context("Failed to connect to Docker")?;
let test_id = generate_test_id();
Expand All @@ -55,6 +56,7 @@ impl DockerEnv {
id: test_id,
volumes: Mutex::new(HashSet::new()),
container_ids: Mutex::new(HashSet::new()),
test_case_config,
})
}

Expand Down Expand Up @@ -339,4 +341,14 @@ impl DockerEnv {

Ok(())
}

// Should run bitcoin in docker
pub fn bitcoin(&self) -> bool {
self.test_case_config.bitcoin
}

// Should run citrea in docker
pub fn citrea(&self) -> bool {
self.test_case_config.citrea
}
}
16 changes: 8 additions & 8 deletions src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl TestFramework {

let test_case = T::test_config();
let docker = if test_case.docker.enabled() {
Some(DockerEnv::new().await?)
Some(DockerEnv::new(test_case.docker.clone()).await?)
} else {
None
};
Expand Down Expand Up @@ -285,21 +285,21 @@ impl TestFramework {
});
}

if let Some(docker) = docker.as_ref() {
bitcoin_confs[0].docker_host = Some(docker.get_hostname(&NodeKind::Bitcoin));
}
bitcoin_confs[0].docker_host = docker
.as_ref()
.and_then(|d| d.citrea().then(|| d.get_hostname(&NodeKind::Bitcoin)));

// Target first bitcoin node as DA for now
let da_config: BitcoinServiceConfig = bitcoin_confs[0].clone().into();

let runner_bind_host = match docker.as_ref() {
Some(d) => d.get_hostname(&NodeKind::Sequencer),
None => sequencer_rollup.rpc.bind_host.clone(),
Some(d) if d.citrea() => d.get_hostname(&NodeKind::Sequencer),
_ => sequencer_rollup.rpc.bind_host.clone(),
};

let bind_host = match docker.as_ref() {
Some(_) => "0.0.0.0".to_string(),
None => sequencer_rollup.rpc.bind_host.clone(),
Some(d) if d.citrea() => "0.0.0.0".to_string(),
_ => sequencer_rollup.rpc.bind_host.clone(),
};

let sequencer_rollup = {
Expand Down
4 changes: 2 additions & 2 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ where

async fn spawn(config: &Self::Config, docker: &Arc<Option<DockerEnv>>) -> Result<SpawnOutput> {
match docker.as_ref() {
Some(docker) => docker.spawn(config.to_owned().into()).await,
None => Self::spawn(config),
Some(docker) if docker.citrea() => docker.spawn(config.to_owned().into()).await,
_ => Self::spawn(config),
}
}

Expand Down
Loading