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,
|
RunE: runlabel,
|
||||||
Args: cobra.MinimumNArgs(2),
|
Args: cobra.MinimumNArgs(2),
|
||||||
Example: `podman container runlabel run imageID
|
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`,
|
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.Optional1, "opt1", "", "Optional parameter to pass for install")
|
||||||
flags.StringVar(&runlabelOptions.Optional2, "opt2", "", "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.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.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.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)")
|
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("opt1")
|
||||||
_ = flags.MarkHidden("opt2")
|
_ = flags.MarkHidden("opt2")
|
||||||
_ = flags.MarkHidden("opt3")
|
_ = flags.MarkHidden("opt3")
|
||||||
|
_ = flags.MarkHidden("pull")
|
||||||
_ = flags.MarkHidden("signature-policy")
|
_ = flags.MarkHidden("signature-policy")
|
||||||
|
|
||||||
if err := flags.MarkDeprecated("pull", "podman will pull if not found in local storage"); err != nil {
|
if err := flags.MarkDeprecated("pull", "podman will pull if not found in local storage"); err != nil {
|
||||||
|
@ -7,12 +7,10 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/image/v5/types"
|
|
||||||
"github.com/containers/podman/v2/libpod/define"
|
"github.com/containers/podman/v2/libpod/define"
|
||||||
"github.com/containers/podman/v2/libpod/image"
|
"github.com/containers/podman/v2/libpod/image"
|
||||||
"github.com/containers/podman/v2/pkg/domain/entities"
|
"github.com/containers/podman/v2/pkg/domain/entities"
|
||||||
envLib "github.com/containers/podman/v2/pkg/env"
|
envLib "github.com/containers/podman/v2/pkg/env"
|
||||||
"github.com/containers/podman/v2/pkg/util"
|
|
||||||
"github.com/containers/podman/v2/utils"
|
"github.com/containers/podman/v2/utils"
|
||||||
"github.com/google/shlex"
|
"github.com/google/shlex"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -89,29 +87,17 @@ func (ic *ContainerEngine) runlabelImage(ctx context.Context, label string, imag
|
|||||||
// Fallthrough and pull!
|
// Fallthrough and pull!
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse credentials if specified.
|
pullOptions := entities.ImagePullOptions{
|
||||||
var credentials *types.DockerAuthConfig
|
Quiet: options.Quiet,
|
||||||
if options.Credentials != "" {
|
CertDir: options.CertDir,
|
||||||
credentials, err = util.ParseRegistryCreds(options.Credentials)
|
SkipTLSVerify: options.SkipTLSVerify,
|
||||||
if err != nil {
|
SignaturePolicy: options.SignaturePolicy,
|
||||||
return nil, err
|
Authfile: options.Authfile,
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if _, err := pull(ctx, ic.Libpod.ImageRuntime(), imageRef, pullOptions, &label); err != nil {
|
||||||
// Suppress pull progress bars if requested.
|
return nil, err
|
||||||
pullOutput := os.Stdout
|
|
||||||
if options.Quiet {
|
|
||||||
pullOutput = nil // c/image/copy takes care of the rest
|
|
||||||
}
|
}
|
||||||
|
return ic.Libpod.ImageRuntime().NewFromLocal(imageRef)
|
||||||
// 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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// generateRunlabelCommand generates the to-be-executed command as a string
|
// generateRunlabelCommand generates the to-be-executed command as a string
|
||||||
|
@ -214,7 +214,7 @@ func ToDomainHistoryLayer(layer *libpodImage.History) entities.ImageHistoryLayer
|
|||||||
return l
|
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
|
var writer io.Writer
|
||||||
if !options.Quiet {
|
if !options.Quiet {
|
||||||
writer = os.Stderr
|
writer = os.Stderr
|
||||||
@ -246,7 +246,7 @@ func (ir *ImageEngine) Pull(ctx context.Context, rawImage string, options entiti
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !options.AllTags {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -280,7 +280,7 @@ func (ir *ImageEngine) Pull(ctx context.Context, rawImage string, options entiti
|
|||||||
foundIDs := []string{}
|
foundIDs := []string{}
|
||||||
for _, tag := range tags {
|
for _, tag := range tags {
|
||||||
name := rawImage + ":" + tag
|
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 {
|
if err != nil {
|
||||||
logrus.Errorf("error pulling image %q", name)
|
logrus.Errorf("error pulling image %q", name)
|
||||||
continue
|
continue
|
||||||
@ -294,6 +294,10 @@ func (ir *ImageEngine) Pull(ctx context.Context, rawImage string, options entiti
|
|||||||
return &entities.ImagePullReport{Images: foundIDs}, nil
|
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) {
|
func (ir *ImageEngine) Inspect(ctx context.Context, namesOrIDs []string, opts entities.InspectOptions) ([]*entities.ImageInspectReport, []error, error) {
|
||||||
reports := []*entities.ImageInspectReport{}
|
reports := []*entities.ImageInspectReport{}
|
||||||
errs := []error{}
|
errs := []error{}
|
||||||
|
@ -29,6 +29,8 @@ var _ = Describe("podman container runlabel", func() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
|
// runlabel is not supported for remote connections
|
||||||
|
SkipIfRemote()
|
||||||
tempdir, err = CreateTempDirInTempDir()
|
tempdir, err = CreateTempDirInTempDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@ -46,7 +48,6 @@ var _ = Describe("podman container runlabel", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("podman container runlabel (podman --version)", func() {
|
It("podman container runlabel (podman --version)", func() {
|
||||||
SkipIfRemote()
|
|
||||||
image := "podman-runlabel-test:podman"
|
image := "podman-runlabel-test:podman"
|
||||||
podmanTest.BuildImage(PodmanDockerfile, image, "false")
|
podmanTest.BuildImage(PodmanDockerfile, image, "false")
|
||||||
|
|
||||||
@ -60,7 +61,6 @@ var _ = Describe("podman container runlabel", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("podman container runlabel (ls -la)", func() {
|
It("podman container runlabel (ls -la)", func() {
|
||||||
SkipIfRemote()
|
|
||||||
image := "podman-runlabel-test:ls"
|
image := "podman-runlabel-test:ls"
|
||||||
podmanTest.BuildImage(LsDockerfile, image, "false")
|
podmanTest.BuildImage(LsDockerfile, image, "false")
|
||||||
|
|
||||||
@ -72,9 +72,7 @@ var _ = Describe("podman container runlabel", func() {
|
|||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
Expect(result.ExitCode()).To(Equal(0))
|
Expect(result.ExitCode()).To(Equal(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman container runlabel --display", func() {
|
It("podman container runlabel --display", func() {
|
||||||
SkipIfRemote()
|
|
||||||
image := "podman-runlabel-test:ls"
|
image := "podman-runlabel-test:ls"
|
||||||
podmanTest.BuildImage(LsDockerfile, image, "false")
|
podmanTest.BuildImage(LsDockerfile, image, "false")
|
||||||
|
|
||||||
@ -115,7 +113,6 @@ var _ = Describe("podman container runlabel", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("runlabel should fail with nonexist authfile", func() {
|
It("runlabel should fail with nonexist authfile", func() {
|
||||||
SkipIfRemote()
|
|
||||||
image := "podman-runlabel-test:podman"
|
image := "podman-runlabel-test:podman"
|
||||||
podmanTest.BuildImage(PodmanDockerfile, image, "false")
|
podmanTest.BuildImage(PodmanDockerfile, image, "false")
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user