You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add pre_start lifecycle hook for init containers
Implements the `pre_start` service field introduced in
compose-spec/compose-spec#647: an ordered list
of init containers run to completion before the service container
starts. Each step runs in its own ephemeral container; a non-zero exit
fails the bring-up of the service and its dependents.
Compose-go owns parsing, validation via JSON schema, and image
inheritance: when a pre_start hook omits `image`, it is normalized
to the parent service's image. Volume/network inheritance and the
runtime execution stay with docker/compose.
Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
Copy file name to clipboardExpand all lines: schema/compose-spec.json
+42Lines changed: 42 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -688,6 +688,11 @@
688
688
},
689
689
"uniqueItems": true
690
690
},
691
+
"pre_start": {
692
+
"type": "array",
693
+
"items": {"$ref": "#/$defs/pre_start_hook"},
694
+
"description": "Init containers to run to completion before the service container is started. Each step runs in its own ephemeral container, in declared order; a non-zero exit fails the bring-up of the service and its dependents."
695
+
},
691
696
"post_start": {
692
697
"type": "array",
693
698
"items": {"$ref": "#/$defs/service_hook"},
@@ -1657,6 +1662,43 @@
1657
1662
"required": ["command"]
1658
1663
},
1659
1664
1665
+
"pre_start_hook": {
1666
+
"type": "object",
1667
+
"description": "Configuration for a pre_start init container, run to completion before the service container starts.",
1668
+
"properties": {
1669
+
"command": {
1670
+
"$ref": "#/$defs/command",
1671
+
"description": "Command to execute. Optional when the chosen image's entrypoint already runs the intended command."
1672
+
},
1673
+
"image": {
1674
+
"type": "string",
1675
+
"description": "Image used for the ephemeral container. If omitted, the parent service's image is used."
1676
+
},
1677
+
"user": {
1678
+
"type": "string",
1679
+
"description": "User to run the command as. Defaults to the user declared in image (or to the service's user when image is omitted)."
1680
+
},
1681
+
"privileged": {
1682
+
"type": ["boolean", "string"],
1683
+
"description": "Whether to run the command with extended privileges."
1684
+
},
1685
+
"working_dir": {
1686
+
"type": "string",
1687
+
"description": "Working directory for the command. Defaults to the service's working directory."
1688
+
},
1689
+
"environment": {
1690
+
"$ref": "#/$defs/list_or_dict",
1691
+
"description": "Environment variables for the command. Appended to or overriding the service environment."
1692
+
},
1693
+
"per_replica": {
1694
+
"type": ["boolean", "string"],
1695
+
"description": "Whether the hook runs once per service replica (true), or once for the service as a whole before any replica starts (false, the default)."
0 commit comments