Skip to content

Commit

Permalink
Merge pull request #7577 from rhatdan/runlabel1
Browse files Browse the repository at this point in the history
podman container runlabel should pull the image if it does not exist
  • Loading branch information
openshift-merge-robot authored Sep 10, 2020
2 parents 41bd5e2 + dfd10d2 commit 96bc5eb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 33 deletions.
5 changes: 3 additions & 2 deletions cmd/podman/containers/runlabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
}
)
Expand All @@ -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)")
Expand All @@ -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 {
Expand Down
32 changes: 9 additions & 23 deletions pkg/domain/infra/abi/containers_runlabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
}

// Suppress pull progress bars if requested.
pullOutput := os.Stdout
if options.Quiet {
pullOutput = nil // c/image/copy takes care of the rest
pullOptions := entities.ImagePullOptions{
Quiet: options.Quiet,
CertDir: options.CertDir,
SkipTLSVerify: options.SkipTLSVerify,
SignaturePolicy: options.SignaturePolicy,
Authfile: options.Authfile,
}

// Pull the image.
dockerRegistryOptions := image.DockerRegistryOptions{
DockerCertPath: options.CertDir,
DockerInsecureSkipTLSVerify: options.SkipTLSVerify,
DockerRegistryCreds: credentials,
if _, err := pull(ctx, ic.Libpod.ImageRuntime(), imageRef, pullOptions, &label); err != nil {
return nil, err
}

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
Expand Down
10 changes: 7 additions & 3 deletions pkg/domain/infra/abi/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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{}
Expand Down
7 changes: 2 additions & 5 deletions test/e2e/runlabel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")

Expand All @@ -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")

Expand All @@ -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")

Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit 96bc5eb

Please sign in to comment.