feat: add pre_start lifecycle hook for init containers#885
Open
glours wants to merge 1 commit into
Open
Conversation
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>
17554a0 to
4d8d851
Compare
There was a problem hiding this comment.
Pull request overview
Adds support in compose-go for the Compose spec’s new pre_start lifecycle hook, representing an ordered list of init containers that run to completion before the main service container starts. This extends the model, schema validation, normalization, and loader test coverage so pre_start can be parsed/validated and can inherit the parent service image when omitted.
Changes:
- Added
pre_starttoServiceConfigand extendedServiceHookwithimageandper_replica. - Updated the JSON schema to validate
pre_startentries via a dedicatedpre_start_hookdefinition. - Implemented normalization to propagate the parent service
imagetopre_starthooks that omitimage, with accompanying tests.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| types/types.go | Adds PreStart field to the service model. |
| types/hooks.go | Extends ServiceHook to carry image and per_replica for pre_start. |
| types/derived.gen.go | Updates generated deep-copy logic for the new fields. |
| schema/compose-spec.json | Adds pre_start service property and $defs/pre_start_hook. |
| loader/normalize.go | Normalizes pre_start hooks to inherit the service image when omitted. |
| loader/tests/service_hooks_test.go | Adds coverage for parsing pre_start and image inheritance through loader. |
| loader/normalize_test.go | Adds coverage for normalization-time image inheritance behavior. |
Files not reviewed (1)
- types/derived.gen.go: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the
pre_startservice 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.