Skip to content

Commit e64b991

Browse files
authored
chore: update to the new bollad api (#94)
1 parent ae25cd8 commit e64b991

File tree

13 files changed

+129
-105
lines changed

13 files changed

+129
-105
lines changed

Cargo.lock

Lines changed: 24 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
[package]
22
name = "rooz"
3-
version = "0.123.0"
3+
version = "0.124.0"
44
edition = "2021"
55

66
[dependencies]
77
age = {version = "0.11.1", features = ["armor"] }
88
base64 = "0.22.1"
9-
bollard = { version = "0.18.1" }
9+
#bollard = { version = "0.19.1" }
10+
bollard = { git = "https://github.com/fussybeaver/bollard", rev = "e785084893d6763dfa1a9c7e283c7ee9adde11eb"}
11+
bollard-stubs = "1.48.3-rc.28.0.4"
1012
clap = { version = "4.5.16", features = ["derive", "env"] }
1113
clap_complete = "4.5.24"
1214
colored = "3.0.0"
@@ -28,5 +30,5 @@ shellexpand = "3.1.0"
2830
tabled = "0.20.0"
2931
termion = "4.0.2"
3032
tokio = { version = "1.46", features = ["rt-multi-thread", "macros"] }
31-
toml = "0.8.19"
33+
toml = "0.9.2"
3234
url = "2.5.2"

src/api/container.rs

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@ use crate::{
99
},
1010
};
1111
use base64::{engine::general_purpose, Engine as _};
12-
use bollard::container::LogOutput::Console;
12+
1313
use bollard::{
14-
container::{
15-
Config, CreateContainerOptions, InspectContainerOptions, KillContainerOptions,
14+
container::LogOutput::Console,
15+
errors::Error,
16+
models::{
17+
ContainerCreateBody, ContainerInspectResponse, ContainerState, ContainerStateStatusEnum,
18+
ContainerSummary, EndpointSettings, HostConfig, Mount, NetworkConnectRequest, PortBinding,
19+
},
20+
query_parameters::{
21+
CreateContainerOptions, InspectContainerOptions, KillContainerOptions,
1622
ListContainersOptions, LogsOptions, RemoveContainerOptions, StartContainerOptions,
1723
StopContainerOptions, WaitContainerOptions,
1824
},
19-
errors::Error,
20-
models::{ContainerState, HostConfig},
21-
network::ConnectNetworkOptions,
22-
secret::{ContainerStateStatusEnum, Mount},
23-
service::{ContainerInspectResponse, ContainerSummary, EndpointSettings, PortBinding},
2425
};
26+
2527
use futures::{future, StreamExt};
2628
use std::{
2729
collections::HashMap,
@@ -52,7 +54,7 @@ pub fn inject(script: &str, name: &str) -> Vec<String> {
5254
impl<'a> ContainerApi<'a> {
5355
pub async fn get_all(&self, labels: &Labels) -> Result<Vec<ContainerSummary>, AnyError> {
5456
let list_options = ListContainersOptions {
55-
filters: labels.into(),
57+
filters: Some(labels.into()),
5658
all: true,
5759
..Default::default()
5860
};
@@ -62,7 +64,7 @@ impl<'a> ContainerApi<'a> {
6264

6365
pub async fn get_running(&self, labels: &Labels) -> Result<Vec<ContainerSummary>, AnyError> {
6466
let list_options = ListContainersOptions {
65-
filters: labels.into(),
67+
filters: Some(labels.into()),
6668
all: false,
6769
..Default::default()
6870
};
@@ -150,7 +152,7 @@ impl<'a> ContainerApi<'a> {
150152
pub async fn kill(&self, container_id: &str, wait_for_remove: bool) -> Result<(), AnyError> {
151153
match self
152154
.client
153-
.kill_container(&container_id, None::<KillContainerOptions<String>>)
155+
.kill_container(&container_id, None::<KillContainerOptions>)
154156
.await
155157
{
156158
Ok(_) => {
@@ -207,12 +209,21 @@ impl<'a> ContainerApi<'a> {
207209

208210
pub async fn stop(&self, container_id: &str) -> Result<(), AnyError> {
209211
self.client
210-
.stop_container(&container_id, Some(StopContainerOptions { t: 0 }))
212+
.stop_container(
213+
&container_id,
214+
Some(StopContainerOptions {
215+
t: Some(0),
216+
signal: Some("SIGINT".into()),
217+
}),
218+
)
211219
.await?;
212220
let mut count = 10;
213221
while count > 0 {
214222
log::debug!("Waiting for container {} to be gone...", container_id);
215-
let r = self.client.inspect_container(&container_id, None).await;
223+
let r = self
224+
.client
225+
.inspect_container(&container_id, None::<InspectContainerOptions>)
226+
.await;
216227
if let Err(Error::DockerResponseServerError {
217228
status_code: 404, ..
218229
}) = r
@@ -241,7 +252,7 @@ impl<'a> ContainerApi<'a> {
241252

242253
let container_id = match self
243254
.client
244-
.inspect_container(&spec.container_name, None)
255+
.inspect_container(&spec.container_name, None::<InspectContainerOptions>)
245256
.await
246257
{
247258
Ok(ContainerInspectResponse { id: Some(id), .. }) if !spec.force_recreate => {
@@ -260,8 +271,8 @@ impl<'a> ContainerApi<'a> {
260271
}
261272

262273
let options = CreateContainerOptions {
263-
name: spec.container_name,
264-
platform: None,
274+
name: Some(spec.container_name.to_string()),
275+
platform: "linux/amd64".into(),
265276
};
266277

267278
let oom_score_adj = match self.backend {
@@ -321,21 +332,25 @@ impl<'a> ContainerApi<'a> {
321332

322333
let env = KeyValue::to_vec_str(&env_kv);
323334

324-
let config = Config {
325-
image: Some(spec.image),
326-
entrypoint: spec.entrypoint,
327-
cmd: spec.command,
328-
working_dir: spec.work_dir,
335+
let config = ContainerCreateBody {
336+
image: Some(spec.image.to_string()),
337+
entrypoint: spec
338+
.entrypoint
339+
.map(|vec| vec.iter().map(|&s| s.to_string()).collect()),
340+
cmd: spec
341+
.command
342+
.map(|vec| vec.iter().map(|&s| s.to_string()).collect()),
343+
working_dir: spec.work_dir.map(|s| s.to_string()),
329344
// THIS MUST BE spec.uid, NOT spec.user - otherwise file ownership will break
330-
user: Some(spec.uid),
345+
user: Some(spec.uid.to_string()),
331346
attach_stdin,
332347
attach_stdout: Some(true),
333348
attach_stderr: Some(true),
334349
tty,
335350
open_stdin,
336351
host_config: Some(host_config),
337352
labels: Some((&spec.labels).into()),
338-
env: Some(env),
353+
env: Some(env.iter().map(|&s| s.to_string()).collect()),
339354
..Default::default()
340355
};
341356

@@ -345,12 +360,12 @@ impl<'a> ContainerApi<'a> {
345360
.await?;
346361

347362
if let Some(network) = &spec.network {
348-
let connect_network_options = ConnectNetworkOptions {
349-
container: &response.id,
350-
endpoint_config: EndpointSettings {
363+
let connect_network_options = NetworkConnectRequest {
364+
container: Some(response.id.to_string()),
365+
endpoint_config: Some(EndpointSettings {
351366
aliases: spec.network_aliases,
352367
..Default::default()
353-
},
368+
}),
354369
};
355370
self.client
356371
.connect_network(network, connect_network_options)
@@ -359,7 +374,7 @@ impl<'a> ContainerApi<'a> {
359374
log::debug!(
360375
"Created container: {} ({})",
361376
spec.container_name,
362-
response.id
377+
response.id.to_string()
363378
);
364379

365380
ContainerResult::Created { id: response.id }
@@ -371,7 +386,7 @@ impl<'a> ContainerApi<'a> {
371386
pub async fn start(&self, container_id: &str) -> Result<(), AnyError> {
372387
match self
373388
.client
374-
.start_container(&container_id, None::<StartContainerOptions<String>>)
389+
.start_container(&container_id, None::<StartContainerOptions>)
375390
.await
376391
.map_err(|e| Box::new(e))
377392
{
@@ -421,7 +436,7 @@ impl<'a> ContainerApi<'a> {
421436
let log_task = tokio::spawn(async move {
422437
let logs_stream = docker_logs.logs(
423438
&s_id,
424-
Some(LogsOptions::<String> {
439+
Some(LogsOptions {
425440
follow: true,
426441
stdout: true,
427442
stderr: true,
@@ -445,7 +460,7 @@ impl<'a> ContainerApi<'a> {
445460

446461
let mut exit_code_stream = self
447462
.client
448-
.wait_container(&id, None::<WaitContainerOptions<String>>);
463+
.wait_container(&id, None::<WaitContainerOptions>);
449464

450465
let _ = match exit_code_stream.next().await {
451466
Some(Ok(response)) => response.status_code,
@@ -475,7 +490,7 @@ impl<'a> ContainerApi<'a> {
475490
let log_task = tokio::spawn(async move {
476491
let logs_stream = docker_logs.logs(
477492
&s_id,
478-
Some(LogsOptions::<String> {
493+
Some(LogsOptions {
479494
follow: true,
480495
stdout: true,
481496
stderr: true,
@@ -502,7 +517,7 @@ impl<'a> ContainerApi<'a> {
502517

503518
let mut exit_code_stream = self
504519
.client
505-
.wait_container(&id, None::<WaitContainerOptions<String>>);
520+
.wait_container(&id, None::<WaitContainerOptions>);
506521

507522
let exit_code = match exit_code_stream.next().await {
508523
Some(Ok(response)) => response.status_code,
@@ -515,7 +530,7 @@ impl<'a> ContainerApi<'a> {
515530
}
516531

517532
pub async fn logs_to_stdout(&self, container_name: &str) -> Result<(), AnyError> {
518-
let log_options = LogsOptions::<String> {
533+
let log_options = LogsOptions {
519534
stdout: true,
520535
follow: true,
521536
..Default::default()

src/api/image.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use crate::{api::ImageApi, model::types::AnyError};
2-
use bollard::errors::Error;
32
use bollard::errors::Error::DockerResponseServerError;
4-
use bollard::image::CreateImageOptions;
53
use bollard::models::CreateImageInfo;
64
use bollard::service::ImageInspect;
5+
use bollard::{errors::Error, query_parameters::CreateImageOptions};
76
use futures::StreamExt;
87
use std::io::{stdout, Write};
98

@@ -12,12 +11,15 @@ impl<'a> ImageApi<'a> {
1211
println!("Pulling image: {}", &image);
1312
let img_chunks = &image.split(':').collect::<Vec<&str>>();
1413
let mut image_info = self.client.create_image(
15-
Some(CreateImageOptions::<&str> {
16-
from_image: img_chunks[0],
17-
tag: match img_chunks.len() {
18-
2 => img_chunks[1],
19-
_ => "latest",
20-
},
14+
Some(CreateImageOptions {
15+
from_image: Some(img_chunks[0].to_string()),
16+
tag: Some(
17+
match img_chunks.len() {
18+
2 => img_chunks[1],
19+
_ => "latest",
20+
}
21+
.to_string(),
22+
),
2123
..Default::default()
2224
}),
2325
None,

0 commit comments

Comments
 (0)