pull/create: add --override-arch/--override-os flags

Add --override-arch and --override-os as hidden flags, in line with the
global flag names that skopeo uses, so that we can test behavior around
manifest lists without having to conditionalize more of it by arch.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
This commit is contained in:
Nalin Dahyabhai
2019-10-16 11:57:45 -04:00
parent 803357334c
commit b9313d355e
11 changed files with 58 additions and 2 deletions

4
API.md
View File

@ -1557,6 +1557,10 @@ oomKillDisable [?bool](#?bool)
oomScoreAdj [?int](#?int) oomScoreAdj [?int](#?int)
overrideArch [?string](#?string)
overrideOS [?string](#?string)
pid [?string](#?string) pid [?string](#?string)
pidsLimit [?int](#?int) pidsLimit [?int](#?int)

View File

@ -9,6 +9,7 @@ import (
"github.com/containers/buildah" "github.com/containers/buildah"
"github.com/containers/buildah/imagebuildah" "github.com/containers/buildah/imagebuildah"
buildahcli "github.com/containers/buildah/pkg/cli" buildahcli "github.com/containers/buildah/pkg/cli"
"github.com/containers/image/v5/types"
"github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/libpod" "github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/adapter" "github.com/containers/libpod/pkg/adapter"
@ -360,6 +361,10 @@ func buildCmd(c *cliconfig.BuildValues) error {
RuntimeArgs: runtimeFlags, RuntimeArgs: runtimeFlags,
SignaturePolicyPath: c.SignaturePolicy, SignaturePolicyPath: c.SignaturePolicy,
Squash: c.Squash, Squash: c.Squash,
SystemContext: &types.SystemContext{
OSChoice: c.OverrideOS,
ArchitectureChoice: c.OverrideArch,
},
Target: c.Target, Target: c.Target,
} }
return runtime.Build(getContext(), c, options, containerfiles) return runtime.Build(getContext(), c, options, containerfiles)

View File

@ -431,6 +431,8 @@ type PullValues struct {
Authfile string Authfile string
CertDir string CertDir string
Creds string Creds string
OverrideArch string
OverrideOS string
Quiet bool Quiet bool
SignaturePolicy string SignaturePolicy string
TlsVerify bool TlsVerify bool

View File

@ -370,6 +370,16 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
"oom-score-adj", 0, "oom-score-adj", 0,
"Tune the host's OOM preferences (-1000 to 1000)", "Tune the host's OOM preferences (-1000 to 1000)",
) )
createFlags.String(
"override-arch", "",
"use `ARCH` instead of the architecture of the machine for choosing images",
)
markFlagHidden(createFlags, "override-arch")
createFlags.String(
"override-os", "",
"use `OS` instead of the running OS for choosing images",
)
markFlagHidden(createFlags, "override-os")
createFlags.String( createFlags.String(
"pid", "", "pid", "",
"PID namespace to use", "PID namespace to use",

View File

@ -54,6 +54,10 @@ func init() {
flags.BoolVar(&pullCommand.AllTags, "all-tags", false, "All tagged images in the repository will be pulled") flags.BoolVar(&pullCommand.AllTags, "all-tags", false, "All tagged images in the repository will be pulled")
flags.StringVar(&pullCommand.Creds, "creds", "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry") flags.StringVar(&pullCommand.Creds, "creds", "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry")
flags.BoolVarP(&pullCommand.Quiet, "quiet", "q", false, "Suppress output information when pulling images") flags.BoolVarP(&pullCommand.Quiet, "quiet", "q", false, "Suppress output information when pulling images")
flags.StringVar(&pullCommand.OverrideArch, "override-arch", "", "use `ARCH` instead of the architecture of the machine for choosing images")
markFlagHidden(flags, "override-arch")
flags.StringVar(&pullCommand.OverrideOS, "override-os", "", "use `OS` instead of the running OS for choosing images")
markFlagHidden(flags, "override-os")
// Disabled flags for the remote client // Disabled flags for the remote client
if !remote { if !remote {
flags.StringVar(&pullCommand.Authfile, "authfile", shared.GetAuthFile(""), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override") flags.StringVar(&pullCommand.Authfile, "authfile", shared.GetAuthFile(""), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
@ -122,6 +126,8 @@ func pullCmd(c *cliconfig.PullValues) (retError error) {
dockerRegistryOptions := image.DockerRegistryOptions{ dockerRegistryOptions := image.DockerRegistryOptions{
DockerRegistryCreds: registryCreds, DockerRegistryCreds: registryCreds,
DockerCertPath: c.CertDir, DockerCertPath: c.CertDir,
OSChoice: c.OverrideOS,
ArchitectureChoice: c.OverrideArch,
} }
if c.IsSet("tls-verify") { if c.IsSet("tls-verify") {
dockerRegistryOptions.DockerInsecureSkipTLSVerify = types.NewOptionalBool(!c.TlsVerify) dockerRegistryOptions.DockerInsecureSkipTLSVerify = types.NewOptionalBool(!c.TlsVerify)

View File

@ -89,7 +89,12 @@ func CreateContainer(ctx context.Context, c *GenericCLIResults, runtime *libpod.
return nil, nil, err return nil, nil, err
} }
newImage, err := runtime.ImageRuntime().New(ctx, name, rtc.SignaturePolicyPath, GetAuthFile(c.String("authfile")), writer, nil, image.SigningOptions{}, nil, pullType) dockerRegistryOptions := image.DockerRegistryOptions{
OSChoice: c.String("override-os"),
ArchitectureChoice: c.String("override-arch"),
}
newImage, err := runtime.ImageRuntime().New(ctx, name, rtc.SignaturePolicyPath, GetAuthFile(c.String("authfile")), writer, &dockerRegistryOptions, image.SigningOptions{}, nil, pullType)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

View File

@ -428,6 +428,8 @@ func NewIntermediateLayer(c *cliconfig.PodmanCommand, remote bool) GenericCLIRes
m["no-hosts"] = newCRBool(c, "no-hosts") m["no-hosts"] = newCRBool(c, "no-hosts")
m["oom-kill-disable"] = newCRBool(c, "oom-kill-disable") m["oom-kill-disable"] = newCRBool(c, "oom-kill-disable")
m["oom-score-adj"] = newCRInt(c, "oom-score-adj") m["oom-score-adj"] = newCRInt(c, "oom-score-adj")
m["override-arch"] = newCRString(c, "override-arch")
m["override-os"] = newCRString(c, "override-os")
m["pid"] = newCRString(c, "pid") m["pid"] = newCRString(c, "pid")
m["pids-limit"] = newCRInt64(c, "pids-limit") m["pids-limit"] = newCRInt64(c, "pids-limit")
m["pod"] = newCRString(c, "pod") m["pod"] = newCRString(c, "pod")

View File

@ -131,6 +131,8 @@ func (g GenericCLIResults) MakeVarlink() iopodman.Create {
Network: StringToPtr(g.Find("network")), Network: StringToPtr(g.Find("network")),
OomKillDisable: BoolToPtr(g.Find("oom-kill-disable")), OomKillDisable: BoolToPtr(g.Find("oom-kill-disable")),
OomScoreAdj: AnyIntToInt64Ptr(g.Find("oom-score-adj")), OomScoreAdj: AnyIntToInt64Ptr(g.Find("oom-score-adj")),
OverrideOS: StringToPtr(g.Find("override-os")),
OverrideArch: StringToPtr(g.Find("override-arch")),
Pid: StringToPtr(g.Find("pid")), Pid: StringToPtr(g.Find("pid")),
PidsLimit: AnyIntToInt64Ptr(g.Find("pids-limit")), PidsLimit: AnyIntToInt64Ptr(g.Find("pids-limit")),
Pod: StringToPtr(g.Find("pod")), Pod: StringToPtr(g.Find("pod")),
@ -389,6 +391,8 @@ func VarlinkCreateToGeneric(opts iopodman.Create) GenericCLIResults {
m["no-hosts"] = boolFromVarlink(opts.NoHosts, "no-hosts", false) m["no-hosts"] = boolFromVarlink(opts.NoHosts, "no-hosts", false)
m["oom-kill-disable"] = boolFromVarlink(opts.OomKillDisable, "oon-kill-disable", false) m["oom-kill-disable"] = boolFromVarlink(opts.OomKillDisable, "oon-kill-disable", false)
m["oom-score-adj"] = intFromVarlink(opts.OomScoreAdj, "oom-score-adj", nil) m["oom-score-adj"] = intFromVarlink(opts.OomScoreAdj, "oom-score-adj", nil)
m["override-os"] = stringFromVarlink(opts.OverrideOS, "override-os", nil)
m["override-arch"] = stringFromVarlink(opts.OverrideArch, "override-arch", nil)
m["pid"] = stringFromVarlink(opts.Pid, "pid", nil) m["pid"] = stringFromVarlink(opts.Pid, "pid", nil)
m["pids-limit"] = int64FromVarlink(opts.PidsLimit, "pids-limit", nil) m["pids-limit"] = int64FromVarlink(opts.PidsLimit, "pids-limit", nil)
m["pod"] = stringFromVarlink(opts.Pod, "pod", nil) m["pod"] = stringFromVarlink(opts.Pod, "pod", nil)

View File

@ -342,6 +342,8 @@ type Create (
noHosts: ?bool, noHosts: ?bool,
oomKillDisable: ?bool, oomKillDisable: ?bool,
oomScoreAdj: ?int, oomScoreAdj: ?int,
overrideArch: ?string,
overrideOS: ?string,
pid: ?string, pid: ?string,
pidsLimit: ?int, pidsLimit: ?int,
pod: ?string, pod: ?string,

View File

@ -26,6 +26,10 @@ type DockerRegistryOptions struct {
// certificates and allows connecting to registries without encryption // certificates and allows connecting to registries without encryption
// - or forces it on even if registries.conf has the registry configured as insecure. // - or forces it on even if registries.conf has the registry configured as insecure.
DockerInsecureSkipTLSVerify types.OptionalBool DockerInsecureSkipTLSVerify types.OptionalBool
// If not "", overrides the use of platform.GOOS when choosing an image or verifying OS match.
OSChoice string
// If not "", overrides the use of platform.GOARCH when choosing an image or verifying architecture match.
ArchitectureChoice string
} }
// GetSystemContext constructs a new system context from a parent context. the values in the DockerRegistryOptions, and other parameters. // GetSystemContext constructs a new system context from a parent context. the values in the DockerRegistryOptions, and other parameters.
@ -35,12 +39,16 @@ func (o DockerRegistryOptions) GetSystemContext(parent *types.SystemContext, add
DockerCertPath: o.DockerCertPath, DockerCertPath: o.DockerCertPath,
DockerInsecureSkipTLSVerify: o.DockerInsecureSkipTLSVerify, DockerInsecureSkipTLSVerify: o.DockerInsecureSkipTLSVerify,
DockerArchiveAdditionalTags: additionalDockerArchiveTags, DockerArchiveAdditionalTags: additionalDockerArchiveTags,
OSChoice: o.OSChoice,
ArchitectureChoice: o.ArchitectureChoice,
} }
if parent != nil { if parent != nil {
sc.SignaturePolicyPath = parent.SignaturePolicyPath sc.SignaturePolicyPath = parent.SignaturePolicyPath
sc.AuthFilePath = parent.AuthFilePath sc.AuthFilePath = parent.AuthFilePath
sc.DirForceCompress = parent.DirForceCompress sc.DirForceCompress = parent.DirForceCompress
sc.DockerRegistryUserAgent = parent.DockerRegistryUserAgent sc.DockerRegistryUserAgent = parent.DockerRegistryUserAgent
sc.OSChoice = parent.OSChoice
sc.ArchitectureChoice = parent.ArchitectureChoice
} }
return sc return sc
} }

View File

@ -223,6 +223,10 @@ func (ir *Runtime) pullImageFromHeuristicSource(ctx context.Context, inputName s
var goal *pullGoal var goal *pullGoal
sc := GetSystemContext(signaturePolicyPath, authfile, false) sc := GetSystemContext(signaturePolicyPath, authfile, false)
if dockerOptions != nil {
sc.OSChoice = dockerOptions.OSChoice
sc.ArchitectureChoice = dockerOptions.ArchitectureChoice
}
sc.BlobInfoCacheDir = filepath.Join(ir.store.GraphRoot(), "cache") sc.BlobInfoCacheDir = filepath.Join(ir.store.GraphRoot(), "cache")
srcRef, err := alltransports.ParseImageName(inputName) srcRef, err := alltransports.ParseImageName(inputName)
if err != nil { if err != nil {
@ -246,6 +250,10 @@ func (ir *Runtime) pullImageFromReference(ctx context.Context, srcRef types.Imag
defer span.Finish() defer span.Finish()
sc := GetSystemContext(signaturePolicyPath, authfile, false) sc := GetSystemContext(signaturePolicyPath, authfile, false)
if dockerOptions != nil {
sc.OSChoice = dockerOptions.OSChoice
sc.ArchitectureChoice = dockerOptions.ArchitectureChoice
}
goal, err := ir.pullGoalFromImageReference(ctx, srcRef, transports.ImageName(srcRef), sc) goal, err := ir.pullGoalFromImageReference(ctx, srcRef, transports.ImageName(srcRef), sc)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "error determining pull goal for image %q", transports.ImageName(srcRef)) return nil, errors.Wrapf(err, "error determining pull goal for image %q", transports.ImageName(srcRef))