2017-06-16 17:24:00 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/containers/image/types"
|
|
|
|
"github.com/containers/storage/pkg/archive"
|
2017-07-23 23:01:37 +00:00
|
|
|
"github.com/kubernetes-incubator/cri-o/libkpod/common"
|
2017-07-22 02:07:40 +00:00
|
|
|
libkpodimage "github.com/kubernetes-incubator/cri-o/libkpod/image"
|
2017-06-16 17:24:00 +00:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/urfave/cli"
|
2017-08-04 13:04:52 +00:00
|
|
|
"golang.org/x/crypto/ssh/terminal"
|
2017-06-16 17:24:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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.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",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
pushDescription = fmt.Sprintf(`
|
|
|
|
Pushes an image to a specified location.
|
|
|
|
The Image "DESTINATION" uses a "transport":"details" format.
|
|
|
|
See kpod-push(1) section "DESTINATION" for the expected format`)
|
|
|
|
|
|
|
|
pushCommand = cli.Command{
|
|
|
|
Name: "push",
|
|
|
|
Usage: "push an image to a specified destination",
|
|
|
|
Description: pushDescription,
|
|
|
|
Flags: pushFlags,
|
|
|
|
Action: pushCmd,
|
|
|
|
ArgsUsage: "IMAGE DESTINATION",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func pushCmd(c *cli.Context) error {
|
|
|
|
var registryCreds *types.DockerAuthConfig
|
|
|
|
|
|
|
|
args := c.Args()
|
|
|
|
if len(args) < 2 {
|
|
|
|
return errors.New("kpod push requires exactly 2 arguments")
|
|
|
|
}
|
|
|
|
srcName := c.Args().Get(0)
|
|
|
|
destName := c.Args().Get(1)
|
|
|
|
|
|
|
|
signaturePolicy := c.String("signature-policy")
|
|
|
|
registryCredsString := c.String("creds")
|
|
|
|
certPath := c.String("cert-dir")
|
|
|
|
skipVerify := !c.BoolT("tls-verify")
|
|
|
|
removeSignatures := c.Bool("remove-signatures")
|
|
|
|
signBy := c.String("sign-by")
|
|
|
|
|
|
|
|
if registryCredsString != "" {
|
2017-07-24 01:38:03 +00:00
|
|
|
creds, err := common.ParseRegistryCreds(registryCredsString)
|
2017-06-16 17:24:00 +00:00
|
|
|
if err != nil {
|
2017-08-04 13:04:52 +00:00
|
|
|
if err == common.ErrNoPassword {
|
|
|
|
fmt.Print("Password: ")
|
|
|
|
password, err := terminal.ReadPassword(0)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "could not read password from terminal")
|
|
|
|
}
|
|
|
|
creds.Password = string(password)
|
|
|
|
} else {
|
|
|
|
return err
|
|
|
|
}
|
2017-06-16 17:24:00 +00:00
|
|
|
}
|
|
|
|
registryCreds = creds
|
|
|
|
}
|
|
|
|
|
2017-07-27 17:18:07 +00:00
|
|
|
config, err := getConfig(c)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "Could not get config")
|
|
|
|
}
|
|
|
|
store, err := getStore(config)
|
2017-06-16 17:24:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-07-23 23:12:36 +00:00
|
|
|
options := libkpodimage.CopyOptions{
|
2017-08-27 11:10:32 +00:00
|
|
|
Compression: archive.Uncompressed,
|
2017-06-16 17:24:00 +00:00
|
|
|
SignaturePolicyPath: signaturePolicy,
|
|
|
|
Store: store,
|
2017-07-23 23:01:37 +00:00
|
|
|
DockerRegistryOptions: common.DockerRegistryOptions{
|
2017-06-16 17:24:00 +00:00
|
|
|
DockerRegistryCreds: registryCreds,
|
|
|
|
DockerCertPath: certPath,
|
|
|
|
DockerInsecureSkipTLSVerify: skipVerify,
|
|
|
|
},
|
2017-07-23 23:01:37 +00:00
|
|
|
SigningOptions: common.SigningOptions{
|
2017-06-16 17:24:00 +00:00
|
|
|
RemoveSignatures: removeSignatures,
|
|
|
|
SignBy: signBy,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if !c.Bool("quiet") {
|
|
|
|
options.ReportWriter = os.Stderr
|
|
|
|
}
|
2017-07-23 23:12:36 +00:00
|
|
|
return libkpodimage.PushImage(srcName, destName, options)
|
2017-06-16 17:24:00 +00:00
|
|
|
}
|