mirror of https://github.com/containers/podman.git
Merge pull request #9133 from rhatdan/pull1
Cleanup bindings for image pull
This commit is contained in:
commit
0fe3d43ef1
|
@ -2,7 +2,6 @@ package images
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/containers/buildah/imagebuildah"
|
"github.com/containers/buildah/imagebuildah"
|
||||||
"github.com/containers/common/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate go run ../generator/generator.go RemoveOptions
|
//go:generate go run ../generator/generator.go RemoveOptions
|
||||||
|
@ -138,32 +137,25 @@ type PullOptions struct {
|
||||||
// AllTags can be specified to pull all tags of an image. Note
|
// AllTags can be specified to pull all tags of an image. Note
|
||||||
// that this only works if the image does not include a tag.
|
// that this only works if the image does not include a tag.
|
||||||
AllTags *bool
|
AllTags *bool
|
||||||
|
// Arch will overwrite the local architecture for image pulls.
|
||||||
|
Arch *string
|
||||||
// Authfile is the path to the authentication file. Ignored for remote
|
// Authfile is the path to the authentication file. Ignored for remote
|
||||||
// calls.
|
// calls.
|
||||||
Authfile *string
|
Authfile *string
|
||||||
// CertDir is the path to certificate directories. Ignored for remote
|
|
||||||
// calls.
|
|
||||||
CertDir *string
|
|
||||||
// Username for authenticating against the registry.
|
|
||||||
Username *string
|
|
||||||
// Password for authenticating against the registry.
|
|
||||||
Password *string
|
|
||||||
// Arch will overwrite the local architecture for image pulls.
|
|
||||||
Arch *string
|
|
||||||
// OS will overwrite the local operating system (OS) for image
|
// OS will overwrite the local operating system (OS) for image
|
||||||
// pulls.
|
// pulls.
|
||||||
OS *string
|
OS *string
|
||||||
// Variant will overwrite the local variant for image pulls.
|
// Password for authenticating against the registry.
|
||||||
Variant *string
|
Password *string
|
||||||
// Quiet can be specified to suppress pull progress when pulling. Ignored
|
// Quiet can be specified to suppress pull progress when pulling. Ignored
|
||||||
// for remote calls.
|
// for remote calls.
|
||||||
Quiet *bool
|
Quiet *bool
|
||||||
// SignaturePolicy to use when pulling. Ignored for remote calls.
|
|
||||||
SignaturePolicy *string
|
|
||||||
// SkipTLSVerify to skip HTTPS and certificate verification.
|
// SkipTLSVerify to skip HTTPS and certificate verification.
|
||||||
SkipTLSVerify *bool
|
SkipTLSVerify *bool
|
||||||
// PullPolicy whether to pull new image
|
// Username for authenticating against the registry.
|
||||||
PullPolicy *config.PullPolicy
|
Username *string
|
||||||
|
// Variant will overwrite the local variant for image pulls.
|
||||||
|
Variant *string
|
||||||
}
|
}
|
||||||
|
|
||||||
//BuildOptions are optional options for building images
|
//BuildOptions are optional options for building images
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/common/pkg/config"
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
@ -104,70 +103,6 @@ func (o *PullOptions) GetAllTags() bool {
|
||||||
return *o.AllTags
|
return *o.AllTags
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithAuthfile
|
|
||||||
func (o *PullOptions) WithAuthfile(value string) *PullOptions {
|
|
||||||
v := &value
|
|
||||||
o.Authfile = v
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetAuthfile
|
|
||||||
func (o *PullOptions) GetAuthfile() string {
|
|
||||||
var authfile string
|
|
||||||
if o.Authfile == nil {
|
|
||||||
return authfile
|
|
||||||
}
|
|
||||||
return *o.Authfile
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithCertDir
|
|
||||||
func (o *PullOptions) WithCertDir(value string) *PullOptions {
|
|
||||||
v := &value
|
|
||||||
o.CertDir = v
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCertDir
|
|
||||||
func (o *PullOptions) GetCertDir() string {
|
|
||||||
var certDir string
|
|
||||||
if o.CertDir == nil {
|
|
||||||
return certDir
|
|
||||||
}
|
|
||||||
return *o.CertDir
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithUsername
|
|
||||||
func (o *PullOptions) WithUsername(value string) *PullOptions {
|
|
||||||
v := &value
|
|
||||||
o.Username = v
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetUsername
|
|
||||||
func (o *PullOptions) GetUsername() string {
|
|
||||||
var username string
|
|
||||||
if o.Username == nil {
|
|
||||||
return username
|
|
||||||
}
|
|
||||||
return *o.Username
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithPassword
|
|
||||||
func (o *PullOptions) WithPassword(value string) *PullOptions {
|
|
||||||
v := &value
|
|
||||||
o.Password = v
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPassword
|
|
||||||
func (o *PullOptions) GetPassword() string {
|
|
||||||
var password string
|
|
||||||
if o.Password == nil {
|
|
||||||
return password
|
|
||||||
}
|
|
||||||
return *o.Password
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithArch
|
// WithArch
|
||||||
func (o *PullOptions) WithArch(value string) *PullOptions {
|
func (o *PullOptions) WithArch(value string) *PullOptions {
|
||||||
v := &value
|
v := &value
|
||||||
|
@ -184,6 +119,22 @@ func (o *PullOptions) GetArch() string {
|
||||||
return *o.Arch
|
return *o.Arch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithAuthfile
|
||||||
|
func (o *PullOptions) WithAuthfile(value string) *PullOptions {
|
||||||
|
v := &value
|
||||||
|
o.Authfile = v
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAuthfile
|
||||||
|
func (o *PullOptions) GetAuthfile() string {
|
||||||
|
var authfile string
|
||||||
|
if o.Authfile == nil {
|
||||||
|
return authfile
|
||||||
|
}
|
||||||
|
return *o.Authfile
|
||||||
|
}
|
||||||
|
|
||||||
// WithOS
|
// WithOS
|
||||||
func (o *PullOptions) WithOS(value string) *PullOptions {
|
func (o *PullOptions) WithOS(value string) *PullOptions {
|
||||||
v := &value
|
v := &value
|
||||||
|
@ -200,20 +151,20 @@ func (o *PullOptions) GetOS() string {
|
||||||
return *o.OS
|
return *o.OS
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithVariant
|
// WithPassword
|
||||||
func (o *PullOptions) WithVariant(value string) *PullOptions {
|
func (o *PullOptions) WithPassword(value string) *PullOptions {
|
||||||
v := &value
|
v := &value
|
||||||
o.Variant = v
|
o.Password = v
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVariant
|
// GetPassword
|
||||||
func (o *PullOptions) GetVariant() string {
|
func (o *PullOptions) GetPassword() string {
|
||||||
var variant string
|
var password string
|
||||||
if o.Variant == nil {
|
if o.Password == nil {
|
||||||
return variant
|
return password
|
||||||
}
|
}
|
||||||
return *o.Variant
|
return *o.Password
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithQuiet
|
// WithQuiet
|
||||||
|
@ -232,22 +183,6 @@ func (o *PullOptions) GetQuiet() bool {
|
||||||
return *o.Quiet
|
return *o.Quiet
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithSignaturePolicy
|
|
||||||
func (o *PullOptions) WithSignaturePolicy(value string) *PullOptions {
|
|
||||||
v := &value
|
|
||||||
o.SignaturePolicy = v
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetSignaturePolicy
|
|
||||||
func (o *PullOptions) GetSignaturePolicy() string {
|
|
||||||
var signaturePolicy string
|
|
||||||
if o.SignaturePolicy == nil {
|
|
||||||
return signaturePolicy
|
|
||||||
}
|
|
||||||
return *o.SignaturePolicy
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithSkipTLSVerify
|
// WithSkipTLSVerify
|
||||||
func (o *PullOptions) WithSkipTLSVerify(value bool) *PullOptions {
|
func (o *PullOptions) WithSkipTLSVerify(value bool) *PullOptions {
|
||||||
v := &value
|
v := &value
|
||||||
|
@ -264,18 +199,34 @@ func (o *PullOptions) GetSkipTLSVerify() bool {
|
||||||
return *o.SkipTLSVerify
|
return *o.SkipTLSVerify
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithPullPolicy
|
// WithUsername
|
||||||
func (o *PullOptions) WithPullPolicy(value config.PullPolicy) *PullOptions {
|
func (o *PullOptions) WithUsername(value string) *PullOptions {
|
||||||
v := &value
|
v := &value
|
||||||
o.PullPolicy = v
|
o.Username = v
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPullPolicy
|
// GetUsername
|
||||||
func (o *PullOptions) GetPullPolicy() config.PullPolicy {
|
func (o *PullOptions) GetUsername() string {
|
||||||
var pullPolicy config.PullPolicy
|
var username string
|
||||||
if o.PullPolicy == nil {
|
if o.Username == nil {
|
||||||
return pullPolicy
|
return username
|
||||||
}
|
}
|
||||||
return *o.PullPolicy
|
return *o.Username
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithVariant
|
||||||
|
func (o *PullOptions) WithVariant(value string) *PullOptions {
|
||||||
|
v := &value
|
||||||
|
o.Variant = v
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetVariant
|
||||||
|
func (o *PullOptions) GetVariant() string {
|
||||||
|
var variant string
|
||||||
|
if o.Variant == nil {
|
||||||
|
return variant
|
||||||
|
}
|
||||||
|
return *o.Variant
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,8 +106,9 @@ func (ir *ImageEngine) Prune(ctx context.Context, opts entities.ImagePruneOption
|
||||||
|
|
||||||
func (ir *ImageEngine) Pull(ctx context.Context, rawImage string, opts entities.ImagePullOptions) (*entities.ImagePullReport, error) {
|
func (ir *ImageEngine) Pull(ctx context.Context, rawImage string, opts entities.ImagePullOptions) (*entities.ImagePullReport, error) {
|
||||||
options := new(images.PullOptions)
|
options := new(images.PullOptions)
|
||||||
options.WithAllTags(opts.AllTags).WithAuthfile(opts.Authfile).WithCertDir(opts.CertDir).WithArch(opts.Arch).WithOS(opts.OS)
|
options.WithAllTags(opts.AllTags).WithAuthfile(opts.Authfile).WithArch(opts.Arch).WithOS(opts.OS)
|
||||||
options.WithVariant(opts.Variant).WithPassword(opts.Password).WithPullPolicy(opts.PullPolicy)
|
options.WithVariant(opts.Variant).WithPassword(opts.Password)
|
||||||
|
options.WithQuiet(opts.Quiet).WithUsername(opts.Username)
|
||||||
if s := opts.SkipTLSVerify; s != types.OptionalBoolUndefined {
|
if s := opts.SkipTLSVerify; s != types.OptionalBoolUndefined {
|
||||||
if s == types.OptionalBoolTrue {
|
if s == types.OptionalBoolTrue {
|
||||||
options.WithSkipTLSVerify(true)
|
options.WithSkipTLSVerify(true)
|
||||||
|
@ -115,7 +116,6 @@ func (ir *ImageEngine) Pull(ctx context.Context, rawImage string, opts entities.
|
||||||
options.WithSkipTLSVerify(false)
|
options.WithSkipTLSVerify(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
options.WithQuiet(opts.Quiet).WithSignaturePolicy(opts.SignaturePolicy).WithUsername(opts.Username)
|
|
||||||
pulledImages, err := images.Pull(ir.ClientCtx, rawImage, options)
|
pulledImages, err := images.Pull(ir.ClientCtx, rawImage, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -522,4 +522,31 @@ var _ = Describe("Podman pull", func() {
|
||||||
Expect(data[0].Os).To(Equal(runtime.GOOS))
|
Expect(data[0].Os).To(Equal(runtime.GOOS))
|
||||||
Expect(data[0].Architecture).To(Equal("arm64"))
|
Expect(data[0].Architecture).To(Equal("arm64"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman pull --arch", func() {
|
||||||
|
session := podmanTest.Podman([]string{"pull", "--arch=bogus", ALPINE})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(125))
|
||||||
|
expectedError := "no image found in manifest list for architecture bogus"
|
||||||
|
Expect(session.ErrorToString()).To(ContainSubstring(expectedError))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"pull", "--arch=arm64", "--os", "windows", ALPINE})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(125))
|
||||||
|
expectedError = "no image found in manifest list for architecture"
|
||||||
|
Expect(session.ErrorToString()).To(ContainSubstring(expectedError))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"pull", "-q", "--arch=arm64", ALPINE})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
setup := podmanTest.Podman([]string{"image", "inspect", session.OutputToString()})
|
||||||
|
setup.WaitWithDefaultTimeout()
|
||||||
|
Expect(setup.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
data := setup.InspectImageJSON() // returns []inspect.ImageData
|
||||||
|
Expect(len(data)).To(Equal(1))
|
||||||
|
Expect(data[0].Os).To(Equal(runtime.GOOS))
|
||||||
|
Expect(data[0].Architecture).To(Equal("arm64"))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue