Resolve dependent images (pre_start hooks, type: image volumes) in WithImagesResolved#894
Merged
Merged
Conversation
ndeloof
force-pushed
the
resolve-prestart-hook-images
branch
3 times, most recently
from
July 21, 2026 07:06
0da904e to
467d4e8
Compare
glours
approved these changes
Jul 21, 2026
glours
enabled auto-merge (rebase)
July 21, 2026 07:52
pre_start hooks run as ephemeral init containers with their own image, but WithImagesResolved only resolved the service image, leaving hook images un-pinned by `docker compose config --resolve-image-digests`. Extract the single-image digest resolution into a resolveImageDigest helper and apply it to both the service image and each pre_start hook image. Hooks without an explicit image (which fall back to the service image at runtime) are left untouched. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
`type: image` volumes mount an image, referenced by the volume source, so their digest should be pinned by `--resolve-image-digests` too. Resolve the source like the service image, unless it references another service by name (those map to a locally built image, not a registry digest). Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
glours
force-pushed
the
resolve-prestart-hook-images
branch
from
July 21, 2026 07:52
467d4e8 to
903ac4c
Compare
This was referenced Jul 21, 2026
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.
What I did
Project.WithImagesResolvedonly resolved the top-levelservice.Image, but a service can depend on other images that should be pinned bydocker compose config --resolve-image-digeststoo:pre_starthook images — hooks run as ephemeral init containers with their own image (ServiceHook.Image)type: imagevolume sources — these mount an image referenced by the volumesourceThis PR extracts the single-image digest resolution into a
resolveImageDigesthelper and applies it to the service image, eachpre_starthook image, and eachtype: imagevolume source.type: imagevolume sources that reference another service by name are resolved to a locally built image, not a registry digest, so they are skipped.Projectstays unchanged:WithServicesTransformoperates on adeepCopy, whosePreStart/Volumesslices have their own backing arrays, so the in-place updates never touch the caller's project.Motivation
Downstream in Docker Compose,
pre_starthook images are otherwise ignored by image resolution (see docker/compose#13924 / docker/compose#13937). That PR handlesconfig --images,pullandup, but digest resolution/locking has to be done here becauseWithImagesResolvedis the single place where digests are computed. Thetype: imagevolume case is the same class of dependent-image resolution.Tests
Test_ResolveImages_preStartHooks: a service withimage: alpine:3.20and twopre_starthooks (one withimage: alpine:3.19, one without an image) — asserts the service image and the explicit hook image are both resolved to...@sha256:..., and the image-less hook is left empty.Test_ResolveImages_imageVolumes: a service with three volumes — an externaltype: imagesource (alpine:3.19, resolved to a digest), atype: imagesource referencing another service (builder, left untouched), and a plain named volume (left untouched).