Skip to content

Fix builder inconsistent error on buggy platform#41873

Merged
thaJeztah merged 1 commit into
moby:masterfrom
cpuguy83:fix_builder_inconsisent_platform
Jan 21, 2021
Merged

Fix builder inconsistent error on buggy platform#41873
thaJeztah merged 1 commit into
moby:masterfrom
cpuguy83:fix_builder_inconsisent_platform

Conversation

@cpuguy83

@cpuguy83 cpuguy83 commented Jan 13, 2021

Copy link
Copy Markdown
Member

addresses docker/for-linux#1170

When pulling an image by platform, it is possible for the image's
configured platform to not match what was in the manifest list.
The image itself is buggy because either the manifest list is incorrect
or the image config is incorrect. In any case, this is preventing people
from upgrading because many times users do not have control over these
buggy images.

This was not a problem in 19.03 because we did not compare on platform
before. It just assumed if we had the image it was the one we wanted
regardless of platform, which has its own problems.

Example Dockerfile that has this problem:

FROM --platform=linux/arm64 k8s.gcr.io/build-image/debian-iptables:buster-v1.3.0
RUN echo hello

This fails the first time you try to build after it finishes pulling but
before performing the RUN command.
On the second attempt it works because the image is already there and
does not hit the code that errors out on platform mismatch (Actually it
ignores errors if an image is returned at all).

Must be run with the classic builder (DOCKER_BUILDKIT=0).

This should mostly be safe (and certainly safer than 19.03) since we only check this immediately after a pull.

Example output before the fix:

root@07d110f25ff1:/go/src/github.com/docker/docker# DOCKER_BUILDKIT=0 docker build -t test -< ./Dockerfile.fix 
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM --platform=linux/arm64 k8s.gcr.io/build-image/debian-iptables:buster-v1.3.0
buster-v1.3.0: Pulling from build-image/debian-iptables
0b711604db4a: Pull complete 
952e2ac66b7a: Pull complete 
37e66e9a979e: Pull complete 
c3cbd1f2e855: Pull complete 
0e1a7dafc259: Pull complete 
643e4c7dc28d: Pull complete 
Digest: sha256:4c9410a4ee555dcb0e8b7bd6fc77c65ac400f7c5bd4555df8187630efaea6ea4
Status: Downloaded newer image for k8s.gcr.io/build-image/debian-iptables:buster-v1.3.0
image with reference k8s.gcr.io/build-image/debian-iptables:buster-v1.3.0 was found but does not match the specified platform: wanted linux/arm64, actual: linux/amd64
root@07d110f25ff1:/go/src/github.com/docker/docker# 

Example output after the fix:

root@34d494e751a0:/go/src/github.com/docker/docker# DOCKER_BUILDKIT=0 docker build -t test -< ./Dockerfile.fix 
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM --platform=linux/arm64 k8s.gcr.io/build-image/debian-iptables:buster-v1.3.0
buster-v1.3.0: Pulling from build-image/debian-iptables
0b711604db4a: Pull complete 
952e2ac66b7a: Pull complete 
37e66e9a979e: Pull complete 
c3cbd1f2e855: Pull complete 
0e1a7dafc259: Pull complete 
643e4c7dc28d: Pull complete 
Digest: sha256:4c9410a4ee555dcb0e8b7bd6fc77c65ac400f7c5bd4555df8187630efaea6ea4
Status: Downloaded newer image for k8s.gcr.io/build-image/debian-iptables:buster-v1.3.0

WARNING: Pulled image with specified platform (linux/arm64), but resulting image's configured platform (linux/amd64) does not match.
This is most likely caused by a bug in the build system that created the fetched image (k8s.gcr.io/build-image/debian-iptables:buster-v1.3.0).
Please notify the image author to correct the configuration.

 ---> ee124318448e
Step 2/2 : RUN echo hello
 ---> Running in 375eb8439033
hello
Removing intermediate container 375eb8439033
 ---> cd1060cadbce
Successfully built cd1060cadbce
Successfully tagged test:latest

Comment thread daemon/images/image_builder.go Outdated

@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.

SGTM

@tonistiigi @tianon PTAL

Comment thread daemon/images/image_builder.go Outdated

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.

Suggested change
`, platforms.Format(p), platforms.Format(imgPlat), name)
`, platforms.Format(p), platforms.Format(imgPlat), name)

@cpuguy83
cpuguy83 force-pushed the fix_builder_inconsisent_platform branch from e78741f to ae8abfc Compare January 14, 2021 19:18

@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.

still LGTM

@thaJeztah

Copy link
Copy Markdown
Member

@tonistiigi ptal

Comment thread daemon/images/image_builder.go Outdated
@cpuguy83
cpuguy83 force-pushed the fix_builder_inconsisent_platform branch from ae8abfc to 1708731 Compare January 14, 2021 19:39
@thaJeztah thaJeztah added area/images Image Service kind/bugfix PR's that fix bugs status/4-merge and removed status/2-code-review labels Jan 14, 2021
@thaJeztah

Copy link
Copy Markdown
Member

@cpuguy83 did you rebase? I see TestBuildUserNamespaceValidateCapabilitiesAreV2 is failing, and that should be fixed by #41865

When pulling an image by platform, it is possible for the image's
configured platform to not match what was in the manifest list.
The image itself is buggy because either the manifest list is incorrect
or the image config is incorrect. In any case, this is preventing people
from upgrading because many times users do not have control over these
buggy images.

This was not a problem in 19.03 because we did not compare on platform
before. It just assumed if we had the image it was the one we wanted
regardless of platform, which has its own problems.

Example Dockerfile that has this problem:

```Dockerfile
FROM --platform=linux/arm64 k8s.gcr.io/build-image/debian-iptables:buster-v1.3.0
RUN echo hello
```

This fails the first time you try to build after it finishes pulling but
before performing the `RUN` command.
On the second attempt it works because the image is already there and
does not hit the code that errors out on platform mismatch (Actually it
ignores errors if an image is returned at all).

Must be run with the classic builder (DOCKER_BUILDKIT=0).

Signed-off-by: Brian Goff <[email protected]>
@cpuguy83
cpuguy83 force-pushed the fix_builder_inconsisent_platform branch from 1708731 to 3996953 Compare January 14, 2021 21:46
@cpuguy83

Copy link
Copy Markdown
Member Author

Rebased.

@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

s390x failure is unrelated

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.

3 participants