mirror of
https://github.com/containers/podman.git
synced 2025-06-24 11:28:24 +08:00
podman container runlabel should pull the image if it does not exist
Since --pull is deprecated, remove it from help and hide if from --help Also set it to true by default. Share image pull code betweern podman image pull and podman container runlabel. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1877181 Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
@ -30,7 +30,7 @@ var (
|
||||
RunE: runlabel,
|
||||
Args: cobra.MinimumNArgs(2),
|
||||
Example: `podman container runlabel run imageID
|
||||
podman container runlabel --pull install imageID arg1 arg2
|
||||
podman container runlabel install imageID arg1 arg2
|
||||
podman container runlabel --display run myImage`,
|
||||
}
|
||||
)
|
||||
@ -51,7 +51,7 @@ func init() {
|
||||
flags.StringVar(&runlabelOptions.Optional1, "opt1", "", "Optional parameter to pass for install")
|
||||
flags.StringVar(&runlabelOptions.Optional2, "opt2", "", "Optional parameter to pass for install")
|
||||
flags.StringVar(&runlabelOptions.Optional3, "opt3", "", "Optional parameter to pass for install")
|
||||
flags.BoolP("pull", "p", false, "Pull the image if it does not exist locally prior to executing the label contents")
|
||||
flags.BoolVarP(&runlabelOptions.Pull, "pull", "p", true, "Pull the image if it does not exist locally prior to executing the label contents")
|
||||
flags.BoolVarP(&runlabelOptions.Quiet, "quiet", "q", false, "Suppress output information when installing images")
|
||||
flags.BoolVar(&runlabelOptions.Replace, "replace", false, "Replace existing container with a new one from the image")
|
||||
flags.StringVar(&runlabelOptions.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)")
|
||||
@ -61,6 +61,7 @@ func init() {
|
||||
_ = flags.MarkHidden("opt1")
|
||||
_ = flags.MarkHidden("opt2")
|
||||
_ = flags.MarkHidden("opt3")
|
||||
_ = flags.MarkHidden("pull")
|
||||
_ = flags.MarkHidden("signature-policy")
|
||||
|
||||
if err := flags.MarkDeprecated("pull", "podman will pull if not found in local storage"); err != nil {
|
||||
|
@ -7,12 +7,10 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/image/v5/types"
|
||||
"github.com/containers/podman/v2/libpod/define"
|
||||
"github.com/containers/podman/v2/libpod/image"
|
||||
"github.com/containers/podman/v2/pkg/domain/entities"
|
||||
envLib "github.com/containers/podman/v2/pkg/env"
|
||||
"github.com/containers/podman/v2/pkg/util"
|
||||
"github.com/containers/podman/v2/utils"
|
||||
"github.com/google/shlex"
|
||||
"github.com/pkg/errors"
|
||||
@ -89,29 +87,17 @@ func (ic *ContainerEngine) runlabelImage(ctx context.Context, label string, imag
|
||||
// Fallthrough and pull!
|
||||
}
|
||||
|
||||
// Parse credentials if specified.
|
||||
var credentials *types.DockerAuthConfig
|
||||
if options.Credentials != "" {
|
||||
credentials, err = util.ParseRegistryCreds(options.Credentials)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pullOptions := entities.ImagePullOptions{
|
||||
Quiet: options.Quiet,
|
||||
CertDir: options.CertDir,
|
||||
SkipTLSVerify: options.SkipTLSVerify,
|
||||
SignaturePolicy: options.SignaturePolicy,
|
||||
Authfile: options.Authfile,
|
||||
}
|
||||
|
||||
// Suppress pull progress bars if requested.
|
||||
pullOutput := os.Stdout
|
||||
if options.Quiet {
|
||||
pullOutput = nil // c/image/copy takes care of the rest
|
||||
if _, err := pull(ctx, ic.Libpod.ImageRuntime(), imageRef, pullOptions, &label); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Pull the image.
|
||||
dockerRegistryOptions := image.DockerRegistryOptions{
|
||||
DockerCertPath: options.CertDir,
|
||||
DockerInsecureSkipTLSVerify: options.SkipTLSVerify,
|
||||
DockerRegistryCreds: credentials,
|
||||
}
|
||||
|
||||
return ic.Libpod.ImageRuntime().New(ctx, imageRef, options.SignaturePolicy, options.Authfile, pullOutput, &dockerRegistryOptions, image.SigningOptions{}, &label, util.PullImageMissing)
|
||||
return ic.Libpod.ImageRuntime().NewFromLocal(imageRef)
|
||||
}
|
||||
|
||||
// generateRunlabelCommand generates the to-be-executed command as a string
|
||||
|
@ -214,7 +214,7 @@ func ToDomainHistoryLayer(layer *libpodImage.History) entities.ImageHistoryLayer
|
||||
return l
|
||||
}
|
||||
|
||||
func (ir *ImageEngine) Pull(ctx context.Context, rawImage string, options entities.ImagePullOptions) (*entities.ImagePullReport, error) {
|
||||
func pull(ctx context.Context, runtime *image.Runtime, rawImage string, options entities.ImagePullOptions, label *string) (*entities.ImagePullReport, error) {
|
||||
var writer io.Writer
|
||||
if !options.Quiet {
|
||||
writer = os.Stderr
|
||||
@ -246,7 +246,7 @@ func (ir *ImageEngine) Pull(ctx context.Context, rawImage string, options entiti
|
||||
}
|
||||
|
||||
if !options.AllTags {
|
||||
newImage, err := ir.Libpod.ImageRuntime().New(ctx, rawImage, options.SignaturePolicy, options.Authfile, writer, &dockerRegistryOptions, image.SigningOptions{}, nil, util.PullImageAlways)
|
||||
newImage, err := runtime.New(ctx, rawImage, options.SignaturePolicy, options.Authfile, writer, &dockerRegistryOptions, image.SigningOptions{}, label, util.PullImageAlways)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -280,7 +280,7 @@ func (ir *ImageEngine) Pull(ctx context.Context, rawImage string, options entiti
|
||||
foundIDs := []string{}
|
||||
for _, tag := range tags {
|
||||
name := rawImage + ":" + tag
|
||||
newImage, err := ir.Libpod.ImageRuntime().New(ctx, name, options.SignaturePolicy, options.Authfile, writer, &dockerRegistryOptions, image.SigningOptions{}, nil, util.PullImageAlways)
|
||||
newImage, err := runtime.New(ctx, name, options.SignaturePolicy, options.Authfile, writer, &dockerRegistryOptions, image.SigningOptions{}, nil, util.PullImageAlways)
|
||||
if err != nil {
|
||||
logrus.Errorf("error pulling image %q", name)
|
||||
continue
|
||||
@ -294,6 +294,10 @@ func (ir *ImageEngine) Pull(ctx context.Context, rawImage string, options entiti
|
||||
return &entities.ImagePullReport{Images: foundIDs}, nil
|
||||
}
|
||||
|
||||
func (ir *ImageEngine) Pull(ctx context.Context, rawImage string, options entities.ImagePullOptions) (*entities.ImagePullReport, error) {
|
||||
return pull(ctx, ir.Libpod.ImageRuntime(), rawImage, options, nil)
|
||||
}
|
||||
|
||||
func (ir *ImageEngine) Inspect(ctx context.Context, namesOrIDs []string, opts entities.InspectOptions) ([]*entities.ImageInspectReport, []error, error) {
|
||||
reports := []*entities.ImageInspectReport{}
|
||||
errs := []error{}
|
||||
|
@ -29,6 +29,8 @@ var _ = Describe("podman container runlabel", func() {
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
// runlabel is not supported for remote connections
|
||||
SkipIfRemote()
|
||||
tempdir, err = CreateTempDirInTempDir()
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
@ -46,7 +48,6 @@ var _ = Describe("podman container runlabel", func() {
|
||||
})
|
||||
|
||||
It("podman container runlabel (podman --version)", func() {
|
||||
SkipIfRemote()
|
||||
image := "podman-runlabel-test:podman"
|
||||
podmanTest.BuildImage(PodmanDockerfile, image, "false")
|
||||
|
||||
@ -60,7 +61,6 @@ var _ = Describe("podman container runlabel", func() {
|
||||
})
|
||||
|
||||
It("podman container runlabel (ls -la)", func() {
|
||||
SkipIfRemote()
|
||||
image := "podman-runlabel-test:ls"
|
||||
podmanTest.BuildImage(LsDockerfile, image, "false")
|
||||
|
||||
@ -72,9 +72,7 @@ var _ = Describe("podman container runlabel", func() {
|
||||
result.WaitWithDefaultTimeout()
|
||||
Expect(result.ExitCode()).To(Equal(0))
|
||||
})
|
||||
|
||||
It("podman container runlabel --display", func() {
|
||||
SkipIfRemote()
|
||||
image := "podman-runlabel-test:ls"
|
||||
podmanTest.BuildImage(LsDockerfile, image, "false")
|
||||
|
||||
@ -115,7 +113,6 @@ var _ = Describe("podman container runlabel", func() {
|
||||
})
|
||||
|
||||
It("runlabel should fail with nonexist authfile", func() {
|
||||
SkipIfRemote()
|
||||
image := "podman-runlabel-test:podman"
|
||||
podmanTest.BuildImage(PodmanDockerfile, image, "false")
|
||||
|
||||
|
Reference in New Issue
Block a user