Skip to content

Commit e1e7552

Browse files
feat: allow developers to bypass the docker build (#11)
Co-authored-by: noot <[email protected]>
1 parent 5a141f7 commit e1e7552

File tree

3 files changed

+41
-32
lines changed

3 files changed

+41
-32
lines changed

.github/workflows/tests.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- uses: actions/checkout@v1
11-
- name: Install stable
12-
run: rustup toolchain install stable
1311
- name: Install protoc
14-
run: sudo apt-get install protobuf-compiler
12+
run: sudo apt-get update -qqq && sudo apt-get install -y protobuf-compiler
13+
- name: Install latest nightly
14+
uses: actions-rs/toolchain@v1
15+
with:
16+
toolchain: stable
17+
override: true
18+
components: rustfmt, clippy
1519
- name: Build
16-
run: cargo build --all
20+
run: DOCKER_BUILD=1 cargo build --all
1721
- name: Run tests
18-
run: cargo test -- --test-threads=1
22+
run: DOCKER_BUILD=1 cargo test
1923

2024

2125
fmt:

README.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ Ensure that docker is installed on the machine where the tests need to be run.
1010

1111
Then, run the following as usual.
1212
```
13-
cargo test
13+
DOCKER_BUILD=1 cargo test
1414
```
1515

16+
Note that if you've already built the docker image and want to avoid this step,
17+
you can ignore the `DOCKER_BUILD` environment variable.
18+
1619
### Writing New Tests
1720

1821
In order to abstract away the `nym-client` instantiation, we rely on the
@@ -27,22 +30,21 @@ snippet.
2730
```rust
2831
#[cfg(test)]
2932
mod test {
30-
use testcontainers::clients;
31-
use testcontainers::core::WaitFor;
32-
use testcontainers::images::generic::GenericImage;
33+
use crate::new_nym_client;
3334
#[tokio::test]
3435
async fn test_with_nym() {
35-
let docker_client = clients::Cli::default();
36-
let nym_ready_message = WaitFor::message_on_stderr("Client startup finished!");
37-
let nym_dialer_image = GenericImage::new("nym", "latest")
38-
.with_env_var("NYM_ID", "test_connection_dialer")
39-
.with_wait_for(nym_ready_message.clone())
40-
.with_exposed_port(1977);
41-
let dialer_container = docker_client.run(nym_dialer_image);
42-
let dialer_port = dialer_container.get_host_port_ipv4(1977);
43-
let dialer_uri = format!("ws://0.0.0.0:{dialer_port}");
36+
37+
let nym_id = "test_transport_connection_dialer";
38+
#[allow(unused)]
39+
let dialer_uri: String;
40+
new_nym_client!(nym_id, dialer_uri);
41+
todo!("Now you can use the dialer_uri to make requests.")
4442
}
4543
}
4644
```
4745

4846
One can create as many of these as needed, limited only by the server resources.
47+
48+
**NOTE**: When using a URI for connections, ensure that you're prefixing the
49+
URI with the `ws://` protocol type, otherwise the nym client assumes http and
50+
crashes unceremoniously.

build.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1+
use std::env;
12
use std::process::Command;
3+
24
fn main() {
3-
println!("cargo:rerun-if-changed=Dockerfile.nym");
4-
let output = Command::new("docker")
5-
.arg("build")
6-
.arg("-t")
7-
.arg("nym:latest")
8-
.arg("-f")
9-
.arg("./Dockerfile.nym")
10-
.arg(".")
11-
.output()
12-
.expect("ERROR: unable to prepare context");
13-
println!("status: {}", output.status);
14-
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
15-
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
16-
assert!(output.status.success());
5+
if env::var("DOCKER_BUILD").is_ok() {
6+
let output = Command::new("docker")
7+
.arg("build")
8+
.arg("-t")
9+
.arg("nym:latest")
10+
.arg("-f")
11+
.arg("./Dockerfile.nym")
12+
.arg(".")
13+
.output()
14+
.expect("ERROR: unable to prepare context");
15+
println!("status: {}", output.status);
16+
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
17+
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
18+
assert!(output.status.success());
19+
};
1720
}

0 commit comments

Comments
 (0)