From c54036cfd69df7985363dc4f9011170bac2dbf79 Mon Sep 17 00:00:00 2001 From: Baylor Maloney Date: Mon, 19 May 2025 14:44:13 -0400 Subject: [PATCH 1/3] allow for healtcheck to be specified when creating a contaienr with the CreateContainerOptsBuilder --- src/opts/container.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/opts/container.rs b/src/opts/container.rs index 0ef099c..6440c0a 100644 --- a/src/opts/container.rs +++ b/src/opts/container.rs @@ -1,4 +1,4 @@ -use crate::models::{DeviceRequest, Labels, NetworkingConfig}; +use crate::models::{DeviceRequest, HealthConfig, Labels, NetworkingConfig}; use crate::opts::ImageName; use containers_api::opts::{Filter, FilterItem}; use containers_api::{ @@ -509,6 +509,11 @@ impl ContainerCreateOptsBuilder { self } + pub fn healthcheck(mut self, health_config: HealthConfig) -> Self { + self.params.insert("Healthcheck", json!(health_config)); + self + } + impl_str_field!( /// Specify the working dir (corresponds to the `-w` docker cli argument) working_dir => "WorkingDir" @@ -893,6 +898,19 @@ mod tests { r#"{"ExposedPorts":{"80/tcp":{}},"HostConfig":{"PortBindings":{"80/tcp":[{"HostIp":"::1","HostPort":"8080"}]}},"Image":"test_image"}"# ); + test_case!( + ContainerCreateOptsBuilder::default() + .image("test_image") + .healthcheck(HealthConfig{ + interval: Some(30), + timeout: Some(5), + retries: Some(3), + start_period: Some(10), + test: Some(vec![String::from("CMD-SHELL"), String::from("echo hello")]), + }), + r#"{"Healthcheck":{"Interval":30,"Retries":3,"StartPeriod":10,"Test":["CMD-SHELL","echo hello"],"Timeout":5},"HostConfig":{},"Image":"test_image"}"# + ); + test_case!( ContainerCreateOptsBuilder::default() .image("test_image") From 7e58a723ac0d46b15320578695dcfb104abefc6e Mon Sep 17 00:00:00 2001 From: Baylor Maloney Date: Mon, 19 May 2025 14:56:52 -0400 Subject: [PATCH 2/3] format --- src/opts/container.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/opts/container.rs b/src/opts/container.rs index 6440c0a..fb8679e 100644 --- a/src/opts/container.rs +++ b/src/opts/container.rs @@ -901,7 +901,7 @@ mod tests { test_case!( ContainerCreateOptsBuilder::default() .image("test_image") - .healthcheck(HealthConfig{ + .healthcheck(HealthConfig { interval: Some(30), timeout: Some(5), retries: Some(3), From 0bbd7f07b8ac469eeb20ca339a41883843213038 Mon Sep 17 00:00:00 2001 From: Baylor Maloney Date: Mon, 19 May 2025 14:59:07 -0400 Subject: [PATCH 3/3] has to be at least 1ms --- src/opts/container.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/opts/container.rs b/src/opts/container.rs index fb8679e..836190f 100644 --- a/src/opts/container.rs +++ b/src/opts/container.rs @@ -902,10 +902,10 @@ mod tests { ContainerCreateOptsBuilder::default() .image("test_image") .healthcheck(HealthConfig { - interval: Some(30), - timeout: Some(5), + interval: Some(1000000), + timeout: Some(5000000), retries: Some(3), - start_period: Some(10), + start_period: Some(10000000), test: Some(vec![String::from("CMD-SHELL"), String::from("echo hello")]), }), r#"{"Healthcheck":{"Interval":30,"Retries":3,"StartPeriod":10,"Test":["CMD-SHELL","echo hello"],"Timeout":5},"HostConfig":{},"Image":"test_image"}"#