Skip to content

Add restart and required to DependsCondition #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub required: Option<bool>,
}

impl DependsCondition {
pub fn new(condition: impl Into<String>) -> 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)]
Expand Down
15 changes: 15 additions & 0 deletions tests/fixtures/v2-dependencies/long.yml
Original file line number Diff line number Diff line change
@@ -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