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

Commit

Permalink
extract pullDryRunSimulate from pullDryRun
Browse files Browse the repository at this point in the history
  • Loading branch information
satotake authored Jun 22, 2021
1 parent 65031c0 commit 8d64724
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions pkg/compose/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type pullDryRunServiceResult struct {
Plan string
}

type pullDrayRunView struct {
type pullDryRunResults struct {
Services []pullDryRunServiceResult
}

Expand All @@ -69,6 +69,23 @@ func (s *composeService) Pull(ctx context.Context, project *types.Project, opts
})
}

func (s *composeService) pullDryRun(ctx context.Context, project *types.Project, opts api.PullOptions) error {
results, err := s.pullDryRunSimulate(ctx, project, opts)
if err != nil {
return err
}
return formatter.Print(results, opts.Format, os.Stdout, func(w io.Writer) {
for _, service := range results.Services {
d := service.DistributionDigest
if d == "" {
// follow `docker images --digests` format
d = "<none>"
}
_, _ = fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", service.Name, service.Image, service.Plan, d)
}
}, "SERVICE", "IMAGE", "PLAN", "REMOTE DIGEST")
}

func getEncodedRegistryAuth(image string, info moby.Info, configFile driver.Auth) (string, error) {
ref, err := reference.ParseNormalizedNamed(image)
if err != nil {
Expand Down Expand Up @@ -204,13 +221,13 @@ func getPullPlan(service types.ServiceConfig, localDigests []string, dstrDigest
return
}

func (s *composeService) pullDryRun(ctx context.Context, project *types.Project, opts api.PullOptions) error {
func (s *composeService) pullDryRunSimulate(ctx context.Context, project *types.Project, opts api.PullOptions) (*pullDryRunResults, error) {
// ignore errors
dstrDigests, _ := s.getDistributionImagesDigests(ctx, project)

localDigests, err := s.getLocalImagesDigests(ctx, project)
if err != nil {
return err
return nil, err
}

var results []pullDryRunServiceResult
Expand All @@ -232,20 +249,8 @@ func (s *composeService) pullDryRun(ctx context.Context, project *types.Project,
results = append(results, *result)
}

view := &pullDrayRunView{
Services: results,
}
return &pullDryRunResults{Services: results}, nil

return formatter.Print(view, opts.Format, os.Stdout, func(w io.Writer) {
for _, result := range results {
d := result.DistributionDigest
if d == "" {
// follow `docker images --digests` format
d = "<none>"
}
_, _ = fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", result.Name, result.Image, result.Plan, d)
}
}, "SERVICE", "IMAGE", "PLAN", "REMOTE DIGEST")
}

func (s *composeService) pullRequiredImages(ctx context.Context, project *types.Project, images map[string]string, quietPull bool) error {
Expand Down

0 comments on commit 8d64724

Please sign in to comment.