mirror of
https://github.com/docker/compose.git
synced 2026-08-27 03:45:29 +00:00
introduce --resolve-image-digests on config command
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
65fc4ffb4e
commit
0e862eeaa7
15 changed files with 72 additions and 112 deletions
|
|
@ -23,18 +23,23 @@ import (
|
|||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/docker/compose-cli/api/compose"
|
||||
|
||||
"github.com/cnabio/cnab-to-oci/remotes"
|
||||
"github.com/distribution/distribution/v3/reference"
|
||||
cliconfig "github.com/docker/cli/cli/config"
|
||||
"github.com/opencontainers/go-digest"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/docker/compose-cli/api/client"
|
||||
"github.com/docker/compose-cli/api/compose"
|
||||
"github.com/docker/compose-cli/api/config"
|
||||
)
|
||||
|
||||
type convertOptions struct {
|
||||
*projectOptions
|
||||
Format string
|
||||
Output string
|
||||
quiet bool
|
||||
Format string
|
||||
Output string
|
||||
quiet bool
|
||||
resolve bool
|
||||
}
|
||||
|
||||
var addFlagsFuncs []func(cmd *cobra.Command, opts *convertOptions)
|
||||
|
|
@ -61,6 +66,7 @@ func convertCommand(p *projectOptions) *cobra.Command {
|
|||
}
|
||||
flags := cmd.Flags()
|
||||
flags.StringVar(&opts.Format, "format", "yaml", "Format the output. Values: [yaml | json]")
|
||||
flags.BoolVar(&opts.resolve, "resolve-image-digests", false, "Pin image tags to digests.")
|
||||
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only validate the configuration, don't print anything.")
|
||||
|
||||
// add flags for hidden backends
|
||||
|
|
@ -82,6 +88,22 @@ func runConvert(ctx context.Context, opts convertOptions, services []string) err
|
|||
return err
|
||||
}
|
||||
|
||||
if opts.resolve {
|
||||
configFile, err := cliconfig.Load(config.Dir(ctx))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resolver := remotes.CreateResolver(configFile)
|
||||
err = project.ResolveImages(func(named reference.Named) (digest.Digest, error) {
|
||||
_, desc, err := resolver.Resolve(ctx, named.String())
|
||||
return desc.Digest, err
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
json, err = c.ComposeService().Convert(ctx, project, compose.ConvertOptions{
|
||||
Format: opts.Format,
|
||||
Output: opts.Output,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue