-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from karnotxyz/explorer
- Loading branch information
Showing
7 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use crate::utils::docker::run_docker_image; | ||
|
||
pub fn explorer() { | ||
let env_vars = vec!["RPC_API_HOST=\"http://127.0.0.1:9944\""]; | ||
run_docker_image("ghcr.io/lambdaclass/stark_compass_explorer:v0.2.34.2", "madara-explorer", env_vars); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ pub mod prompt; | |
pub mod list; | ||
|
||
pub mod run; | ||
|
||
pub mod explorer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use bollard::container::{Config, CreateContainerOptions}; | ||
use bollard::Docker; | ||
|
||
use bollard::image::CreateImageOptions; | ||
use futures_util::TryStreamExt; | ||
|
||
pub fn run_docker_image(image: &str, container_name: &str, env_vars: Vec<&str>) { | ||
is_docker_installed(); | ||
match pull_and_start_docker_image(image, container_name, env_vars) { | ||
Ok(..) => { | ||
log::info!("Successfully ran {}", container_name); | ||
} | ||
Err(err) => { | ||
log::error!("Error: {} running image: {}", err, image); | ||
} | ||
}; | ||
} | ||
|
||
#[tokio::main] | ||
async fn is_docker_installed() -> bool { | ||
let docker = Docker::connect_with_local_defaults().unwrap(); | ||
return match docker.version().await { | ||
Ok(_) => { | ||
log::info!("Docker running!"); | ||
true | ||
} | ||
Err(_) => { | ||
panic!("Please check docker installation, panicking"); | ||
} | ||
}; | ||
} | ||
|
||
#[tokio::main] | ||
async fn pull_and_start_docker_image( | ||
image: &str, | ||
container_name: &str, | ||
env_vars: Vec<&str>, | ||
) -> Result<(), Box<dyn std::error::Error + 'static>> { | ||
let docker = Docker::connect_with_local_defaults().unwrap(); | ||
|
||
docker | ||
.create_image(Some(CreateImageOptions { from_image: image, ..Default::default() }), None, None) | ||
.try_collect::<Vec<_>>() | ||
.await?; | ||
|
||
let config = Config { image: Some(image), tty: Some(true), env: Some(env_vars), ..Default::default() }; | ||
|
||
let container_option = Some(CreateContainerOptions { name: container_name, ..Default::default() }); | ||
|
||
let id = docker.create_container::<&str, &str>(container_option, config).await?.id; | ||
|
||
docker.start_container::<String>(&id, None).await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,5 @@ pub mod errors; | |
pub mod toml; | ||
|
||
pub mod constants; | ||
|
||
pub mod docker; |