diff --git a/src/lib.rs b/src/lib.rs index 81e2518..7f6bf12 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -332,10 +332,47 @@ impl DependsOnOptions { } } } - -#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Hash)] +/// https://docs.docker.com/reference/compose-file/services/#depends_on +#[derive(Default, Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Hash)] pub struct DependsCondition { pub condition: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub restart: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub required: Option, +} + +impl DependsCondition { + pub fn new(condition: impl Into) -> Self { + Self { + condition: condition.into(), + ..Default::default() + } + } + pub fn service_started() -> Self { + Self::new("service_started") + } + + pub fn service_healthy() -> Self { + Self::new("service_healthy") + } + + pub fn service_completed_successfully() -> Self { + Self::new("service_completed_successfully") + } + + pub fn with_restart(self, flag: bool) -> Self { + Self { + restart: Some(flag), + ..self + } + } + pub fn with_required(self, flag: bool) -> Self { + Self { + required: Some(flag), + ..self + } + } } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] diff --git a/tests/fixtures/v2-dependencies/long.yml b/tests/fixtures/v2-dependencies/long.yml new file mode 100644 index 0000000..7aa95a5 --- /dev/null +++ b/tests/fixtures/v2-dependencies/long.yml @@ -0,0 +1,15 @@ +services: + db: + image: busybox:1.31.0-uclibc + command: top + web: + image: busybox:1.31.0-uclibc + command: top + depends_on: + db: + condition: service_started + restart: true + required: true + console: + image: busybox:1.31.0-uclibc + command: top