Skip to content

feat: add pre_start lifecycle hook for init containers#885

Open
glours wants to merge 1 commit into
compose-spec:mainfrom
glours:pre-start-init-containers
Open

feat: add pre_start lifecycle hook for init containers#885
glours wants to merge 1 commit into
compose-spec:mainfrom
glours:pre-start-init-containers

Conversation

@glours

@glours glours commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

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.

@glours glours requested a review from ndeloof as a code owner June 16, 2026 13:01
@glours glours self-assigned this Jun 16, 2026
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>
@glours glours force-pushed the pre-start-init-containers branch from 17554a0 to 4d8d851 Compare June 16, 2026 13:05
@glours glours requested a review from Copilot June 16, 2026 13:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_start to ServiceConfig and extended ServiceHook with image and per_replica.
  • Updated the JSON schema to validate pre_start entries via a dedicated pre_start_hook definition.
  • Implemented normalization to propagate the parent service image to pre_start hooks that omit image, 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.

Comment thread loader/normalize.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants