Skip to content

Commit

Permalink
introduce depends_on.service
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Dec 18, 2024
1 parent 20738c5 commit c095387
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions schema/compose-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
"additionalProperties": false,
"patternProperties": {"^x-": {}},
"properties": {
"service": {"type": "string"},
"restart": {"type": ["boolean", "string"]},
"required": {
"type": "boolean",
Expand Down
8 changes: 6 additions & 2 deletions transform/dependson.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@ import (
func transformDependsOn(data any, p tree.Path, _ bool) (any, error) {
switch v := data.(type) {
case map[string]any:
for i, e := range v {
for k, e := range v {
d, ok := e.(map[string]any)
if !ok {
return nil, fmt.Errorf("%s.%s: unsupported value %s", p, i, v)
return nil, fmt.Errorf("%s.%s: unsupported value %s", p, k, v)
}
if _, ok := d["condition"]; !ok {
d["condition"] = "service_started"
}
if _, ok := d["required"]; !ok {
d["required"] = true
}
if _, ok := d["service"]; !ok {
d["service"] = k
}
}
return v, nil
case []any:
Expand All @@ -44,6 +47,7 @@ func transformDependsOn(data any, p tree.Path, _ bool) (any, error) {
d[k.(string)] = map[string]any{
"condition": "service_started",
"required": true,
"service": k,
}
}
return d, nil
Expand Down

0 comments on commit c095387

Please sign in to comment.