-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx.rs
76 lines (52 loc) · 1.84 KB
/
nginx.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#[path = "example_utils/lib.rs"]
mod example_utils;
use std::process::ExitCode;
use log::*;
use passivized_docker_engine_client::DockerEngineClient;
use passivized_docker_engine_client::requests::CreateContainerRequest;
use passivized_test_support::cli;
use passivized_test_support::http_status_tests::is_success;
use passivized_test_support::waiter::wait_for_http_server;
use example_utils::errors::ExampleError;
const IMAGE_NAME: &str = "nginx";
const IMAGE_TAG: &str = "1.20";
#[tokio::main]
async fn main() -> ExitCode {
cli::run(run).await
}
async fn run() -> Result<(), ExampleError> {
let dec = DockerEngineClient::new()?;
info!("Connecting to {}", dec);
info!("Pulling image");
let pull_result = dec.images().pull_if_not_present(IMAGE_NAME, IMAGE_TAG)
.await?;
info!("Pull result: {}", pull_result);
let create_request = CreateContainerRequest::default()
.image(format!("{}:{}", IMAGE_NAME, IMAGE_TAG));
info!("Creating container");
let container = dec.containers().create(create_request)
.await?;
info!("Created container with id {}", container.id);
for w in &container.warnings {
info!("Container warning: {}", w)
}
dec.container(&container.id).rename("test-nginx")
.await?;
dec.container(&container.id).start()
.await?;
let inspected = dec.container(&container.id).inspect()
.await?;
let ip = inspected.first_ip_address()
.ok_or(ExampleError::NoIp())?;
let url = format!("http://{}", ip);
let response = wait_for_http_server(url, is_success())
.await?;
info!("{}", response);
info!("Stopping container {}", container.id);
dec.container(&container.id).stop()
.await?;
info!("Removing container {}", container.id);
dec.container(container.id).remove()
.await?;
Ok(())
}