Skip to content

Commit

Permalink
introduce service hooks
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Oct 7, 2024
1 parent 49efa50 commit 2e78b55
Show file tree
Hide file tree
Showing 5 changed files with 280 additions and 112 deletions.
46 changes: 46 additions & 0 deletions loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3509,3 +3509,49 @@ services:
},
})
}

func TestLoadServiceHooks(t *testing.T) {
p, err := loadYAML(`
name: load-service-hooks
services:
test:
post_start:
- command: echo start
user: root
privileged: true
working_dir: /
environment:
- FOO=BAR
pre_stop:
- command: echo stop
user: root
working_dir: /
environment:
FOO: BAR
`)
assert.NilError(t, err)
start := p.Services["test"].PostStart
assert.DeepEqual(t, start, []types.ServiceHook{
{
Command: types.ShellCommand{"echo", "start"},
User: "root",
Privileged: true,
WorkingDir: "/",
Environment: types.MappingWithEquals{
"FOO": strPtr("BAR"),
},
},
})
stop := p.Services["test"].PreStop
assert.DeepEqual(t, stop, []types.ServiceHook{
{
Command: types.ShellCommand{"echo", "stop"},
User: "root",
WorkingDir: "/",
Environment: types.MappingWithEquals{
"FOO": strPtr("BAR"),
},
},
})
}
16 changes: 16 additions & 0 deletions schema/compose-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@
},
"uniqueItems": true
},
"post_start": {"type": "array", "items": {"$ref": "#/definitions/service_hook"}},
"pre_stop": {"type": "array", "items": {"$ref": "#/definitions/service_hook"}},
"privileged": {"type": ["boolean", "string"]},
"profiles": {"$ref": "#/definitions/list_of_strings"},
"pull_policy": {"type": "string", "enum": [
Expand Down Expand Up @@ -816,6 +818,20 @@
]
},

"service_hook": {
"id": "#/definitions/service_hook",
"type": "object",
"properties": {
"command": {"$ref": "#/definitions/command"},
"user": {"type": "string"},
"privileged": {"type": ["boolean", "string"]},
"working_dir": {"type": "string"},
"environment": {"$ref": "#/definitions/list_or_dict"}
},
"additionalProperties": false,
"patternProperties": {"^x-": {}}
},

"env_file": {
"oneOf": [
{"type": "string"},
Expand Down
Loading

0 comments on commit 2e78b55

Please sign in to comment.