Skip to content

Commit

Permalink
inspect image ID after pull to se com.docker.compose.image
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Apr 21, 2022
1 parent 14ca112 commit 00fd1c1
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions pkg/compose/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (s *composeService) pull(ctx context.Context, project *types.Project, opts
}

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

func (s *composeService) pullServiceImage(ctx context.Context, service types.ServiceConfig, info moby.Info, configFile driver.Auth, w progress.Writer, quietPull bool) error {
func (s *composeService) pullServiceImage(ctx context.Context, service types.ServiceConfig, info moby.Info, configFile driver.Auth, w progress.Writer, quietPull bool) (string, error) {
w.Event(progress.Event{
ID: service.Name,
Status: progress.Working,
Text: "Pulling",
})
ref, err := reference.ParseNormalizedNamed(service.Image)
if err != nil {
return err
return "", err
}

repoInfo, err := registry.ParseRepositoryInfo(ref)
if err != nil {
return err
return "", err
}

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

authConfig, err := configFile.GetAuthConfig(key)
if err != nil {
return err
return "", err
}

buf, err := json.Marshal(authConfig)
if err != nil {
return err
return "", err
}

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

dec := json.NewDecoder(stream)
Expand All @@ -169,10 +169,10 @@ func (s *composeService) pullServiceImage(ctx context.Context, service types.Ser
if err == io.EOF {
break
}
return WrapCategorisedComposeError(err, PullFailure)
return "", WrapCategorisedComposeError(err, PullFailure)
}
if jm.Error != nil {
return WrapCategorisedComposeError(errors.New(jm.Error.Message), PullFailure)
return "", WrapCategorisedComposeError(errors.New(jm.Error.Message), PullFailure)
}
if !quietPull {
toPullProgressEvent(service.Name, jm, w)
Expand All @@ -183,7 +183,12 @@ func (s *composeService) pullServiceImage(ctx context.Context, service types.Ser
Status: progress.Done,
Text: "Pulled",
})
return nil

inspected, _, err := s.dockerCli.Client().ImageInspectWithRaw(ctx, service.Image)
if err != nil {
return "", err
}
return inspected.ID, nil
}

func (s *composeService) pullRequiredImages(ctx context.Context, project *types.Project, images map[string]string, quietPull bool) error {
Expand Down Expand Up @@ -220,18 +225,29 @@ func (s *composeService) pullRequiredImages(ctx context.Context, project *types.
return progress.Run(ctx, func(ctx context.Context) error {
w := progress.ContextWriter(ctx)
eg, ctx := errgroup.WithContext(ctx)
for _, service := range needPull {
service := service
pulledImages := make([]string, len(needPull))
for i, service := range needPull {
i, service := i, service
eg.Go(func() error {
err := s.pullServiceImage(ctx, service, info, s.configFile(), w, quietPull)
id, err := s.pullServiceImage(ctx, service, info, s.configFile(), w, quietPull)
pulledImages[i] = id
if err != nil && service.Build != nil {
// image can be built, so we can ignore pull failure
return nil
}
return err
})
}
return eg.Wait()
for i, service := range needPull {
if pulledImages[i] != "" {
images[service.Image] = pulledImages[i]
}
}
err := eg.Wait()
if err != nil {
return err
}
return err
})
}

Expand Down

0 comments on commit 00fd1c1

Please sign in to comment.