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: add wsl support (Docker Desktop) #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

history.txt
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ rustyline = { version = "9.1", features = ["case_insensitive_history_search"] }
secp256k1 = { version = "0.20", features = ["recovery"] }
serde_json = "1.0"
tokio = { version = "1.0", features = ["macros"] }
wsl = "0.1.0"
wslpath = "0.0.2"

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ You need to take the following steps to run axon and benchmark with axon-cli.
Under the axon-cli directory, run the following command:
`cargo build --release` Or `cargo build`
## 2. Run axon-cli
For example,
`./target/debug/axon-cli` in case you run the command `cargo build`.
For example run: `./target/debug/axon-cli` in case you've previously ran the command `cargo build`.

You can optionally pass `DOCKER_API_URL` environment variable to Axon CLI which lets you change default Docker API URL (127.0.0.1:2375). This is especially useful when you're running Docker Desktop on Windows Subsystem for Linux (WSL).

## 3. Interactive Commands
Before the execution of axon commands, you have to enable tcp port for docker(0.0.0.0:2375 in this case).
Expand Down
20 changes: 16 additions & 4 deletions src/docker.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::env;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;
Expand All @@ -7,8 +8,9 @@ use docker_api::{
docker::Docker,
};
use futures::StreamExt;
use wsl::is_wsl;

const DOCKER_URI: &str = "tcp://127.0.0.1:2375";
const DEFAULT_DOCKER_URI: &str = "tcp://127.0.0.1:2375";
const AXON_IMAGE_NAME: &str = "wenyuancas/axon";
const AXON_IMAGE_TAG: &str = "v1";
const BM_IMAGE_NAME: &str = "zhengjianhui/axon-benchmark";
Expand All @@ -24,7 +26,8 @@ impl DockerApi {
}

pub fn new_docker() -> Docker {
Docker::new(DOCKER_URI).unwrap()
let docker_api_url = env::var("DOCKER_API_URL").unwrap_or(String::from(DEFAULT_DOCKER_URI));
Docker::new(docker_api_url).unwrap()
}

pub async fn create_network(network_name: &str) {
Expand Down Expand Up @@ -71,8 +74,17 @@ impl DockerApi {
let cmd = vec!["./axon", file_para, genesis_para];
println!("cmd: {:?}", cmd);

let data_mapping = self.path.to_owned() + "/devtools" + ":/app/devtools";
let log_mapping = self.path.to_owned() + "/logs/" + name + ":/app/logs";
let mut base_path = Path::new(&self.path);
let wsl_path: String;

if is_wsl() {
wsl_path = wslpath::wsl_to_windows(&self.path.to_owned()).unwrap().to_owned().replace("/", "\\");
Copy link
Contributor

@wenyuanhust wenyuanhust Sep 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you running docker on Windows instead of WSL?
I tried this branch on Ubuntu 20.04 of WSL2 for Window10. And, I started docker on my WSL2. After running axon start command by axon-cli. I got the following error msg:

Error: error 400 Bad Request - create \wsl$\Ubuntu-20.04\root.axon/devtools: "\\wsl$\Ubuntu-20.04\root\.axon/devtools" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path

If I run the main branch of axon-cli, it works fine.

Copy link
Author

@e00dan e00dan Sep 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you install Docker on WSL using https://www.docker.com/products/docker-desktop/ or did you install it in custom way?

I'm running Docker Desktop on WSL with exposed Remote API port from Windows host (it was unreachable otherwise)

Copy link
Contributor

@wenyuanhust wenyuanhust Sep 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure cause I installed Docker long time ago.
But I didn't install Docker on my Win10 machine. Looks like I installed Docker for Ubuntu in custom way.
By the way, I'm using WSL2 instead fo WSL.

base_path = Path::new(&wsl_path);
}

let data_mapping = Path::join(base_path, "devtools").to_str().unwrap().to_owned() + ":/app/devtools";
let log_mapping = Path::join(base_path, "logs").to_str().unwrap().to_owned() + ":/app/logs";

let vols = vec![data_mapping, log_mapping];
println!("mapping: {:?}", vols);
// prometheus collecting port from 8900-8903
Expand Down