Skip to content

Commit

Permalink
Revert "Fix compose images that reutn a different image with the same…
Browse files Browse the repository at this point in the history
… ID"

This reverts commit 799ab84.

Signed-off-by: Tobias Schlatter <[email protected]>
  • Loading branch information
gzm0 committed Jan 8, 2025
1 parent a351585 commit 4ba0fc7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 122 deletions.
2 changes: 1 addition & 1 deletion pkg/compose/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func (s *composeService) getLocalImagesDigests(ctx context.Context, project *typ
imageNames = append(imageNames, imgName)
}
}
imgs, err := s.getImageSummaries(ctx, imageNames)
imgs, err := s.getImages(ctx, imageNames)
if err != nil {
return nil, err
}
Expand Down
39 changes: 21 additions & 18 deletions pkg/compose/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,20 @@ func (s *composeService) Images(ctx context.Context, projectName string, options
containers = allContainers
}

images := []string{}
imageIDs := []string{}
// aggregate image IDs
for _, c := range containers {
if !utils.StringContains(images, c.Image) {
images = append(images, c.Image)
if !utils.StringContains(imageIDs, c.ImageID) {
imageIDs = append(imageIDs, c.ImageID)
}
}
imageSummaries, err := s.getImageSummaries(ctx, images)
images, err := s.getImages(ctx, imageIDs)
if err != nil {
return nil, err
}
summary := make([]api.ImageSummary, len(containers))
for i, container := range containers {
img, ok := imageSummaries[container.Image]
img, ok := images[container.ImageID]
if !ok {
return nil, fmt.Errorf("failed to retrieve image for container %s", getCanonicalContainerName(container))
}
Expand All @@ -77,32 +78,34 @@ func (s *composeService) Images(ctx context.Context, projectName string, options
return summary, nil
}

func (s *composeService) getImageSummaries(ctx context.Context, repoTags []string) (map[string]api.ImageSummary, error) {
func (s *composeService) getImages(ctx context.Context, images []string) (map[string]api.ImageSummary, error) {
summary := map[string]api.ImageSummary{}
l := sync.Mutex{}
eg, ctx := errgroup.WithContext(ctx)
for _, repoTag := range repoTags {
repoTag := repoTag
for _, img := range images {
img := img
eg.Go(func() error {
inspect, _, err := s.apiClient().ImageInspectWithRaw(ctx, repoTag)
inspect, _, err := s.apiClient().ImageInspectWithRaw(ctx, img)
if err != nil {
if errdefs.IsNotFound(err) {
return nil
}
return fmt.Errorf("unable to get image '%s': %w", repoTag, err)
return fmt.Errorf("unable to get image '%s': %w", img, err)
}
tag := ""
repository := ""
ref, err := reference.ParseDockerRef(repoTag)
if err != nil {
return err
}
repository = reference.FamiliarName(ref)
if tagged, ok := ref.(reference.Tagged); ok {
tag = tagged.Tag()
if len(inspect.RepoTags) > 0 {
ref, err := reference.ParseDockerRef(inspect.RepoTags[0])
if err != nil {
return err
}
repository = reference.FamiliarName(ref)
if tagged, ok := ref.(reference.Tagged); ok {
tag = tagged.Tag()
}
}
l.Lock()
summary[repoTag] = api.ImageSummary{
summary[img] = api.ImageSummary{
ID: inspect.ID,
Repository: repository,
Tag: tag,
Expand Down
103 changes: 0 additions & 103 deletions pkg/compose/images_test.go

This file was deleted.

0 comments on commit 4ba0fc7

Please sign in to comment.