Skip to content

Commit

Permalink
introduce config --images --only-built
Browse files Browse the repository at this point in the history
Ability to filter images by services which uses built images

It solves docker#8994 ( option 2 )

Signed-off-by: abdennour <mail@abdennoor.com>
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.
  • Loading branch information
abdennour committed Dec 4, 2021
1 parent e2f33af commit 3bf943e
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 3bf943e

Please sign in to comment.