Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use --arch and --os options to select architecture and os #2868

Merged
merged 2 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions cmd/buildah/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"github.com/containers/buildah/manifests"
"github.com/containers/buildah/pkg/cli"
"github.com/containers/buildah/pkg/parse"
"github.com/containers/buildah/util"
"github.com/containers/common/pkg/auth"
Expand All @@ -24,11 +25,10 @@ import (
)

type manifestCreateOpts = struct {
osOverride, archOverride string
all bool
os, arch string
all bool
}
type manifestAddOpts = struct {
osOverride, archOverride string
authfile, certDir, creds, os, arch, variant, osVersion string
features, osFeatures, annotations []string
tlsVerify, all bool
Expand Down Expand Up @@ -90,14 +90,15 @@ func init() {
manifestCreateCommand.SetUsageTemplate(UsageTemplate())
flags := manifestCreateCommand.Flags()
flags.BoolVar(&manifestCreateOpts.all, "all", false, "add all of the lists' images if the images to add are lists")
flags.StringVar(&manifestCreateOpts.osOverride, "override-os", "", "if any of the specified images is a list, choose the one for `os`")
if err := flags.MarkHidden("override-os"); err != nil {
panic(fmt.Sprintf("error marking override-os as hidden: %v", err))
flags.StringVar(&manifestCreateOpts.os, "os", "", "if any of the specified images is a list, choose the one for `os`")
if err := flags.MarkHidden("os"); err != nil {
panic(fmt.Sprintf("error marking --os as hidden: %v", err))
}
flags.StringVar(&manifestCreateOpts.archOverride, "override-arch", "", "if any of the specified images is a list, choose the one for `arch`")
if err := flags.MarkHidden("override-arch"); err != nil {
panic(fmt.Sprintf("error marking override-arch as hidden: %v", err))
flags.StringVar(&manifestCreateOpts.arch, "arch", "", "if any of the specified images is a list, choose the one for `arch`")
if err := flags.MarkHidden("arch"); err != nil {
panic(fmt.Sprintf("error marking --arch as hidden: %v", err))
}
flags.SetNormalizeFunc(cli.AliasFlags)
manifestCommand.AddCommand(manifestCreateCommand)

manifestAddCommand := &cobra.Command{
Expand All @@ -113,14 +114,6 @@ func init() {
}
manifestAddCommand.SetUsageTemplate(UsageTemplate())
flags = manifestAddCommand.Flags()
flags.StringVar(&manifestAddOpts.osOverride, "override-os", "", "if any of the specified images is a list, choose the one for `os`")
if err := flags.MarkHidden("override-os"); err != nil {
panic(fmt.Sprintf("error marking override-os as hidden: %v", err))
}
flags.StringVar(&manifestAddOpts.archOverride, "override-arch", "", "if any of the specified images is a list, choose the one for `arch`")
if err := flags.MarkHidden("override-arch"); err != nil {
panic(fmt.Sprintf("error marking override-arch as hidden: %v", err))
}
flags.StringVar(&manifestAddOpts.authfile, "authfile", auth.GetDefaultAuthFile(), "path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
flags.StringVar(&manifestAddOpts.certDir, "cert-dir", "", "use certificates at the specified path to access the registry")
flags.StringVar(&manifestAddOpts.creds, "creds", "", "use `[username[:password]]` for accessing the registry")
Expand All @@ -133,6 +126,7 @@ func init() {
flags.StringSliceVar(&manifestAddOpts.annotations, "annotation", nil, "set an `annotation` for the specified image")
flags.BoolVar(&manifestAddOpts.tlsVerify, "tls-verify", true, "require HTTPS and verify certificates when accessing the registry. TLS verification cannot be used when talking to an insecure registry.")
flags.BoolVar(&manifestAddOpts.all, "all", false, "add all of the list's images if the image is a list")
flags.SetNormalizeFunc(cli.AliasFlags)
manifestCommand.AddCommand(manifestAddCommand)

manifestRemoveCommand := &cobra.Command{
Expand Down
13 changes: 3 additions & 10 deletions cmd/buildah/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ type pullOptions struct {
blobCache string
certDir string
creds string
overrideArch string
overrideOS string
signaturePolicy string
quiet bool
removeSignatures bool
Expand Down Expand Up @@ -67,14 +65,9 @@ func init() {
panic(fmt.Sprintf("error marking signature-policy as hidden: %v", err))
}
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "don't output progress information when pulling images")
flags.StringVar(&opts.overrideOS, "override-os", runtime.GOOS, "prefer `OS` instead of the running OS for choosing images")
if err := flags.MarkHidden("override-os"); err != nil {
panic(fmt.Sprintf("error marking override-os as hidden: %v", err))
}
flags.StringVar(&opts.overrideArch, "override-arch", runtime.GOARCH, "prefer `ARCH` instead of the architecture of the machine for choosing images")
if err := flags.MarkHidden("override-arch"); err != nil {
panic(fmt.Sprintf("error marking override-arch as hidden: %v", err))
}
flags.String("os", runtime.GOOS, "prefer `OS` instead of the running OS for choosing images")
flags.String("arch", runtime.GOARCH, "prefer `ARCH` instead of the architecture of the machine for choosing images")
flags.String("variant", "", "override the `variant` of the specified image")
flags.BoolVar(&opts.tlsVerify, "tls-verify", true, "require HTTPS and verify certificates when accessing the registry. TLS verification cannot be used when talking to an insecure registry.")
if err := flags.MarkHidden("blob-cache"); err != nil {
panic(fmt.Sprintf("error marking blob-cache as hidden: %v", err))
Expand Down
10 changes: 8 additions & 2 deletions docs/buildah-bud.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Note: this information is not present in Docker image formats, so it is discarde

**--arch**="ARCH"

Set the ARCH of the image to the provided value instead of using the architecture of the host.
Set the ARCH of the image to be pulled to the provided value instead of using the architecture of the host. (Examples: aarch64, arm, i686, ppc64le, s390x, x86_64)

**--authfile** *path*

Expand Down Expand Up @@ -393,7 +393,7 @@ Do not use existing cached images for the container build. Build from the start

**--os**="OS"

Set the OS of the image to the provided value instead of using the current operating system of the host.
Set the OS of the image to be pulled instead of using the current operating system of the host.

**--pid** *how*

Expand Down Expand Up @@ -588,6 +588,10 @@ that the UTS namespace in which `buildah` itself is being run should be reused,
or it can be the path to a UTS namespace which is already in use by another
process.

**--variant**=""

Set the architecture variant of the image to be pulled.

**--volume**, **-v**[=*[HOST-DIR:CONTAINER-DIR[:OPTIONS]]*]

Create a bind mount. If you specify, ` -v /HOST-DIR:/CONTAINER-DIR`, Buildah
Expand Down Expand Up @@ -727,6 +731,8 @@ buildah bud --memory 40m --cpu-period 10000 --cpu-quota 50000 --ulimit nofile=10

buildah bud --security-opt label=level:s0:c100,c200 --cgroup-parent /path/to/cgroup/parent -t imageName .

buildah bud --arch=arm --variant v7 -t imageName .

buildah bud --volume /home/test:/myvol:ro,Z -t imageName .

buildah bud -v /home/test:/myvol:z,U -t imageName .
Expand Down
14 changes: 14 additions & 0 deletions docs/buildah-from.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ Add a custom host-to-IP mapping (host:ip)

Add a line to /etc/hosts. The format is hostname:ip. The **--add-host** option can be set multiple times.

**--arch**="ARCH"

Set the ARCH of the image to be pulled to the provided value instead of using the architecture of the host. (Examples: aarch64, arm, i686, ppc64le, s390x, x86_64)

**--authfile** *path*

Path of the authentication file. Default is ${XDG\_RUNTIME\_DIR}/containers/auth.json, which is set using `buildah login`.
Expand Down Expand Up @@ -271,6 +275,10 @@ that the network namespace in which `Buildah` itself is being run should be
reused, or it can be the path to a network namespace which is already in use by
another process.

**--os**="OS"

Set the OS of the image to be pulled instead of using the current operating system of the host.

**--pid** *how*

Sets the configuration for PID namespaces when the container is subsequently
Expand Down Expand Up @@ -442,6 +450,10 @@ that the UTS namespace in which `Buildah` itself is being run should be reused,
or it can be the path to a UTS namespace which is already in use by another
process.

**--variant**=""

Set the architecture variant of the image to be pulled.

**--volume**, **-v**[=*[HOST-DIR:CONTAINER-DIR[:OPTIONS]]*]

Create a bind mount. If you specify, ` -v /HOST-DIR:/CONTAINER-DIR`, Buildah
Expand Down Expand Up @@ -566,6 +578,8 @@ buildah from -v /home/test:/myvol:z,U myregistry/myrepository/imagename:imagetag

buildah from -v /var/lib/yum:/var/lib/yum:O myregistry/myrepository/imagename:imagetag

buildah from --arch=arm --variant v7 myregistry/myrepository/imagename:imagetag

## ENVIRONMENT

**BUILD\_REGISTRY\_SOURCES**
Expand Down
15 changes: 15 additions & 0 deletions docs/buildah-pull.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ The image ID of the image that was pulled. On error 1 is returned.

All tagged images in the repository will be pulled.

**--arch**="ARCH"

Set the ARCH of the image to be pulled to the provided value instead of using the architecture of the host. (Examples: aarch64, arm, i686, ppc64le, s390x, x86_64)

**--authfile** *path*

Path of the authentication file. Default is ${XDG\_RUNTIME\_DIR}/containers/auth.json, which is set using `buildah login`.
Expand All @@ -70,6 +74,10 @@ The [key[:passphrase]] to be used for decryption of images. Key can point to key

If an image needs to be pulled from the registry, suppress progress output.

**--os**="OS"

Set the OS of the image to be pulled instead of using the current operating system of the host.

**--policy**=**always**|**missing**|**never**

Pull image policy. The default is **missing**.
Expand All @@ -86,6 +94,9 @@ Don't copy signatures when pulling images.

Require HTTPS and verify certificates when talking to container registries (defaults to true). TLS verification cannot be used when talking to an insecure registry.

**--variant**=""

Set the architecture variant of the image to be pulled.

## EXAMPLE

Expand All @@ -107,6 +118,10 @@ buildah pull --creds=myusername:mypassword --cert-dir ~/auth myregistry/myreposi

buildah pull --authfile=/tmp/auths/myauths.json myregistry/myrepository/imagename:imagetag

buildah pull --arch=aarch64 myregistry/myrepository/imagename:imagetag

buildah pull --arch=arm --variant=v7 myregistry/myrepository/imagename:imagetag

## ENVIRONMENT

**BUILD\_REGISTRY\_SOURCES**
Expand Down
31 changes: 15 additions & 16 deletions pkg/cli/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type NameSpaceResults struct {
// BudResults represents the results for Bud flags
type BudResults struct {
Annotation []string
Arch string
Authfile string
BuildArg []string
CacheFrom string
Expand All @@ -70,8 +69,6 @@ type BudResults struct {
Loglevel int
NoCache bool
Timestamp int64
OS string
Platform string
Pull bool
PullAlways bool
PullNever bool
Expand Down Expand Up @@ -112,8 +109,6 @@ type FromAndBudResults struct {
Isolation string
Memory string
MemorySwap string
OverrideArch string
OverrideOS string
SecurityOpt []string
ShmSize string
Ulimit []string
Expand Down Expand Up @@ -179,7 +174,7 @@ func GetLayerFlags(flags *LayerResults) pflag.FlagSet {
// GetBudFlags returns common bud flags
func GetBudFlags(flags *BudResults) pflag.FlagSet {
fs := pflag.FlagSet{}
fs.StringVar(&flags.Arch, "arch", runtime.GOARCH, "set the ARCH of the image to the provided value instead of the architecture of the host")
fs.String("arch", runtime.GOARCH, "set the ARCH of the image to the provided value instead of the architecture of the host")
fs.StringArrayVar(&flags.Annotation, "annotation", []string{}, "Set metadata for an image (default [])")
fs.StringVar(&flags.Authfile, "authfile", auth.GetDefaultAuthFile(), "path of the authentication file.")
fs.StringArrayVar(&flags.BuildArg, "build-arg", []string{}, "`argument=value` to supply to the builder")
Expand All @@ -203,8 +198,8 @@ func GetBudFlags(flags *BudResults) pflag.FlagSet {
panic(fmt.Sprintf("error marking the log-rusage flag as hidden: %v", err))
}
fs.BoolVar(&flags.NoCache, "no-cache", false, "Do not use existing cached images for the container build. Build from the start with a new set of cached layers.")
fs.StringVar(&flags.OS, "os", runtime.GOOS, "set the OS to the provided value instead of the current operating system of the host")
fs.StringVar(&flags.Platform, "platform", parse.DefaultPlatform(), "set the OS/ARCH to the provided value instead of the current operating system and architecture of the host (for example `linux/arm`)")
fs.String("os", runtime.GOOS, "set the OS to the provided value instead of the current operating system of the host")
fs.String("platform", parse.DefaultPlatform(), "set the OS/ARCH to the provided value instead of the current operating system and architecture of the host (for example `linux/arm`)")
fs.BoolVar(&flags.Pull, "pull", true, "pull the image from the registry if newer or not present in store, if false, only pull the image if not present")
fs.BoolVar(&flags.PullAlways, "pull-always", false, "pull the image even if the named image is present in store")
fs.BoolVar(&flags.PullNever, "pull-never", false, "do not pull the image, use the image present in store if available")
Expand All @@ -223,6 +218,7 @@ func GetBudFlags(flags *BudResults) pflag.FlagSet {
fs.StringVar(&flags.Target, "target", "", "set the target build stage to build")
fs.Int64Var(&flags.Timestamp, "timestamp", 0, "set created timestamp to the specified epoch seconds to allow for deterministic builds, defaults to current time")
fs.BoolVar(&flags.TLSVerify, "tls-verify", true, "require HTTPS and verify certificates when accessing the registry")
fs.String("variant", "", "override the `variant` of the specified image")
return fs
}

Expand Down Expand Up @@ -253,6 +249,7 @@ func GetBudFlagsCompletions() commonComp.FlagCompletions {
flagCompletion["tag"] = commonComp.AutocompleteNone
flagCompletion["target"] = commonComp.AutocompleteNone
flagCompletion["timestamp"] = commonComp.AutocompleteNone
flagCompletion["variant"] = commonComp.AutocompleteNone
return flagCompletion
}

Expand Down Expand Up @@ -286,14 +283,9 @@ func GetFromAndBudFlags(flags *FromAndBudResults, usernsResults *UserNSResults,
fs.StringVar(&flags.Isolation, "isolation", DefaultIsolation(), "`type` of process isolation to use. Use BUILDAH_ISOLATION environment variable to override.")
fs.StringVarP(&flags.Memory, "memory", "m", "", "memory limit (format: <number>[<unit>], where unit = b, k, m or g)")
fs.StringVar(&flags.MemorySwap, "memory-swap", "", "swap limit equal to memory plus swap: '-1' to enable unlimited swap")
fs.StringVar(&flags.OverrideOS, "override-os", runtime.GOOS, "prefer `OS` instead of the running OS when pulling images")
if err := fs.MarkHidden("override-os"); err != nil {
panic(fmt.Sprintf("error marking override-os as hidden: %v", err))
}
fs.StringVar(&flags.OverrideArch, "override-arch", runtime.GOARCH, "prefer `ARCH` instead of the architecture of the machine when pulling images")
if err := fs.MarkHidden("override-arch"); err != nil {
panic(fmt.Sprintf("error marking override-arch as hidden: %v", err))
}
fs.String("arch", runtime.GOARCH, "set the ARCH of the image to the provided value instead of the architecture of the host")
fs.String("os", runtime.GOOS, "prefer `OS` instead of the running OS when pulling images")
fs.String("variant", "", "override the `variant` of the specified image")
fs.StringArrayVar(&flags.SecurityOpt, "security-opt", []string{}, "security options (default [])")
fs.StringVar(&flags.ShmSize, "shm-size", defaultContainerConfig.Containers.ShmSize, "size of '/dev/shm'. The format is `<number><unit>`.")
fs.StringSliceVar(&flags.Ulimit, "ulimit", defaultContainerConfig.Containers.DefaultUlimits, "ulimit options")
Expand All @@ -311,6 +303,7 @@ func GetFromAndBudFlags(flags *FromAndBudResults, usernsResults *UserNSResults,
// GetFromAndBudFlagsCompletions returns the FlagCompletions for the from and bud flags
func GetFromAndBudFlagsCompletions() commonComp.FlagCompletions {
flagCompletion := commonComp.FlagCompletions{}
flagCompletion["arch"] = commonComp.AutocompleteNone
flagCompletion["add-host"] = commonComp.AutocompleteNone
flagCompletion["blob-cache"] = commonComp.AutocompleteNone
flagCompletion["cap-add"] = commonComp.AutocompleteCapabilities
Expand All @@ -329,10 +322,12 @@ func GetFromAndBudFlagsCompletions() commonComp.FlagCompletions {
flagCompletion["isolation"] = commonComp.AutocompleteNone
flagCompletion["memory"] = commonComp.AutocompleteNone
flagCompletion["memory-swap"] = commonComp.AutocompleteNone
flagCompletion["os"] = commonComp.AutocompleteNone
flagCompletion["security-opt"] = commonComp.AutocompleteNone
flagCompletion["shm-size"] = commonComp.AutocompleteNone
flagCompletion["ulimit"] = commonComp.AutocompleteNone
flagCompletion["volume"] = commonComp.AutocompleteDefault
flagCompletion["variant"] = commonComp.AutocompleteNone

// Add in the usernamespace and namespace flag completions
userNsComp := GetUserNSFlagsCompletions()
Expand Down Expand Up @@ -401,6 +396,10 @@ func AliasFlags(f *pflag.FlagSet, name string) pflag.NormalizedName {
switch name {
case "net":
name = "network"
case "override-arch":
name = "arch"
case "override-os":
name = "os"
}
return pflag.NormalizedName(name)
}
Loading