From 3bf943ed678c43ada0d33366e077dbc289361f4f Mon Sep 17 00:00:00 2001 From: abdennour Date: Sat, 4 Dec 2021 13:38:35 +0300 Subject: [PATCH] introduce config --images --only-built Ability to filter images by services which uses built images It solves #8994 ( option 2 ) Signed-off-by: abdennour 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. --- cmd/compose/convert.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd/compose/convert.go b/cmd/compose/convert.go index 125331d6b1..bdeab2f326 100644 --- a/cmd/compose/convert.go +++ b/cmd/compose/convert.go @@ -50,6 +50,7 @@ type convertOptions struct { profiles bool images bool hash string + onlyBuilt bool } func convertCommand(p *projectOptions, backend api.Service) *cobra.Command { @@ -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)") @@ -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) +}