mirror of https://github.com/containers/podman.git
Merge pull request #8488 from rhatdan/platform
Add support for --platform
This commit is contained in:
commit
e3313fdd50
|
@ -513,6 +513,14 @@ func DefineCreateFlags(cmd *cobra.Command, cf *ContainerCLIOpts) {
|
||||||
)
|
)
|
||||||
_ = cmd.RegisterFlagCompletionFunc(pidsLimitFlagName, completion.AutocompleteNone)
|
_ = cmd.RegisterFlagCompletionFunc(pidsLimitFlagName, completion.AutocompleteNone)
|
||||||
|
|
||||||
|
platformFlagName := "platform"
|
||||||
|
createFlags.StringVar(
|
||||||
|
&cf.Platform,
|
||||||
|
platformFlagName, "",
|
||||||
|
"Specify the platform for selecting the image. (Conflicts with override-arch and override-os)",
|
||||||
|
)
|
||||||
|
_ = cmd.RegisterFlagCompletionFunc(platformFlagName, completion.AutocompleteNone)
|
||||||
|
|
||||||
podFlagName := "pod"
|
podFlagName := "pod"
|
||||||
createFlags.StringVar(
|
createFlags.StringVar(
|
||||||
&cf.Pod,
|
&cf.Pod,
|
||||||
|
|
|
@ -78,6 +78,7 @@ type ContainerCLIOpts struct {
|
||||||
OverrideVariant string
|
OverrideVariant string
|
||||||
PID string
|
PID string
|
||||||
PIDsLimit *int64
|
PIDsLimit *int64
|
||||||
|
Platform string
|
||||||
Pod string
|
Pod string
|
||||||
PodIDFile string
|
PodIDFile string
|
||||||
PreserveFDs uint
|
PreserveFDs uint
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"github.com/containers/podman/v2/pkg/specgen"
|
"github.com/containers/podman/v2/pkg/specgen"
|
||||||
"github.com/containers/podman/v2/pkg/util"
|
"github.com/containers/podman/v2/pkg/util"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -236,6 +237,21 @@ func pullImage(imageName string) (string, error) {
|
||||||
imageMissing = !br.Value
|
imageMissing = !br.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cliVals.Platform != "" {
|
||||||
|
if cliVals.OverrideArch != "" || cliVals.OverrideOS != "" {
|
||||||
|
return "", errors.Errorf("--platform option can not be specified with --overide-arch or --override-os")
|
||||||
|
}
|
||||||
|
split := strings.SplitN(cliVals.Platform, "/", 2)
|
||||||
|
cliVals.OverrideOS = split[0]
|
||||||
|
if len(split) > 1 {
|
||||||
|
cliVals.OverrideArch = split[1]
|
||||||
|
}
|
||||||
|
if pullPolicy != config.PullImageAlways {
|
||||||
|
logrus.Info("--platform causes the pull policy to be \"always\"")
|
||||||
|
pullPolicy = config.PullImageAlways
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if imageMissing || pullPolicy == config.PullImageAlways {
|
if imageMissing || pullPolicy == config.PullImageAlways {
|
||||||
if pullPolicy == config.PullImageNever {
|
if pullPolicy == config.PullImageNever {
|
||||||
return "", errors.Wrapf(define.ErrNoSuchImage, "unable to find a name and tag match for %s in repotags", imageName)
|
return "", errors.Wrapf(define.ErrNoSuchImage, "unable to find a name and tag match for %s in repotags", imageName)
|
||||||
|
|
|
@ -3,6 +3,7 @@ package images
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/common/pkg/auth"
|
"github.com/containers/common/pkg/auth"
|
||||||
"github.com/containers/common/pkg/completion"
|
"github.com/containers/common/pkg/completion"
|
||||||
|
@ -11,6 +12,7 @@ import (
|
||||||
"github.com/containers/podman/v2/cmd/podman/registry"
|
"github.com/containers/podman/v2/cmd/podman/registry"
|
||||||
"github.com/containers/podman/v2/pkg/domain/entities"
|
"github.com/containers/podman/v2/pkg/domain/entities"
|
||||||
"github.com/containers/podman/v2/pkg/util"
|
"github.com/containers/podman/v2/pkg/util"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -94,6 +96,10 @@ func pullFlags(cmd *cobra.Command) {
|
||||||
flags.StringVar(&pullOptions.OverrideVariant, overrideVariantFlagName, "", " use VARIANT instead of the running architecture variant for choosing images")
|
flags.StringVar(&pullOptions.OverrideVariant, overrideVariantFlagName, "", " use VARIANT instead of the running architecture variant for choosing images")
|
||||||
_ = cmd.RegisterFlagCompletionFunc(overrideVariantFlagName, completion.AutocompleteNone)
|
_ = cmd.RegisterFlagCompletionFunc(overrideVariantFlagName, completion.AutocompleteNone)
|
||||||
|
|
||||||
|
platformFlagName := "platform"
|
||||||
|
flags.String(platformFlagName, "", "Specify the platform for selecting the image. (Conflicts with override-arch and override-os)")
|
||||||
|
_ = cmd.RegisterFlagCompletionFunc(platformFlagName, completion.AutocompleteNone)
|
||||||
|
|
||||||
flags.Bool("disable-content-trust", false, "This is a Docker specific option and is a NOOP")
|
flags.Bool("disable-content-trust", false, "This is a Docker specific option and is a NOOP")
|
||||||
flags.BoolVarP(&pullOptions.Quiet, "quiet", "q", false, "Suppress output information when pulling images")
|
flags.BoolVarP(&pullOptions.Quiet, "quiet", "q", false, "Suppress output information when pulling images")
|
||||||
flags.StringVar(&pullOptions.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)")
|
flags.StringVar(&pullOptions.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)")
|
||||||
|
@ -127,6 +133,20 @@ func imagePull(cmd *cobra.Command, args []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
platform, err := cmd.Flags().GetString("platform")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if platform != "" {
|
||||||
|
if pullOptions.OverrideArch != "" || pullOptions.OverrideOS != "" {
|
||||||
|
return errors.Errorf("--platform option can not be specified with --overide-arch or --override-os")
|
||||||
|
}
|
||||||
|
split := strings.SplitN(platform, "/", 2)
|
||||||
|
pullOptions.OverrideOS = split[0]
|
||||||
|
if len(split) > 1 {
|
||||||
|
pullOptions.OverrideArch = split[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if pullOptions.CredentialsCLI != "" {
|
if pullOptions.CredentialsCLI != "" {
|
||||||
creds, err := util.ParseRegistryCreds(pullOptions.CredentialsCLI)
|
creds, err := util.ParseRegistryCreds(pullOptions.CredentialsCLI)
|
||||||
|
|
|
@ -689,6 +689,11 @@ Default is to create a private PID namespace for the container
|
||||||
|
|
||||||
Tune the container's pids limit. Set `0` to have unlimited pids for the container. (default "4096" on systems that support PIDS cgroups).
|
Tune the container's pids limit. Set `0` to have unlimited pids for the container. (default "4096" on systems that support PIDS cgroups).
|
||||||
|
|
||||||
|
#### **--platform**=*OS/ARCH*
|
||||||
|
|
||||||
|
Specify the platform for selecting the image. (Conflicts with override-arch and override-os)
|
||||||
|
The `--platform` option can be used to override the current architecture and operating system.
|
||||||
|
|
||||||
#### **--pod**=*name*
|
#### **--pod**=*name*
|
||||||
|
|
||||||
Run container in an existing pod. If you want Podman to make the pod for you, preference the pod name with `new:`.
|
Run container in an existing pod. If you want Podman to make the pod for you, preference the pod name with `new:`.
|
||||||
|
|
|
@ -106,6 +106,11 @@ Override the OS, defaults to hosts, of the image to be pulled. For example, `win
|
||||||
|
|
||||||
Use _VARIANT_ instead of the default architecture variant of the container image. Some images can use multiple variants of the arm architectures, such as arm/v5 and arm/v7.
|
Use _VARIANT_ instead of the default architecture variant of the container image. Some images can use multiple variants of the arm architectures, such as arm/v5 and arm/v7.
|
||||||
|
|
||||||
|
#### **--platform**=*OS/ARCH*
|
||||||
|
|
||||||
|
Specify the platform for selecting the image. (Conflicts with override-arch and override-os)
|
||||||
|
The `--platform` option can be used to override the current architecture and operating system.
|
||||||
|
|
||||||
#### **--quiet**, **-q**
|
#### **--quiet**, **-q**
|
||||||
|
|
||||||
Suppress output information when pulling images
|
Suppress output information when pulling images
|
||||||
|
|
|
@ -717,6 +717,11 @@ The efault is to create a private PID namespace for the container.
|
||||||
|
|
||||||
Tune the container's pids limit. Set to **0** to have unlimited pids for the container. The default is **4096** on systems that support "pids" cgroup controller.
|
Tune the container's pids limit. Set to **0** to have unlimited pids for the container. The default is **4096** on systems that support "pids" cgroup controller.
|
||||||
|
|
||||||
|
#### **--platform**=*OS/ARCH*
|
||||||
|
|
||||||
|
Specify the platform for selecting the image. (Conflicts with override-arch and override-os)
|
||||||
|
The `--platform` option can be used to override the current architecture and operating system.
|
||||||
|
|
||||||
#### **--pod**=*name*
|
#### **--pod**=*name*
|
||||||
|
|
||||||
Run container in an existing pod. If you want Podman to make the pod for you, prefix the pod name with **new:**.
|
Run container in an existing pod. If you want Podman to make the pod for you, prefix the pod name with **new:**.
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
. "github.com/containers/podman/v2/test/utils"
|
. "github.com/containers/podman/v2/test/utils"
|
||||||
|
@ -644,4 +645,35 @@ var _ = Describe("Podman create", func() {
|
||||||
Expect(session.ErrorToString()).To(ContainSubstring("unknown flag"))
|
Expect(session.ErrorToString()).To(ContainSubstring("unknown flag"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman create --platform", func() {
|
||||||
|
session := podmanTest.Podman([]string{"create", "--platform=linux/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{"create", "--platform=linux/arm64", "--override-os", "windows", ALPINE})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(125))
|
||||||
|
expectedError = "--platform option can not be specified with --overide-arch or --override-os"
|
||||||
|
Expect(session.ErrorToString()).To(ContainSubstring(expectedError))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"create", "-q", "--platform=linux/arm64", ALPINE})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
setup := podmanTest.Podman([]string{"container", "inspect", session.OutputToString()})
|
||||||
|
setup.WaitWithDefaultTimeout()
|
||||||
|
Expect(setup.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
data := setup.InspectContainerToJSON()
|
||||||
|
setup = podmanTest.Podman([]string{"image", "inspect", data[0].Image})
|
||||||
|
setup.WaitWithDefaultTimeout()
|
||||||
|
Expect(setup.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
idata := setup.InspectImageJSON() // returns []inspect.ImageData
|
||||||
|
Expect(len(idata)).To(Equal(1))
|
||||||
|
Expect(idata[0].Os).To(Equal(runtime.GOOS))
|
||||||
|
Expect(idata[0].Architecture).To(Equal("arm64"))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
. "github.com/containers/podman/v2/test/utils"
|
. "github.com/containers/podman/v2/test/utils"
|
||||||
|
@ -494,4 +495,31 @@ var _ = Describe("Podman pull", func() {
|
||||||
Expect(data[0].ID).To(Equal(image1))
|
Expect(data[0].ID).To(Equal(image1))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman pull --platform", func() {
|
||||||
|
session := podmanTest.Podman([]string{"pull", "--platform=linux/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", "--platform=linux/arm64", "--override-os", "windows", ALPINE})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(125))
|
||||||
|
expectedError = "--platform option can not be specified with --overide-arch or --override-os"
|
||||||
|
Expect(session.ErrorToString()).To(ContainSubstring(expectedError))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"pull", "-q", "--platform=linux/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