testing bollard

This commit is contained in:
2023-06-25 14:41:26 +02:00
parent 2b0d2b07d1
commit c002a37da9
4 changed files with 288 additions and 19 deletions

245
Cargo.lock generated
View File

@@ -77,6 +77,47 @@ version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6776fc96284a0bb647b615056fc496d1fe1644a7ab01829818a6d91cae888b84"
[[package]]
name = "bollard"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c92fed694fd5a7468c971538351c61b9c115f1ae6ed411cd2800f0f299403a4b"
dependencies = [
"base64",
"bollard-stubs",
"bytes",
"chrono",
"dirs-next",
"futures-core",
"futures-util",
"hex",
"http",
"hyper",
"hyperlocal",
"log",
"pin-project",
"serde",
"serde_derive",
"serde_json",
"serde_urlencoded",
"thiserror",
"tokio",
"tokio-util 0.6.10",
"url",
"winapi",
]
[[package]]
name = "bollard-stubs"
version = "1.41.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed2f2e73fffe9455141e170fb9c1feb0ac521ec7e7dcd47a7cab72a658490fb8"
dependencies = [
"chrono",
"serde",
"serde_with 1.14.0",
]
[[package]]
name = "bumpalo"
version = "3.13.0"
@@ -162,14 +203,38 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "darling"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c"
dependencies = [
"darling_core 0.13.4",
"darling_macro 0.13.4",
]
[[package]]
name = "darling"
version = "0.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0558d22a7b463ed0241e993f76f09f30b126687447751a8638587b864e4b3944"
dependencies = [
"darling_core",
"darling_macro",
"darling_core 0.20.1",
"darling_macro 0.20.1",
]
[[package]]
name = "darling_core"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote",
"strsim",
"syn 1.0.109",
]
[[package]]
@@ -183,7 +248,18 @@ dependencies = [
"proc-macro2",
"quote",
"strsim",
"syn",
"syn 2.0.18",
]
[[package]]
name = "darling_macro"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835"
dependencies = [
"darling_core 0.13.4",
"quote",
"syn 1.0.109",
]
[[package]]
@@ -192,9 +268,30 @@ version = "0.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29a358ff9f12ec09c3e61fef9b5a9902623a695a46a917b07f269bff1445611a"
dependencies = [
"darling_core",
"darling_core 0.20.1",
"quote",
"syn",
"syn 2.0.18",
]
[[package]]
name = "dirs-next"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
dependencies = [
"cfg-if",
"dirs-sys-next",
]
[[package]]
name = "dirs-sys-next"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
dependencies = [
"libc",
"redox_users",
"winapi",
]
[[package]]
@@ -231,7 +328,7 @@ dependencies = [
"chrono",
"serde",
"serde_json",
"serde_with",
"serde_with 2.3.3",
]
[[package]]
@@ -339,7 +436,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.18",
]
[[package]]
@@ -372,6 +469,36 @@ dependencies = [
"slab",
]
[[package]]
name = "getrandom"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
dependencies = [
"cfg-if",
"libc",
"wasi 0.11.0+wasi-snapshot-preview1",
]
[[package]]
name = "h2"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d357c7ae988e7d2182f7d7871d0b963962420b0678b0997ce7de72001aeab782"
dependencies = [
"bytes",
"fnv",
"futures-core",
"futures-sink",
"futures-util",
"http",
"indexmap",
"slab",
"tokio",
"tokio-util 0.7.8",
"tracing",
]
[[package]]
name = "hashbrown"
version = "0.12.3"
@@ -456,6 +583,7 @@ dependencies = [
"futures-channel",
"futures-core",
"futures-util",
"h2",
"http",
"http-body",
"httparse",
@@ -616,6 +744,7 @@ dependencies = [
name = "mrdeployer"
version = "0.1.0"
dependencies = [
"bollard",
"docker-api",
"futures",
"rusqlite",
@@ -699,7 +828,7 @@ checksum = "39407670928234ebc5e6e580247dd567ad73a3578460c5990f9503df207e8f07"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.18",
]
[[package]]
@@ -756,6 +885,17 @@ dependencies = [
"bitflags 1.3.2",
]
[[package]]
name = "redox_users"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
dependencies = [
"getrandom",
"redox_syscall 0.2.16",
"thiserror",
]
[[package]]
name = "rusqlite"
version = "0.29.0"
@@ -799,7 +939,7 @@ checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.18",
]
[[package]]
@@ -813,6 +953,28 @@ dependencies = [
"serde",
]
[[package]]
name = "serde_urlencoded"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"
dependencies = [
"form_urlencoded",
"itoa",
"ryu",
"serde",
]
[[package]]
name = "serde_with"
version = "1.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "678b5a069e50bf00ecd22d0cd8ddf7c236f68581b03db652061ed5eb13a312ff"
dependencies = [
"serde",
"serde_with_macros 1.5.2",
]
[[package]]
name = "serde_with"
version = "2.3.3"
@@ -825,20 +987,32 @@ dependencies = [
"indexmap",
"serde",
"serde_json",
"serde_with_macros",
"serde_with_macros 2.3.3",
"time 0.3.21",
]
[[package]]
name = "serde_with_macros"
version = "1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082"
dependencies = [
"darling 0.13.4",
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "serde_with_macros"
version = "2.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "881b6f881b17d13214e5d494c939ebab463d01264ce1811e9d4ac3a882e7695f"
dependencies = [
"darling",
"darling 0.20.1",
"proc-macro2",
"quote",
"syn",
"syn 2.0.18",
]
[[package]]
@@ -881,6 +1055,17 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "syn"
version = "2.0.18"
@@ -920,7 +1105,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.18",
]
[[package]]
@@ -1003,7 +1188,35 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.18",
]
[[package]]
name = "tokio-util"
version = "0.6.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36943ee01a6d67977dd3f84a5a1d2efeb4ada3a1ae771cadfaa535d9d9fc6507"
dependencies = [
"bytes",
"futures-core",
"futures-sink",
"log",
"pin-project-lite",
"tokio",
]
[[package]]
name = "tokio-util"
version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d"
dependencies = [
"bytes",
"futures-core",
"futures-sink",
"pin-project-lite",
"tokio",
"tracing",
]
[[package]]
@@ -1125,7 +1338,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"syn",
"syn 2.0.18",
"wasm-bindgen-shared",
]
@@ -1147,7 +1360,7 @@ checksum = "e128beba882dd1eb6200e1dc92ae6c5dbaa4311aa7bb211ca035779e5efc39f8"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.18",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]

View File

@@ -5,6 +5,12 @@ edition = "2021"
[dependencies]
docker-api = "*"
bollard = "0.11"
futures = "0.3"
tokio = { version = "1", features = ["full"] }
rusqlite = { version = "0.29.0", features = ["bundled"] }
rusqlite = { version = "0.29.0", features = ["bundled"] }
[target.x86_64-unknown-linux-gnu]
rustflags = [
"-C", "link-arg=-fuse-ld=mold",
]

View File

@@ -27,6 +27,7 @@ pub async fn create(docker: docker_api::Docker){
let opts = ContainerCreateOpts::builder()
.image("itzg/minecraft-server:latest")
.env(env)
//.network_config(network_config)
.build();
let cont = match docker.containers().create(&opts).await {
Ok(c) => {
@@ -43,3 +44,7 @@ pub async fn create(docker: docker_api::Docker){
};
}
/*async fn get_network(docker: docker_api::Docker) -> Network {
}*/

View File

@@ -2,17 +2,62 @@ use futures::executor::block_on;
use std::io;
use tokio::net::TcpListener;
use tokio::io::AsyncWriteExt;
use std::collections::hash_map::HashMap;
use bollard::Docker;
use bollard::container::{StartContainerOptions, CreateContainerOptions, Config, NetworkingConfig};
use bollard::models::{EndpointSettings, EndpointIpamConfig};
mod create_container;
mod server;
mod conf;
#[tokio::main]
async fn main() {
let docker = match docker_api::Docker::new("unix:///var/run/docker.sock") {
let docker = match Docker::connect_with_local_defaults() {
Ok(d) => d,
Err(e) => panic!("error:{}",e.to_string()),
};
let options = Some(CreateContainerOptions{
name: "my-new-container",
//platform: None,
});
let ip = Some(String::from("172.20.0.5"));
let endpoint = EndpointSettings {
ipam_config: Some(EndpointIpamConfig{
ipv4_address: ip.clone(),
..Default::default()
}),
//network_id: Some(String::from("672821882d72")),
//ip_address: ip.clone(),
..Default::default()
};
let mut hash = HashMap::new();
hash.insert("customnetwork", endpoint);
let net = NetworkingConfig {
endpoints_config: hash
};
let env = vec!["EULA=TRUE"];
let config = Config {
image: Some("itzg/minecraft-server:latest"),
env: Some(env),
networking_config: Some(net),
..Default::default()
};
match docker.create_container(options, config).await{
Ok(r) => println!("va1"),
Err(e) => println!("error1:{}",e.to_string()),
}
match docker.start_container("my-new-container", None::<StartContainerOptions<String>>).await {
Ok(r) => println!("va2"),
Err(e) => println!("error2:{}",e.to_string()),
};
/*let docker = match docker_api::Docker::new("unix:///var/run/docker.sock") {
Ok(d) => d,
Err(e) => {print!("{}",e.to_string()); panic!("{}", e.to_string())},
};
block_on(create_container::list(docker.clone()));
block_on(create_container::list(docker.clone()));*/
//block_on(create_container::create(docker.clone()));
//block_on(create_container::list_c(docker));
//server::start().await;