summaryrefslogtreecommitdiff
path: root/cmd/podman/push.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-01-31 13:20:04 -0600
committerbaude <bbaude@redhat.com>2019-02-08 10:26:43 -0600
commit25a3923b61a5ca014318e6d957f68abd03947297 (patch)
tree2ccb4a0bd9bda70c1c258dcb1b8aca8961d9ad30 /cmd/podman/push.go
parent962850c6e0dfcee926af31fc0ad24f1f6c26f8ac (diff)
downloadpodman-25a3923b61a5ca014318e6d957f68abd03947297.tar.gz
podman-25a3923b61a5ca014318e6d957f68abd03947297.tar.bz2
podman-25a3923b61a5ca014318e6d957f68abd03947297.zip
Migrate to cobra CLI
We intend to migrate to the cobra cli from urfave/cli because the project is more well maintained. There are also some technical reasons as well which extend into our remote client work. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman/push.go')
-rw-r--r--cmd/podman/push.go115
1 files changed, 45 insertions, 70 deletions
diff --git a/cmd/podman/push.go b/cmd/podman/push.go
index 361a25e35..a1ee00a65 100644
--- a/cmd/podman/push.go
+++ b/cmd/podman/push.go
@@ -2,6 +2,8 @@ package main
import (
"fmt"
+ "github.com/containers/libpod/cmd/podman/cliconfig"
+ "github.com/spf13/cobra"
"io"
"os"
"strings"
@@ -14,76 +16,52 @@ import (
"github.com/containers/libpod/pkg/util"
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
- "github.com/urfave/cli"
)
var (
- pushFlags = []cli.Flag{
- cli.StringFlag{
- Name: "signature-policy",
- Usage: "`Pathname` of signature policy file (not usually used)",
- Hidden: true,
- },
- cli.StringFlag{
- Name: "creds",
- Usage: "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry",
- },
- cli.StringFlag{
- Name: "cert-dir",
- Usage: "`Pathname` of a directory containing TLS certificates and keys",
- },
- cli.BoolFlag{
- Name: "compress",
- Usage: "Compress tarball image layers when pushing to a directory using the 'dir' transport. (default is same compression type as source)",
- },
- cli.StringFlag{
- Name: "format, f",
- Usage: "Manifest type (oci, v2s1, or v2s2) to use when pushing an image using the 'dir:' transport (default is manifest type of source)",
- },
- cli.BoolTFlag{
- Name: "tls-verify",
- Usage: "Require HTTPS and verify certificates when contacting registries (default: true)",
- },
- cli.BoolFlag{
- Name: "remove-signatures",
- Usage: "Discard any pre-existing signatures in the image",
- },
- cli.StringFlag{
- Name: "sign-by",
- Usage: "Add a signature at the destination using the specified key",
- },
- cli.BoolFlag{
- Name: "quiet, q",
- Usage: "Don't output progress information when pushing images",
- },
- cli.StringFlag{
- Name: "authfile",
- Usage: "Path of the authentication file. Default is ${XDG_RUNTIME_DIR}/containers/auth.json. Use REGISTRY_AUTH_FILE environment variable to override. ",
- },
- }
+ pushCommand cliconfig.PushValues
pushDescription = fmt.Sprintf(`
Pushes an image to a specified location.
The Image "DESTINATION" uses a "transport":"details" format.
See podman-push(1) section "DESTINATION" for the expected format`)
- pushCommand = cli.Command{
- Name: "push",
- Usage: "Push an image to a specified destination",
- Description: pushDescription,
- Flags: sortFlags(pushFlags),
- Action: pushCmd,
- ArgsUsage: "IMAGE DESTINATION",
- OnUsageError: usageErrorHandler,
+ _pushCommand = &cobra.Command{
+ Use: "push",
+ Short: "Push an image to a specified destination",
+ Long: pushDescription,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ pushCommand.InputArgs = args
+ pushCommand.GlobalFlags = MainGlobalOpts
+ return pushCmd(&pushCommand)
+ },
+ Example: "IMAGE DESTINATION",
}
)
-func pushCmd(c *cli.Context) error {
+func init() {
+ pushCommand.Command = _pushCommand
+ flags := pushCommand.Flags()
+ flags.MarkHidden("signature-policy")
+ flags.StringVar(&pushCommand.Authfile, "authfile", "", "Path of the authentication file. Default is ${XDG_RUNTIME_DIR}/containers/auth.json. Use REGISTRY_AUTH_FILE environment variable to override")
+ flags.StringVar(&pushCommand.CertDir, "cert-dir", "", "`Pathname` of a directory containing TLS certificates and keys")
+ flags.BoolVar(&pushCommand.Compress, "compress", false, "Compress tarball image layers when pushing to a directory using the 'dir' transport. (default is same compression type as source)")
+ flags.StringVar(&pushCommand.Creds, "creds", "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry")
+ flags.StringVarP(&pushCommand.Format, "format", "f", "", "Manifest type (oci, v2s1, or v2s2) to use when pushing an image using the 'dir:' transport (default is manifest type of source)")
+ flags.BoolVarP(&pushCommand.Quiet, "quiet", "q", false, "Don't output progress information when pushing images")
+ flags.BoolVar(&pushCommand.RemoveSignatures, "remove-signatures", false, "Discard any pre-existing signatures in the image")
+ flags.StringVar(&pushCommand.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)")
+ flags.StringVar(&pushCommand.SignBy, "sign-by", "", "Add a signature at the destination using the specified key")
+ flags.BoolVar(&pushCommand.TlsVerify, "tls-verify", true, "Require HTTPS and verify certificates when contacting registries (default: true)")
+ rootCmd.AddCommand(pushCommand.Command)
+}
+
+func pushCmd(c *cliconfig.PushValues) error {
var (
registryCreds *types.DockerAuthConfig
destName string
)
- args := c.Args()
+ args := c.InputArgs
if len(args) == 0 || len(args) > 2 {
return errors.New("podman push requires at least one image name, and optionally a second to specify a different destination name")
}
@@ -94,43 +72,40 @@ func pushCmd(c *cli.Context) error {
case 2:
destName = args[1]
}
- if err := validateFlags(c, pushFlags); err != nil {
- return err
- }
// --compress and --format can only be used for the "dir" transport
splitArg := strings.SplitN(destName, ":", 2)
- if c.IsSet("compress") || c.IsSet("format") {
+ if c.Flag("compress").Changed || c.Flag("format").Changed {
if splitArg[0] != directory.Transport.Name() {
return errors.Errorf("--compress and --format can be set only when pushing to a directory using the 'dir' transport")
}
}
- certPath := c.String("cert-dir")
- removeSignatures := c.Bool("remove-signatures")
- signBy := c.String("sign-by")
+ certPath := c.CertDir
+ removeSignatures := c.RemoveSignatures
+ signBy := c.SignBy
- if c.IsSet("creds") {
- creds, err := util.ParseRegistryCreds(c.String("creds"))
+ if c.Flag("creds").Changed {
+ creds, err := util.ParseRegistryCreds(c.Creds)
if err != nil {
return err
}
registryCreds = creds
}
- runtime, err := libpodruntime.GetRuntime(c)
+ runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "could not create runtime")
}
defer runtime.Shutdown(false)
var writer io.Writer
- if !c.Bool("quiet") {
+ if !c.Quiet {
writer = os.Stderr
}
var manifestType string
- if c.IsSet("format") {
+ if c.Flag("format").Changed {
switch c.String("format") {
case "oci":
manifestType = imgspecv1.MediaTypeImageManifest
@@ -147,8 +122,8 @@ func pushCmd(c *cli.Context) error {
DockerRegistryCreds: registryCreds,
DockerCertPath: certPath,
}
- if c.IsSet("tls-verify") {
- dockerRegistryOptions.DockerInsecureSkipTLSVerify = types.NewOptionalBool(!c.BoolT("tls-verify"))
+ if c.Flag("tls-verify").Changed {
+ dockerRegistryOptions.DockerInsecureSkipTLSVerify = types.NewOptionalBool(!c.TlsVerify)
}
so := image.SigningOptions{
@@ -161,7 +136,7 @@ func pushCmd(c *cli.Context) error {
return err
}
- authfile := getAuthFile(c.String("authfile"))
+ authfile := getAuthFile(c.Authfile)
- return newImage.PushImageToHeuristicDestination(getContext(), destName, manifestType, authfile, c.String("signature-policy"), writer, c.Bool("compress"), so, &dockerRegistryOptions, nil)
+ return newImage.PushImageToHeuristicDestination(getContext(), destName, manifestType, authfile, c.SignaturePolicy, writer, c.Compress, so, &dockerRegistryOptions, nil)
}