-
Notifications
You must be signed in to change notification settings - Fork 495
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
Cannot set multi-platform bake contexts if platforms do not match exactly #2486
Comments
Seems like your machine does not support arm architectures which is why your build fails with either |
The issue is not that my machine does not support ARM (I can You can check this locally by changing the platforms for Lines 878 to 881 in 9ad116a
to |
Oh my bad I can't read 🙈 So yes platforms need to perfectly match otherwise it fails with this error because there is no proper linking between platforms in your named context. Does it work with the following definition?: target "default" {
dockerfile-inline = "FROM other"
contexts = {
other = "target:other"
}
platforms = [
"linux/amd64",
"linux/arm64",
"linux/arm/v7"
]
}
target "other" {
dockerfile-inline = "FROM docker.io/library/alpine:3"
platforms = [
"linux/amd64",
"linux/arm64",
"linux/arm/v7"
]
} Maybe if a named context does not match |
Yes, the snippet you link works. The issue is that I want to build two separate targets, one of which supports more platforms than the other 😅 . I think changing Lines 501 to 505 in 9ad116a
to check if |
Yeah maybe a subset would be enough but wonder if should not override with platforms from caller instead per my comment #2486 (comment). WDYT @tonistiigi? |
@crazy-max @tonistiigi @PigeonF I recently stumbled across this problem and I think a subset, rather than overriding, is what I'd expect. If I referenced an image here rather than a target, and the platform wasn't found, it would return an error. I've been treating However, whilst that's what I'd expect to happen, I don't know whether that's a good enough reason to not just override. I'm hoping my thoughts here at least help us choose a direction. Do they? 😄 I'd really like to contribute the fix when we know the path forward. |
I think subset-based validation should work fine. |
It's kind of odd that the check only comes into play with So if the target or referenced target only have the one platform each, they can completely differ from each other. I suspect originally this was suppose to use Changing that now would probably be a breaking change. It also means that as long as you only provided one platform, the referenced target platform never mattered before. Due to this, maybe it should override, rather than be a subset? It feels odd to enforce a subset only when there's 2 or more platforms. |
Apologies for the noise.
It turns out it does matter.
This passes validation, but will only create an amd64 image. The target being a subset does matter, it's just that the current validation isn't correct. |
That In a more practical sense, an example of a valid use case on mismatching platforms is cross-compilation. The target you are importing may be always used for your native architecture, while the caller target may be multi-platform. For example https://github.com/tonistiigi/xx/blob/master/docker-bake.hcl#L189 does that. From API standpoint, named contexts in BuildKit can have a platform identifier or may not. If they don't then they match against any platform. For example, this is how platform matching works internally and how bake uses to map them. from foo
run uname -m && cat /etc/alpine-release || true buildctl build --opt context:foo::linux/amd64=docker-image://busybox --opt context:foo::linux/arm64=docker-image://alpine --opt platform=linux/amd64,linux/arm64 --local dockerfile=. --progress=plain --frontend=dockerfile.v0
...
#7 [linux/arm64 1/2] RUN uname -m && cat /etc/alpine-release || true
#7 0.074 aarch64
#7 0.074 3.21.0
#7 DONE 0.1s
#8 [linux/amd64 1/2] RUN uname -m && cat /etc/alpine-release || true
#8 0.083 x86_64
#8 0.092 cat: can't open '/etc/alpine-release': No such file or directory
#8 DONE 0.1s In a normal case you would just do |
Contributing guidelines
I've found a bug and checked that ...
Description
When using a
target:
directive as a bakefile context in a multi-platform scenario, the platforms of the targets have to match exactly or the build fails.Expected behaviour
The build should succeed if the referencing target is built for a subset of the platforms of the referenced target.
Actual behaviour
The build fails unless the platforms match exactly.
Buildx version
github.com/docker/buildx v0.14.0
Docker info
Builders list
Configuration
Build logs
Additional info
No response
The text was updated successfully, but these errors were encountered: