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

fix: handle docker's unknown/unknown platform in index manifests #975

Merged
merged 1 commit into from
Mar 8, 2023

Conversation

imjasonh
Copy link
Member

@imjasonh imjasonh commented Mar 8, 2023

Docker decided to include provenance attestations in index manifests, with descriptors having the platform unknown/unknown: https://docs.docker.com/build/attestations/attestation-storage/#image-index-sha25694acc2ca70c40f3f6291681f37ce9c767e3d251ce01c7e4e9b98ccf148c26260

This causes problems for ko build --platform=all since unknown/unknown is not a, well, known GOOS/GOARCH, in accordance with the OCI image spec.

This change ignores unknown/unknown when trying to match a multi-arch base image's platforms, even when using --platform=all.

Copy link
Collaborator

@jonjohnsonjr jonjohnsonjr left a comment

Choose a reason for hiding this comment

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

This LGTM, but we should consider looking at what the go tool thinks are valid GOOS and GOARCH combinations per the spec.

@imjasonh imjasonh merged commit 11670b7 into ko-build:main Mar 8, 2023
@developer-guy
Copy link
Collaborator

this is so cool!

listx pushed a commit to listx/test-infra that referenced this pull request Aug 18, 2023
The motivation for this change comes from the strange "unsupported
GOOS/GOARCH pair unknown/unknown" errors we were getting in [1] for the
pull-test-infra-prow-image-build-test job. There, we just bumped the
base `git` image from

    gcr.io/k8s-prow/git:v20220215-ddc3ad9

to

    gcr.io/k8s-prow/git:v20230817-0485b825c2

but this resulted in the aforementioned error for the pod utility
images (clonerefs, sidecar, etc). Digging further, these images are set
to the "all" platform in /.ko.yaml, and this results in the
hack/prowimagebuilder passing the "--platform=all" flag to ko, which
does the actual Docker image build. This instructs ko to look at the
Docker manifest of the base image (in this case the
`gcr.io/k8s-prow/git:...` image), and look through all of the
architectures there, and passes these as is to golang for the go build
invocation [2], which states

    To build and push an image for all platforms supported by the
    configured base image, simply add --platform=all. This will instruct
    ko to look up all the supported platforms in the base image, execute
    GOOS=<os> GOARCH=<arch> GOARM=<variant> go build for each platform,
    and produce a manifest list containing an image for each platform.

Previously (at least up to gcr.io/k8s-prow/git:v20230111-cd1b3caf9c),
the above behavior worked fine, because the <os> and <arch> bits in the
Docker manifest for these images looked normal (e.g., "linux", "amd64").
For example, gcr.io/k8s-prow/git:v20220215-ddc3ad9 only has entries that
look like

      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "digest": "sha256:232320cd437e5171fa7e29738e9efa191f714da1ae47d96c1f3b7e3016d15e52",
         "size": 1363,
         "platform": {
            "architecture": "amd64",
            "os": "linux"
         }
      },

and also for other architectures like "arm64".

But since gcr.io/k8s-prow/git:v20230324-76cde35b3d the git base image
started having "attestation-manifest" annotations [3] in the Docker
manifest that look like

      {
         "mediaType": "application/vnd.oci.image.manifest.v1+json",
         "digest": "sha256:5fd1fcaec895346cef283fdf47cf3b061ce7fb4cc8554151eb7b7052ab9886b6",
         "size": 566,
         "annotations": {
            "vnd.docker.reference.digest": "sha256:707be29a6b0a747163add36cb5a594580b4b9dcc7d55dd9324128f8a83d74eb3",
            "vnd.docker.reference.type": "attestation-manifest"
         },
         "platform": {
            "architecture": "unknown",
            "os": "unknown"
         }
      },

This means that ko, when given `--platform=all`, will try to pass in a
GOOS "unknown" and GOARCH "unknown" pair to `go build`, which leads to
the image build errors we saw in [1]. This buggy behavior of ko was
fixed in [4], and this change to update ko pulls in that fix.  We ran

   go get -u github.com/google/ko
   go mod tidy

to create this change.

[1] kubernetes#30410
[2] https://ko.build/features/multi-platform/
[3] https://docs.docker.com/build/attestations/attestation-storage/
[4] ko-build/ko#975
listx pushed a commit to listx/test-infra that referenced this pull request Aug 19, 2023
The motivation for this change comes from the strange "unsupported
GOOS/GOARCH pair unknown/unknown" errors we were getting in [1] for the
pull-test-infra-prow-image-build-test job. There, we just bumped the
base `git` image from

    gcr.io/k8s-prow/git:v20220215-ddc3ad9

to

    gcr.io/k8s-prow/git:v20230817-0485b825c2

but this resulted in the aforementioned error for the pod utility
images (clonerefs, sidecar, etc). Digging further, these images are set
to the "all" platform in /.ko.yaml, and this results in the
hack/prowimagebuilder passing the "--platform=all" flag to ko, which
does the actual Docker image build. This instructs ko to look at the
Docker manifest of the base image (in this case the
`gcr.io/k8s-prow/git:...` image), and look through all of the
architectures there, and passes these as is to golang for the go build
invocation [2], which states

    To build and push an image for all platforms supported by the
    configured base image, simply add --platform=all. This will instruct
    ko to look up all the supported platforms in the base image, execute
    GOOS=<os> GOARCH=<arch> GOARM=<variant> go build for each platform,
    and produce a manifest list containing an image for each platform.

