Skip to content

Commit

Permalink
Merge pull request #1 from ElmCompany/8994-convert-built-images
Browse files Browse the repository at this point in the history
introduce config --images --only-built
  • Loading branch information
abdennour committed Dec 4, 2021
2 parents e2f33af + 3bf943e commit 27016ae
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions cmd/compose/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type convertOptions struct {
profiles bool
images bool
hash string
onlyBuilt bool
}

func convertCommand(p *projectOptions, backend api.Service) *cobra.Command {
Expand Down Expand Up @@ -105,6 +106,7 @@ func convertCommand(p *projectOptions, backend api.Service) *cobra.Command {
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.BoolVar(&opts.onlyBuilt, "only-built", false, "filter only services which uses built images")
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)")

Expand Down Expand Up @@ -227,11 +229,16 @@ func runConfigImages(opts convertOptions, services []string) error {
return err
}
for _, s := range project.Services {
if s.Image != "" {
fmt.Println(s.Image)
} else {
fmt.Printf("%s_%s\n", project.Name, s.Name)
if !opts.onlyBuilt || (opts.onlyBuilt && s.Build != nil) {
fmt.Println(getImageName(s, *project))
}
}
return nil
}

func getImageName(s types.ServiceConfig, p types.Project) string {
if s.Image != "" {
return s.Image
}
return fmt.Sprintf("%s_%s", p.Name, s.Name)
}

0 comments on commit 27016ae

Please sign in to comment.