Skip to content

Builder: Check remote when local img platform doesn't match#40629

Merged
thaJeztah merged 1 commit into
moby:masterfrom
cpuguy83:buildkit_check_img_arch
Mar 31, 2020
Merged

Builder: Check remote when local img platform doesn't match#40629
thaJeztah merged 1 commit into
moby:masterfrom
cpuguy83:buildkit_check_img_arch

Conversation

@cpuguy83

@cpuguy83 cpuguy83 commented Mar 6, 2020

Copy link
Copy Markdown
Member

fixes docker/for-linux#1144

This fixes an issue where if a build requests an image that already
exists in Docker's image store but does not match the specified build
platform, instead of building using the wrong platform go ahead and
check the remote for the correct platform.

Steps to reproduce issue:

$ docker pull --platform=amd64 debian:buster
<output supressed>
$ cat Dockerfile
FROM debian:buster
RUN echo hello
$ docker build --platform=armhf -< Dockerfile
<output supressed>

Without this fix, the build invocation will build using the amd64 image
since it is already tagged locally, but this is clearly not what we
want.

With the fix the local image is not used and instead we pull the correct
image.

@cpuguy83
cpuguy83 requested review from tiborvass and tonistiigi March 6, 2020 06:33
@cpuguy83

cpuguy83 commented Mar 6, 2020

Copy link
Copy Markdown
Member Author

Any ideas how to write a test for this?

This fixes an issue where if a build requests an image that already
exists in Docker's image store but does not match the specified build
platform, instead of building using the wrong platform go ahead and
check the remote for the correct platform.

Steps to reproduce issue:

```terminal
$ docker pull --platform=amd64 debian:buster
<output supressed>
$ cat Dockerfile
FROM debian:buster
RUN echo hello
$ docker build --platform=armhf -< Dockerfile
<output supressed>
```

Without this fix, the build invokcation will build using the amd64 image
since it is already tagged locally, but this is clearly not what we
want.

With the fix the local image is not used and instead we pull the correct
image.

Signed-off-by: Brian Goff <[email protected]>
@tonistiigi tonistiigi removed their assignment Mar 18, 2020
@thaJeztah thaJeztah changed the title Builder: Check remote when local img platform doesn't match [WIP] Builder: Check remote when local img platform doesn't match Mar 26, 2020
@thaJeztah

Copy link
Copy Markdown
Member

Marked as "WIP", because possibly #40725 could also address the problem; @cpuguy83 will look further into that

@cpuguy83 cpuguy83 changed the title [WIP] Builder: Check remote when local img platform doesn't match Builder: Check remote when local img platform doesn't match Mar 27, 2020
@cpuguy83

Copy link
Copy Markdown
Member Author

Unmarked WIP since the other PR will not have an effect on this.

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thaJeztah
thaJeztah merged commit bd81cf2 into moby:master Mar 31, 2020
@thaJeztah

Copy link
Copy Markdown
Member

@cpuguy83 this one we want to backport?

@tonistiigi

Copy link
Copy Markdown
Member

I think we shouldn't backport this. It's subtly changing the behavior and although previous was undocumented and new makes more sense it might still be somewhat surprising in a patch release.

@thaJeztah

Copy link
Copy Markdown
Member

👍

@cpuguy83

Copy link
Copy Markdown
Member Author

Agreed with @tonistiigi

@cpuguy83
cpuguy83 deleted the buildkit_check_img_arch branch March 31, 2020 16:02
img, err := is.resolveLocal(ref)
if err == nil {
return "", dt, err
if img.Architecture != opt.Platform.Architecture || img.Variant != opt.Platform.Variant || img.OS != opt.Platform.OS {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tonistiigi Should this have checked if the img.Variant is even set?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docker run's --platform option is ignored if the image already exists locally

3 participants