Skip to content

Commit 2e78b55

Browse files
committed
introduce service hooks
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 49efa50 commit 2e78b55

File tree

5 files changed

+280
-112
lines changed

5 files changed

+280
-112
lines changed

loader/loader_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3509,3 +3509,49 @@ services:
35093509
},
35103510
})
35113511
}
3512+
3513+
func TestLoadServiceHooks(t *testing.T) {
3514+
p, err := loadYAML(`
3515+
name: load-service-hooks
3516+
services:
3517+
test:
3518+
post_start:
3519+
- command: echo start
3520+
user: root
3521+
privileged: true
3522+
working_dir: /
3523+
environment:
3524+
- FOO=BAR
3525+
pre_stop:
3526+
- command: echo stop
3527+
user: root
3528+
working_dir: /
3529+
environment:
3530+
FOO: BAR
3531+
3532+
`)
3533+
assert.NilError(t, err)
3534+
start := p.Services["test"].PostStart
3535+
assert.DeepEqual(t, start, []types.ServiceHook{
3536+
{
3537+
Command: types.ShellCommand{"echo", "start"},
3538+
User: "root",
3539+
Privileged: true,
3540+
WorkingDir: "/",
3541+
Environment: types.MappingWithEquals{
3542+
"FOO": strPtr("BAR"),
3543+
},
3544+
},
3545+
})
3546+
stop := p.Services["test"].PreStop
3547+
assert.DeepEqual(t, stop, []types.ServiceHook{
3548+
{
3549+
Command: types.ShellCommand{"echo", "stop"},
3550+
User: "root",
3551+
WorkingDir: "/",
3552+
Environment: types.MappingWithEquals{
3553+
"FOO": strPtr("BAR"),
3554+
},
3555+
},
3556+
})
3557+
}

schema/compose-spec.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@
370370
},
371371
"uniqueItems": true
372372
},
373+
"post_start": {"type": "array", "items": {"$ref": "#/definitions/service_hook"}},
374+
"pre_stop": {"type": "array", "items": {"$ref": "#/definitions/service_hook"}},
373375
"privileged": {"type": ["boolean", "string"]},
374376
"profiles": {"$ref": "#/definitions/list_of_strings"},
375377
"pull_policy": {"type": "string", "enum": [
@@ -816,6 +818,20 @@
816818
]
817819
},
818820

821+
"service_hook": {
822+
"id": "#/definitions/service_hook",
823+
"type": "object",
824+
"properties": {
825+
"command": {"$ref": "#/definitions/command"},
826+
"user": {"type": "string"},
827+
"privileged": {"type": ["boolean", "string"]},
828+
"working_dir": {"type": "string"},
829+
"environment": {"$ref": "#/definitions/list_or_dict"}
830+
},
831+
"additionalProperties": false,
832+
"patternProperties": {"^x-": {}}
833+
},
834+
819835
"env_file": {
820836
"oneOf": [
821837
{"type": "string"},

0 commit comments

Comments
 (0)