From 8e1c113ec926201aa4a8aa89d85a1aa1d8aeda08 Mon Sep 17 00:00:00 2001 From: satotake Date: Tue, 22 Jun 2021 12:20:58 +0000 Subject: [PATCH] extract pullDryRunSimulate from pullDryRun Signed-off-by: GitHub --- pkg/compose/pull.go | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/pkg/compose/pull.go b/pkg/compose/pull.go index 8109144d23..4b82c34df8 100644 --- a/pkg/compose/pull.go +++ b/pkg/compose/pull.go @@ -53,7 +53,7 @@ type pullDryRunServiceResult struct { Plan string } -type pullDrayRunView struct { +type pullDryRunResults struct { Services []pullDryRunServiceResult } @@ -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 = "" + } + _, _ = 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 { @@ -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 @@ -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 = "" - } - _, _ = 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 {