Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1997 from ndeloof/image_digest
Browse files Browse the repository at this point in the history
introduce ImageDigestLabel to track image built for service
  • Loading branch information
mat007 authored Aug 6, 2021
2 parents 5cfa7f5 + 64cea4f commit fff0ed2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 2 additions & 0 deletions pkg/api/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const (
OneoffLabel = "com.docker.compose.oneoff"
// SlugLabel stores unique slug used for one-off container identity
SlugLabel = "com.docker.compose.slug"
// ImageDigestLabel stores digest of the container image used to run service
ImageDigestLabel = "com.docker.compose.image"
// VersionLabel stores the compose tool version used to run application
VersionLabel = "com.docker.compose.version"
)
Expand Down
16 changes: 7 additions & 9 deletions pkg/compose/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (s *composeService) ensureImagesExists(ctx context.Context, project *types.
if quietPull {
mode = xprogress.PrinterModeQuiet
}
opts, imagesToBuild, err := s.getBuildOptions(project, images)
opts, err := s.getBuildOptions(project, images)
if err != nil {
return err
}
Expand All @@ -120,7 +120,7 @@ func (s *composeService) ensureImagesExists(ctx context.Context, project *types.
return err
}

if len(imagesToBuild) > 0 {
if len(builtImages) > 0 {
utils.DisplayScanSuggestMsg()
}
for name, digest := range builtImages {
Expand All @@ -130,18 +130,17 @@ func (s *composeService) ensureImagesExists(ctx context.Context, project *types.
for i, service := range project.Services {
digest, ok := images[getImageName(service, project.Name)]
if ok {
project.Services[i].Image = digest
project.Services[i].Labels[api.ImageDigestLabel] = digest
}
}
return nil
}

func (s *composeService) getBuildOptions(project *types.Project, images map[string]string) (map[string]build.Options, []string, error) {
func (s *composeService) getBuildOptions(project *types.Project, images map[string]string) (map[string]build.Options, error) {
opts := map[string]build.Options{}
imagesToBuild := []string{}
for _, service := range project.Services {
if service.Image == "" && service.Build == nil {
return nil, nil, fmt.Errorf("invalid service %q. Must specify either image or build", service.Name)
return nil, fmt.Errorf("invalid service %q. Must specify either image or build", service.Name)
}
imageName := getImageName(service, project.Name)
_, localImagePresent := images[imageName]
Expand All @@ -150,16 +149,15 @@ func (s *composeService) getBuildOptions(project *types.Project, images map[stri
if localImagePresent && service.PullPolicy != types.PullPolicyBuild {
continue
}
imagesToBuild = append(imagesToBuild, imageName)
opt, err := s.toBuildOptions(project, service, imageName)
if err != nil {
return nil, nil, err
return nil, err
}
opts[imageName] = opt
continue
}
}
return opts, imagesToBuild, nil
return opts, nil

}

Expand Down

0 comments on commit fff0ed2

Please sign in to comment.