Skip to content
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

introduce service hooks #694

Merged
merged 1 commit into from
Oct 7, 2024
Merged
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
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