Browse Source

introduce docker compose config --images

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 3 years ago
parent
commit
45956c36fb
1 changed files with 20 additions and 0 deletions
  1. 20 0
      cmd/compose/convert.go

+ 20 - 0
cmd/compose/convert.go

@@ -48,6 +48,7 @@ type convertOptions struct {
 	services            bool
 	volumes             bool
 	profiles            bool
+	images              bool
 	hash                string
 }
 
@@ -85,6 +86,9 @@ func convertCommand(p *projectOptions, backend api.Service) *cobra.Command {
 			if opts.profiles {
 				return runProfiles(opts, args)
 			}
+			if opts.images {
+				return runConfigImages(opts, args)
+			}
 
 			return runConvert(ctx, backend, opts, args)
 		}),
@@ -100,6 +104,7 @@ func convertCommand(p *projectOptions, backend api.Service) *cobra.Command {
 	flags.BoolVar(&opts.services, "services", false, "Print the service names, one per line.")
 	flags.BoolVar(&opts.volumes, "volumes", false, "Print the volume names, one per line.")
 	flags.BoolVar(&opts.profiles, "profiles", false, "Print the profile names, one per line.")
+	flags.BoolVar(&opts.images, "images", false, "Print the image names, one per line.")
 	flags.StringVar(&opts.hash, "hash", "", "Print the service config hash, one per line.")
 	flags.StringVarP(&opts.Output, "output", "o", "", "Save to file (default to stdout)")
 
@@ -215,3 +220,18 @@ func runProfiles(opts convertOptions, services []string) error {
 	}
 	return nil
 }
+
+func runConfigImages(opts convertOptions, services []string) error {
+	project, err := opts.toProject(services)
+	if err != nil {
+		return err
+	}
+	for _, s := range project.Services {
+		if s.Image != "" {
+			fmt.Println(s.Image)
+		} else {
+			fmt.Printf("%s_%s\n", project.Name, s.Name)
+		}
+	}
+	return nil
+}