Merge pull request #18411 from flouthoc/bindings-fix-invalid-platform
bindings, build: don't pass invalid platform in case of none
This commit is contained in:
		
						commit
						04c45cebcd
					
				
							
								
								
									
										4
									
								
								go.mod
								
								
								
								
							
							
						
						
									
										4
									
								
								go.mod
								
								
								
								
							| 
						 | 
					@ -12,7 +12,7 @@ require (
 | 
				
			||||||
	github.com/container-orchestrated-devices/container-device-interface v0.5.4
 | 
						github.com/container-orchestrated-devices/container-device-interface v0.5.4
 | 
				
			||||||
	github.com/containernetworking/cni v1.1.2
 | 
						github.com/containernetworking/cni v1.1.2
 | 
				
			||||||
	github.com/containernetworking/plugins v1.2.0
 | 
						github.com/containernetworking/plugins v1.2.0
 | 
				
			||||||
	github.com/containers/buildah v1.30.0
 | 
						github.com/containers/buildah v1.30.1-0.20230501124043-3908816d5310
 | 
				
			||||||
	github.com/containers/common v0.53.1-0.20230502134647-9cd0cc23c80f
 | 
						github.com/containers/common v0.53.1-0.20230502134647-9cd0cc23c80f
 | 
				
			||||||
	github.com/containers/conmon v2.0.20+incompatible
 | 
						github.com/containers/conmon v2.0.20+incompatible
 | 
				
			||||||
	github.com/containers/image/v5 v5.25.0
 | 
						github.com/containers/image/v5 v5.25.0
 | 
				
			||||||
| 
						 | 
					@ -46,7 +46,7 @@ require (
 | 
				
			||||||
	github.com/onsi/gomega v1.27.6
 | 
						github.com/onsi/gomega v1.27.6
 | 
				
			||||||
	github.com/opencontainers/go-digest v1.0.0
 | 
						github.com/opencontainers/go-digest v1.0.0
 | 
				
			||||||
	github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b
 | 
						github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b
 | 
				
			||||||
	github.com/opencontainers/runc v1.1.5
 | 
						github.com/opencontainers/runc v1.1.7
 | 
				
			||||||
	github.com/opencontainers/runtime-spec v1.1.0-rc.2
 | 
						github.com/opencontainers/runtime-spec v1.1.0-rc.2
 | 
				
			||||||
	github.com/opencontainers/runtime-tools v0.9.1-0.20230317050512-e931285f4b69
 | 
						github.com/opencontainers/runtime-tools v0.9.1-0.20230317050512-e931285f4b69
 | 
				
			||||||
	github.com/opencontainers/selinux v1.11.0
 | 
						github.com/opencontainers/selinux v1.11.0
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										4
									
								
								go.sum
								
								
								
								
							
							
						
						
									
										4
									
								
								go.sum
								
								
								
								
							| 
						 | 
					@ -237,8 +237,8 @@ github.com/containernetworking/plugins v0.8.6/go.mod h1:qnw5mN19D8fIwkqW7oHHYDHV
 | 
				
			||||||
github.com/containernetworking/plugins v0.9.1/go.mod h1:xP/idU2ldlzN6m4p5LmGiwRDjeJr6FLK6vuiUwoH7P8=
 | 
					github.com/containernetworking/plugins v0.9.1/go.mod h1:xP/idU2ldlzN6m4p5LmGiwRDjeJr6FLK6vuiUwoH7P8=
 | 
				
			||||||
github.com/containernetworking/plugins v1.2.0 h1:SWgg3dQG1yzUo4d9iD8cwSVh1VqI+bP7mkPDoSfP9VU=
 | 
					github.com/containernetworking/plugins v1.2.0 h1:SWgg3dQG1yzUo4d9iD8cwSVh1VqI+bP7mkPDoSfP9VU=
 | 
				
			||||||
github.com/containernetworking/plugins v1.2.0/go.mod h1:/VjX4uHecW5vVimFa1wkG4s+r/s9qIfPdqlLF4TW8c4=
 | 
					github.com/containernetworking/plugins v1.2.0/go.mod h1:/VjX4uHecW5vVimFa1wkG4s+r/s9qIfPdqlLF4TW8c4=
 | 
				
			||||||
github.com/containers/buildah v1.30.0 h1:mdp2COGKFFEZNEGP8VZ5ITuUFVNPFoH+iK2sSesNfTA=
 | 
					github.com/containers/buildah v1.30.1-0.20230501124043-3908816d5310 h1:xYQch7NrCYPrNcrDUHPc1dE2nwg+2xHiG5l59T+m5Q4=
 | 
				
			||||||
github.com/containers/buildah v1.30.0/go.mod h1:lyMLZIevpAa6zSzjRl7z4lFJMCMQLFjfo56YIefaB/U=
 | 
					github.com/containers/buildah v1.30.1-0.20230501124043-3908816d5310/go.mod h1:6A/BK0YJLXL8+AqlbceKJrhUT+NtEgsvAc51F7TAllc=
 | 
				
			||||||
github.com/containers/common v0.53.1-0.20230502134647-9cd0cc23c80f h1:NGr0tr+qnavYQ3m+ajnrCLCp7y/YlGj14OXsYD5RhqY=
 | 
					github.com/containers/common v0.53.1-0.20230502134647-9cd0cc23c80f h1:NGr0tr+qnavYQ3m+ajnrCLCp7y/YlGj14OXsYD5RhqY=
 | 
				
			||||||
github.com/containers/common v0.53.1-0.20230502134647-9cd0cc23c80f/go.mod h1:uG5iTo9KbPxcyj3nsq0OPbBRTrSsrXKIMNRw4D6rt/w=
 | 
					github.com/containers/common v0.53.1-0.20230502134647-9cd0cc23c80f/go.mod h1:uG5iTo9KbPxcyj3nsq0OPbBRTrSsrXKIMNRw4D6rt/w=
 | 
				
			||||||
github.com/containers/conmon v2.0.20+incompatible h1:YbCVSFSCqFjjVwHTPINGdMX1F6JXHGTUje2ZYobNrkg=
 | 
					github.com/containers/conmon v2.0.20+incompatible h1:YbCVSFSCqFjjVwHTPINGdMX1F6JXHGTUje2ZYobNrkg=
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -298,6 +298,12 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO
 | 
				
			||||||
	if len(options.Platforms) > 0 {
 | 
						if len(options.Platforms) > 0 {
 | 
				
			||||||
		params.Del("platform")
 | 
							params.Del("platform")
 | 
				
			||||||
		for _, platformSpec := range options.Platforms {
 | 
							for _, platformSpec := range options.Platforms {
 | 
				
			||||||
 | 
								// podman-cli will send empty struct, in such
 | 
				
			||||||
 | 
								// case don't add platform to param and let the
 | 
				
			||||||
 | 
								// build backend decide the default platform.
 | 
				
			||||||
 | 
								if platformSpec.OS == "" && platformSpec.Arch == "" && platformSpec.Variant == "" {
 | 
				
			||||||
 | 
									continue
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			platform = platformSpec.OS + "/" + platformSpec.Arch
 | 
								platform = platformSpec.OS + "/" + platformSpec.Arch
 | 
				
			||||||
			if platformSpec.Variant != "" {
 | 
								if platformSpec.Variant != "" {
 | 
				
			||||||
				platform += "/" + platformSpec.Variant
 | 
									platform += "/" + platformSpec.Variant
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -192,7 +192,7 @@ conformance_task:
 | 
				
			||||||
    gce_instance:
 | 
					    gce_instance:
 | 
				
			||||||
        image_name: "${DEBIAN_CACHE_IMAGE_NAME}"
 | 
					        image_name: "${DEBIAN_CACHE_IMAGE_NAME}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    timeout_in: 25m
 | 
					    timeout_in: 65m
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    matrix:
 | 
					    matrix:
 | 
				
			||||||
        - env:
 | 
					        - env:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -167,7 +167,7 @@ install.runc:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.PHONY: test-conformance
 | 
					.PHONY: test-conformance
 | 
				
			||||||
test-conformance:
 | 
					test-conformance:
 | 
				
			||||||
	$(GO_TEST) -v -tags "$(STORAGETAGS) $(SECURITYTAGS)" -cover -timeout 20m ./tests/conformance
 | 
						$(GO_TEST) -v -tags "$(STORAGETAGS) $(SECURITYTAGS)" -cover -timeout 60m ./tests/conformance
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.PHONY: test-integration
 | 
					.PHONY: test-integration
 | 
				
			||||||
test-integration: install.tools
 | 
					test-integration: install.tools
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,7 +29,7 @@ const (
 | 
				
			||||||
	// identify working containers.
 | 
						// identify working containers.
 | 
				
			||||||
	Package = "buildah"
 | 
						Package = "buildah"
 | 
				
			||||||
	// Version for the Package. Also used by .packit.sh for Packit builds.
 | 
						// Version for the Package. Also used by .packit.sh for Packit builds.
 | 
				
			||||||
	Version = "1.30.0"
 | 
						Version = "1.31.0-dev"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// DefaultRuntime if containers.conf fails.
 | 
						// DefaultRuntime if containers.conf fails.
 | 
				
			||||||
	DefaultRuntime = "runc"
 | 
						DefaultRuntime = "runc"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -55,6 +55,7 @@ func GetBindMount(ctx *types.SystemContext, args []string, contextDir string, st
 | 
				
			||||||
		Type: define.TypeBind,
 | 
							Type: define.TypeBind,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						setRelabel := false
 | 
				
			||||||
	mountReadability := false
 | 
						mountReadability := false
 | 
				
			||||||
	setDest := false
 | 
						setDest := false
 | 
				
			||||||
	bindNonRecursive := false
 | 
						bindNonRecursive := false
 | 
				
			||||||
| 
						 | 
					@ -111,6 +112,22 @@ func GetBindMount(ctx *types.SystemContext, args []string, contextDir string, st
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			newMount.Destination = targetPath
 | 
								newMount.Destination = targetPath
 | 
				
			||||||
			setDest = true
 | 
								setDest = true
 | 
				
			||||||
 | 
							case "relabel":
 | 
				
			||||||
 | 
								if setRelabel {
 | 
				
			||||||
 | 
									return newMount, "", fmt.Errorf("cannot pass 'relabel' option more than once: %w", errBadOptionArg)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								setRelabel = true
 | 
				
			||||||
 | 
								if len(kv) != 2 {
 | 
				
			||||||
 | 
									return newMount, "", fmt.Errorf("%s mount option must be 'private' or 'shared': %w", kv[0], errBadMntOption)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								switch kv[1] {
 | 
				
			||||||
 | 
								case "private":
 | 
				
			||||||
 | 
									newMount.Options = append(newMount.Options, "Z")
 | 
				
			||||||
 | 
								case "shared":
 | 
				
			||||||
 | 
									newMount.Options = append(newMount.Options, "z")
 | 
				
			||||||
 | 
								default:
 | 
				
			||||||
 | 
									return newMount, "", fmt.Errorf("%s mount option must be 'private' or 'shared': %w", kv[0], errBadMntOption)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		case "consistency":
 | 
							case "consistency":
 | 
				
			||||||
			// Option for OS X only, has no meaning on other platforms
 | 
								// Option for OS X only, has no meaning on other platforms
 | 
				
			||||||
			// and can thus be safely ignored.
 | 
								// and can thus be safely ignored.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -510,8 +510,6 @@ func PlatformsFromOptions(c *cobra.Command) (platforms []struct{ OS, Arch, Varia
 | 
				
			||||||
	return platforms, nil
 | 
						return platforms, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const platformSep = "/"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// DefaultPlatform returns the standard platform for the current system
 | 
					// DefaultPlatform returns the standard platform for the current system
 | 
				
			||||||
func DefaultPlatform() string {
 | 
					func DefaultPlatform() string {
 | 
				
			||||||
	return platforms.DefaultString()
 | 
						return platforms.DefaultString()
 | 
				
			||||||
| 
						 | 
					@ -520,21 +518,19 @@ func DefaultPlatform() string {
 | 
				
			||||||
// Platform separates the platform string into os, arch and variant,
 | 
					// Platform separates the platform string into os, arch and variant,
 | 
				
			||||||
// accepting any of $arch, $os/$arch, or $os/$arch/$variant.
 | 
					// accepting any of $arch, $os/$arch, or $os/$arch/$variant.
 | 
				
			||||||
func Platform(platform string) (os, arch, variant string, err error) {
 | 
					func Platform(platform string) (os, arch, variant string, err error) {
 | 
				
			||||||
	split := strings.Split(platform, platformSep)
 | 
						if platform == "local" || platform == "" || platform == "/" {
 | 
				
			||||||
	switch len(split) {
 | 
							return Platform(DefaultPlatform())
 | 
				
			||||||
	case 3:
 | 
					 | 
				
			||||||
		variant = split[2]
 | 
					 | 
				
			||||||
		fallthrough
 | 
					 | 
				
			||||||
	case 2:
 | 
					 | 
				
			||||||
		arch = split[1]
 | 
					 | 
				
			||||||
		os = split[0]
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	case 1:
 | 
					 | 
				
			||||||
		if platform == "local" {
 | 
					 | 
				
			||||||
			return Platform(DefaultPlatform())
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return "", "", "", fmt.Errorf("invalid platform syntax for %q (use OS/ARCH[/VARIANT][,...])", platform)
 | 
						if platform[len(platform)-1] == '/' || platform[0] == '/' {
 | 
				
			||||||
 | 
							// If --platform string has format as `some/plat/string/`
 | 
				
			||||||
 | 
							// or `/some/plat/string` make it `some/plat/string`
 | 
				
			||||||
 | 
							platform = strings.Trim(platform, "/")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						platformSpec, err := platforms.Parse(platform)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return "", "", "", fmt.Errorf("invalid platform syntax for --platform=%q: %w", platform, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return platformSpec.OS, platformSpec.Architecture, platformSpec.Variant, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func parseCreds(creds string) (string, string) {
 | 
					func parseCreds(creds string) (string, string) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -102,7 +102,7 @@ github.com/containernetworking/cni/pkg/version
 | 
				
			||||||
# github.com/containernetworking/plugins v1.2.0
 | 
					# github.com/containernetworking/plugins v1.2.0
 | 
				
			||||||
## explicit; go 1.17
 | 
					## explicit; go 1.17
 | 
				
			||||||
github.com/containernetworking/plugins/pkg/ns
 | 
					github.com/containernetworking/plugins/pkg/ns
 | 
				
			||||||
# github.com/containers/buildah v1.30.0
 | 
					# github.com/containers/buildah v1.30.1-0.20230501124043-3908816d5310
 | 
				
			||||||
## explicit; go 1.18
 | 
					## explicit; go 1.18
 | 
				
			||||||
github.com/containers/buildah
 | 
					github.com/containers/buildah
 | 
				
			||||||
github.com/containers/buildah/bind
 | 
					github.com/containers/buildah/bind
 | 
				
			||||||
| 
						 | 
					@ -731,7 +731,7 @@ github.com/opencontainers/go-digest
 | 
				
			||||||
## explicit; go 1.17
 | 
					## explicit; go 1.17
 | 
				
			||||||
github.com/opencontainers/image-spec/specs-go
 | 
					github.com/opencontainers/image-spec/specs-go
 | 
				
			||||||
github.com/opencontainers/image-spec/specs-go/v1
 | 
					github.com/opencontainers/image-spec/specs-go/v1
 | 
				
			||||||
# github.com/opencontainers/runc v1.1.5 => github.com/opencontainers/runc v1.1.1-0.20220617142545-8b9452f75cbc
 | 
					# github.com/opencontainers/runc v1.1.7 => github.com/opencontainers/runc v1.1.1-0.20220617142545-8b9452f75cbc
 | 
				
			||||||
## explicit; go 1.17
 | 
					## explicit; go 1.17
 | 
				
			||||||
github.com/opencontainers/runc/libcontainer/apparmor
 | 
					github.com/opencontainers/runc/libcontainer/apparmor
 | 
				
			||||||
github.com/opencontainers/runc/libcontainer/cgroups
 | 
					github.com/opencontainers/runc/libcontainer/cgroups
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue