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

Commit 8e1c113

Browse files
authored
extract pullDryRunSimulate from pullDryRun
Signed-off-by: GitHub <[email protected]>
1 parent 65031c0 commit 8e1c113

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

Diff for: pkg/compose/pull.go

+21-16
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type pullDryRunServiceResult struct {
5353
Plan string
5454
}
5555

56-
type pullDrayRunView struct {
56+
type pullDryRunResults struct {
5757
Services []pullDryRunServiceResult
5858
}
5959

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

72+
func (s *composeService) pullDryRun(ctx context.Context, project *types.Project, opts api.PullOptions) error {
73+
results, err := s.pullDryRunSimulate(ctx, project, opts)
74+
if err != nil {
75+
return err
76+
}
77+
return formatter.Print(results, opts.Format, os.Stdout, func(w io.Writer) {
78+
for _, service := range results.Services {
79+
d := service.DistributionDigest
80+
if d == "" {
81+
// follow `docker images --digests` format
82+
d = "<none>"
83+
}
84+
_, _ = fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", service.Name, service.Image, service.Plan, d)
85+
}
86+
}, "SERVICE", "IMAGE", "PLAN", "REMOTE DIGEST")
87+
}
88+
7289
func getEncodedRegistryAuth(image string, info moby.Info, configFile driver.Auth) (string, error) {
7390
ref, err := reference.ParseNormalizedNamed(image)
7491
if err != nil {
@@ -204,13 +221,13 @@ func getPullPlan(service types.ServiceConfig, localDigests []string, dstrDigest
204221
return
205222
}
206223

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

211228
localDigests, err := s.getLocalImagesDigests(ctx, project)
212229
if err != nil {
213-
return err
230+
return nil, err
214231
}
215232

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

235-
view := &pullDrayRunView{
236-
Services: results,
237-
}
252+
return &pullDryRunResults{Services: results}, nil
238253

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

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

0 commit comments

Comments
 (0)