Skip to content

Commit 00fd1c1

Browse files
committed
inspect image ID after pull to se com.docker.compose.image
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 14ca112 commit 00fd1c1

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

pkg/compose/pull.go

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (s *composeService) pull(ctx context.Context, project *types.Project, opts
9595
}
9696

9797
eg.Go(func() error {
98-
err := s.pullServiceImage(ctx, service, info, s.configFile(), w, false)
98+
_, err := s.pullServiceImage(ctx, service, info, s.configFile(), w, false)
9999
if err != nil {
100100
if !opts.IgnoreFailures {
101101
if service.Build != nil {
@@ -118,20 +118,20 @@ func (s *composeService) pull(ctx context.Context, project *types.Project, opts
118118
return err
119119
}
120120

121-
func (s *composeService) pullServiceImage(ctx context.Context, service types.ServiceConfig, info moby.Info, configFile driver.Auth, w progress.Writer, quietPull bool) error {
121+
func (s *composeService) pullServiceImage(ctx context.Context, service types.ServiceConfig, info moby.Info, configFile driver.Auth, w progress.Writer, quietPull bool) (string, error) {
122122
w.Event(progress.Event{
123123
ID: service.Name,
124124
Status: progress.Working,
125125
Text: "Pulling",
126126
})
127127
ref, err := reference.ParseNormalizedNamed(service.Image)
128128
if err != nil {
129-
return err
129+
return "", err
130130
}
131131

132132
repoInfo, err := registry.ParseRepositoryInfo(ref)
133133
if err != nil {
134-
return err
134+
return "", err
135135
}
136136

137137
key := repoInfo.Index.Name
@@ -141,12 +141,12 @@ func (s *composeService) pullServiceImage(ctx context.Context, service types.Ser
141141

142142
authConfig, err := configFile.GetAuthConfig(key)
143143
if err != nil {
144-
return err
144+
return "", err
145145
}
146146

147147
buf, err := json.Marshal(authConfig)
148148
if err != nil {
149-
return err
149+
return "", err
150150
}
151151

152152
stream, err := s.apiClient().ImagePull(ctx, service.Image, moby.ImagePullOptions{
@@ -159,7 +159,7 @@ func (s *composeService) pullServiceImage(ctx context.Context, service types.Ser
159159
Status: progress.Error,
160160
Text: "Error",
161161
})
162-
return WrapCategorisedComposeError(err, PullFailure)
162+
return "", WrapCategorisedComposeError(err, PullFailure)
163163
}
164164

165165
dec := json.NewDecoder(stream)
@@ -169,10 +169,10 @@ func (s *composeService) pullServiceImage(ctx context.Context, service types.Ser
169169
if err == io.EOF {
170170
break
171171
}
172-
return WrapCategorisedComposeError(err, PullFailure)
172+
return "", WrapCategorisedComposeError(err, PullFailure)
173173
}
174174
if jm.Error != nil {
175-
return WrapCategorisedComposeError(errors.New(jm.Error.Message), PullFailure)
175+
return "", WrapCategorisedComposeError(errors.New(jm.Error.Message), PullFailure)
176176
}
177177
if !quietPull {
178178
toPullProgressEvent(service.Name, jm, w)
@@ -183,7 +183,12 @@ func (s *composeService) pullServiceImage(ctx context.Context, service types.Ser
183183
Status: progress.Done,
184184
Text: "Pulled",
185185
})
186-
return nil
186+
187+
inspected, _, err := s.dockerCli.Client().ImageInspectWithRaw(ctx, service.Image)
188+
if err != nil {
189+
return "", err
190+
}
191+
return inspected.ID, nil
187192
}
188193

189194
func (s *composeService) pullRequiredImages(ctx context.Context, project *types.Project, images map[string]string, quietPull bool) error {
@@ -220,18 +225,29 @@ func (s *composeService) pullRequiredImages(ctx context.Context, project *types.
220225
return progress.Run(ctx, func(ctx context.Context) error {
221226
w := progress.ContextWriter(ctx)
222227
eg, ctx := errgroup.WithContext(ctx)
223-
for _, service := range needPull {
224-
service := service
228+
pulledImages := make([]string, len(needPull))
229+
for i, service := range needPull {
230+
i, service := i, service
225231
eg.Go(func() error {
226-
err := s.pullServiceImage(ctx, service, info, s.configFile(), w, quietPull)
232+
id, err := s.pullServiceImage(ctx, service, info, s.configFile(), w, quietPull)
233+
pulledImages[i] = id
227234
if err != nil && service.Build != nil {
228235
// image can be built, so we can ignore pull failure
229236
return nil
230237
}
231238
return err
232239
})
233240
}
234-
return eg.Wait()
241+
for i, service := range needPull {
242+
if pulledImages[i] != "" {
243+
images[service.Image] = pulledImages[i]
244+
}
245+
}
246+
err := eg.Wait()
247+
if err != nil {
248+
return err
249+
}
250+
return err
235251
})
236252
}
237253

0 commit comments

Comments
 (0)