Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit fff0ed2

Browse files
authored
Merge pull request #1997 from ndeloof/image_digest
introduce ImageDigestLabel to track image built for service
2 parents 5cfa7f5 + 64cea4f commit fff0ed2

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

pkg/api/labels.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ const (
4747
OneoffLabel = "com.docker.compose.oneoff"
4848
// SlugLabel stores unique slug used for one-off container identity
4949
SlugLabel = "com.docker.compose.slug"
50+
// ImageDigestLabel stores digest of the container image used to run service
51+
ImageDigestLabel = "com.docker.compose.image"
5052
// VersionLabel stores the compose tool version used to run application
5153
VersionLabel = "com.docker.compose.version"
5254
)

pkg/compose/build.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (s *composeService) ensureImagesExists(ctx context.Context, project *types.
111111
if quietPull {
112112
mode = xprogress.PrinterModeQuiet
113113
}
114-
opts, imagesToBuild, err := s.getBuildOptions(project, images)
114+
opts, err := s.getBuildOptions(project, images)
115115
if err != nil {
116116
return err
117117
}
@@ -120,7 +120,7 @@ func (s *composeService) ensureImagesExists(ctx context.Context, project *types.
120120
return err
121121
}
122122

123-
if len(imagesToBuild) > 0 {
123+
if len(builtImages) > 0 {
124124
utils.DisplayScanSuggestMsg()
125125
}
126126
for name, digest := range builtImages {
@@ -130,18 +130,17 @@ func (s *composeService) ensureImagesExists(ctx context.Context, project *types.
130130
for i, service := range project.Services {
131131
digest, ok := images[getImageName(service, project.Name)]
132132
if ok {
133-
project.Services[i].Image = digest
133+
project.Services[i].Labels[api.ImageDigestLabel] = digest
134134
}
135135
}
136136
return nil
137137
}
138138

139-
func (s *composeService) getBuildOptions(project *types.Project, images map[string]string) (map[string]build.Options, []string, error) {
139+
func (s *composeService) getBuildOptions(project *types.Project, images map[string]string) (map[string]build.Options, error) {
140140
opts := map[string]build.Options{}
141-
imagesToBuild := []string{}
142141
for _, service := range project.Services {
143142
if service.Image == "" && service.Build == nil {
144-
return nil, nil, fmt.Errorf("invalid service %q. Must specify either image or build", service.Name)
143+
return nil, fmt.Errorf("invalid service %q. Must specify either image or build", service.Name)
145144
}
146145
imageName := getImageName(service, project.Name)
147146
_, localImagePresent := images[imageName]
@@ -150,16 +149,15 @@ func (s *composeService) getBuildOptions(project *types.Project, images map[stri
150149
if localImagePresent && service.PullPolicy != types.PullPolicyBuild {
151150
continue
152151
}
153-
imagesToBuild = append(imagesToBuild, imageName)
154152
opt, err := s.toBuildOptions(project, service, imageName)
155153
if err != nil {
156-
return nil, nil, err
154+
return nil, err
157155
}
158156
opts[imageName] = opt
159157
continue
160158
}
161159
}
162-
return opts, imagesToBuild, nil
160+
return opts, nil
163161

164162
}
165163

0 commit comments

Comments
 (0)