Previously (at least up to gcr.io/k8s-prow/git:v20230111-cd1b3caf9c),
the above behavior worked fine, because the `<os>` and `<arch>` bits in the
Docker manifest for these images looked normal (e.g., "linux", "amd64").
For example, gcr.io/k8s-prow/git:v20220215-ddc3ad9 only has entries that
look like

      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "digest": "sha256:232320cd437e5171fa7e29738e9efa191f714da1ae47d96c1f3b7e3016d15e52",
         "size": 1363,
         "platform": {
            "architecture": "amd64",
            "os": "linux"
         }
      },

and also for other architectures like "arm64".

But since gcr.io/k8s-prow/git:v20230324-76cde35b3d the git base image
started having additional "attestation-manifest" annotations [3] in the
Docker manifest that look like

      {
         "mediaType": "application/vnd.oci.image.manifest.v1+json",
         "digest": "sha256:5fd1fcaec895346cef283fdf47cf3b061ce7fb4cc8554151eb7b7052ab9886b6",
         "size": 566,
         "annotations": {
            "vnd.docker.reference.digest": "sha256:707be29a6b0a747163add36cb5a594580b4b9dcc7d55dd9324128f8a83d74eb3",
            "vnd.docker.reference.type": "attestation-manifest"
         },
         "platform": {
            "architecture": "unknown",
            "os": "unknown"
         }
      },

This means that ko, when given `--platform=all`, will try to pass in a
GOOS "unknown" and GOARCH "unknown" pair to `go build`, which leads to
the image build errors we saw in [1]. This buggy behavior of ko was
fixed in [4], and this change to update ko pulls in that fix.  We ran

   go get -u github.com/google/ko
   go mod tidy

to create this change.

[1] kubernetes#30410
[2] https://ko.build/features/multi-platform/
[3] https://docs.docker.com/build/attestations/attestation-storage/
[4] ko-build/ko#975
listx pushed a commit to listx/test-infra that referenced this pull request Sep 6, 2023
The motivation for this change comes from the strange "unsupported
GOOS/GOARCH pair unknown/unknown" errors we were getting in [1] for the
pull-test-infra-prow-image-build-test job. There, we just bumped the
base `git` image from

    gcr.io/k8s-prow/git:v20220215-ddc3ad9

to

    gcr.io/k8s-prow/git:v20230817-0485b825c2

but this resulted in the aforementioned error for the pod utility
images (clonerefs, sidecar, etc). Digging further, these images are set
to the "all" platform in /.ko.yaml, and this results in the
hack/prowimagebuilder passing the "--platform=all" flag to ko, which
does the actual Docker image build. This instructs ko to look at the
Docker manifest of the base image (in this case the
`gcr.io/k8s-prow/git:...` image), and look through all of the
architectures there, and passes these as is to golang for the go build
invocation [2], which states

    To build and push an image for all platforms supported by the
    configured base image, simply add --platform=all. This will instruct
    ko to look up all the supported platforms in the base image, execute
    GOOS=<os> GOARCH=<arch> GOARM=<variant> go build for each platform,
    and produce a manifest list containing an image for each platform.

Previously (at least up to gcr.io/k8s-prow/git:v20230111-cd1b3caf9c),
the above behavior worked fine, because the `<os>` and `<arch>` bits in the
Docker manifest for these images looked normal (e.g., "linux", "amd64").
For example, gcr.io/k8s-prow/git:v20220215-ddc3ad9 only has entries that
look like

      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "digest": "sha256:232320cd437e5171fa7e29738e9efa191f714da1ae47d96c1f3b7e3016d15e52",
         "size": 1363,
         "platform": {
            "architecture": "amd64",
            "os": "linux"
         }
      },

and also for other architectures like "arm64".

But since gcr.io/k8s-prow/git:v20230324-76cde35b3d the git base image
started having additional "attestation-manifest" annotations [3] in the
Docker manifest that look like

      {
         "mediaType": "application/vnd.oci.image.manifest.v1+json",
         "digest": "sha256:5fd1fcaec895346cef283fdf47cf3b061ce7fb4cc8554151eb7b7052ab9886b6",
         "size": 566,
         "annotations": {
            "vnd.docker.reference.digest": "sha256:707be29a6b0a747163add36cb5a594580b4b9dcc7d55dd9324128f8a83d74eb3",
            "vnd.docker.reference.type": "attestation-manifest"
         },
         "platform": {
            "architecture": "unknown",
            "os": "unknown"
         }
      },

This means that ko, when given `--platform=all`, will try to pass in a
GOOS "unknown" and GOARCH "unknown" pair to `go build`, which leads to
the image build errors we saw in [1]. This buggy behavior of ko was
fixed in [4], and this change to update ko pulls in that fix.

We ran

   hack/make-rules/update/go-deps.sh --minor --tools github.com/google/ko@latest

to create this change.

[1] kubernetes#30410
[2] https://ko.build/features/multi-platform/
[3] https://docs.docker.com/build/attestations/attestation-storage/
[4] ko-build/ko#975
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants