Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: keep pulled digest reference when tagging image (#4482)
Kyle Mendelle68c9081ab86
diff --git a/backend/internal/imageupdate/service.go b/backend/internal/imageupdate/service.goindex 12d3f8fc2..aadfa84c2 100644--- a/backend/internal/imageupdate/service.go+++ b/backend/internal/imageupdate/service.go@@ -548,9 +548,12 @@ func (s *ImageUpdateService) getImageRefByID(ctx context.Context, imageID stringif inspectErr != nil {return "", false}- for _, tag := range inspectResponse.RepoTags {- if tag != "<none>:<none>" {- return tag, true+ // Prefer a real tag over a digest name kept by the containerd image store.+ for _, pinned := range []bool{false, true} {+ for _, tag := range inspectResponse.RepoTags {+ if tag != "<none>:<none>" && refs.IsDigestPinnedReference(tag) == pinned {+ return tag, true+ }}}for _, digestValue := range inspectResponse.RepoDigests {@@ -665,7 +668,15 @@ func filterImageSummariesByContainerOptOut(images []image.Summary, containers []}for _, summary := range images {+ // A digest name kept beside a real tag (containerd image store) would save a+ // skipped result under the same image ID and replace the tag's result.+ hasTag := slices.ContainsFunc(summary.RepoTags, func(imageRef string) bool {+ return imageRef != "<none>:<none>" && !refs.IsDigestPinnedReference(imageRef)+ })for _, imageRef := range summary.RepoTags {+ if hasTag && refs.IsDigestPinnedReference(imageRef) {+ continue+ }if addCandidate(imageRef, summary.ID) {return filtered}diff --git a/backend/pkg/authz/access_policy_test.go b/backend/pkg/authz/access_policy_test.goindex 6c30b63b0..7e2e3965d 100644--- a/backend/pkg/authz/access_policy_test.go+++ b/backend/pkg/authz/access_policy_test.go@@ -4,7 +4,6 @@ import ("os""path/filepath""regexp"- "runtime""strings""testing"@@ -225,9 +224,10 @@ func findAccessSurfaceInternal(id string) (authz.AccessSurface, bool) {func repoRootInternal(t *testing.T) string {t.Helper()- _, filename, _, ok := runtime.Caller(0)- require.True(t, ok)- return filepath.Clean(filepath.Join(filepath.Dir(filename), "..", "..", ".."))+ // go test runs in the package directory; runtime.Caller breaks under -trimpath.+ wd, err := os.Getwd()+ require.NoError(t, err)+ return filepath.Clean(filepath.Join(wd, "..", "..", ".."))}func frontendRoutePathInternal(routesRoot, url string) string {diff --git a/backend/pkg/utils/imageref/pull.go b/backend/pkg/utils/imageref/pull.goindex 3a51e8afa..cd6f46398 100644--- a/backend/pkg/utils/imageref/pull.go+++ b/backend/pkg/utils/imageref/pull.go@@ -3,18 +3,15 @@ package imagerefimport ("context""fmt"- "log/slog"- "slices"- "github.com/distribution/reference""github.com/moby/moby/client""go.getarcane.app/updater/refs")// PullAsTag runs pull for the immutable pulled reference, tags it as selected,// and verifies the tag resolves to the pulled image. Both must name the same-// repository. A digest name the pull added to RepoTags (containerd image store)-// is removed so only the selected tag remains.+// repository. The digest name is kept on purpose: removing it deletes the image+// on the containerd image store.func PullAsTag(ctx context.Context, dockerClient *client.Client, pulled, selected string, pull func(context.Context) error) error {pulledRef, err := refs.NormalizeReference(pulled)if err != nil {@@ -28,16 +25,6 @@ func PullAsTag(ctx context.Context, dockerClient *client.Client, pulled, selectereturn fmt.Errorf("pulled image %s does not belong to repository of %s", pulled, selected)}- hasPulledName := func(repoTags []string) bool {- pulledName, parseErr := reference.ParseNormalizedNamed(pulled)- return parseErr == nil && slices.ContainsFunc(repoTags, func(tag string) bool {- named, tagErr := reference.ParseNormalizedNamed(tag)- return tagErr == nil && named.String() == pulledName.String()- })- }- before, inspectErr := dockerClient.ImageInspect(ctx, pulled)- hadPulledName := inspectErr == nil && hasPulledName(before.RepoTags)-if pullErr := pull(ctx); pullErr != nil {return pullErr}@@ -55,12 +42,5 @@ func PullAsTag(ctx context.Context, dockerClient *client.Client, pulled, selecteif pulledInspect.ID != selectedInspect.ID {return fmt.Errorf("%s resolves to %s after tagging, expected %s", selected, selectedInspect.ID, pulledInspect.ID)}-- // The tag already holds the image, so a leftover digest name is only cosmetic.- if !hadPulledName && hasPulledName(selectedInspect.RepoTags) {- if _, removeErr := dockerClient.ImageRemove(ctx, pulled, client.ImageRemoveOptions{}); removeErr != nil {- slog.WarnContext(ctx, "failed to remove pulled digest reference", "image", pulled, "error", removeErr)- }- }return nil}diff --git a/frontend/src/routes/(app)/images/components/image-table.svelte b/frontend/src/routes/(app)/images/components/image-table.svelteindex 285c372c7..45716d4a7 100644--- a/frontend/src/routes/(app)/images/components/image-table.svelte+++ b/frontend/src/routes/(app)/images/components/image-table.svelte@@ -724,7 +724,9 @@</DropdownMenu.Item>{/if}- {@const usableTag = item.repoTags?.find((tag) => tag !== '<none>:<none>')}+ {@const usableTags = item.repoTags?.filter((tag) => tag !== '<none>:<none>') ?? []}+ <!-- Prefer a real tag: a digest name kept beside it would pull the old pinned image. -->+ {@const usableTag = usableTags.find((tag) => !tag.includes('@')) ?? usableTags[0]}{#if canPullImage && hasPermission('images:pull', envId)}<DropdownMenu.Item onclick={() => handleInlineImagePull(usableTag || '', envId)} disabled={!usableTag}><DownloadIcon class="size-4" />