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

Prefer platform that is currently running #646

Closed

Conversation

lisa
Copy link

@lisa lisa commented Apr 22, 2019

Prefer platform that is currently running

The goal of this changeset is to prefer the current platform (v1.Platform, and GOARCH) to better support multiple (non-amd64) architectures. There are two targets for this: 1) the Makefile (and Dockerfiles), and 2) select the appropriate image manifest where possible.

  1. Makefile section Previously, the Makefile had set GOARCH to amd64, which is problematic for portability. Setting it to the value of go env GOARCH if not already set seems a good compromise.

Note: This changeset does not address the other inherent portability issues in the Dockerfiles (a separate PR may be forthcoming), but be aware that while the Makefile and code will support the Platform and GOARCH "auto-detection", the Dockerfiles still do not. All this section does is make a GOARCH kaniko binary.

  1. For container images that have multiple manifests, select the one for my platform

If an image has multiple manifests (such as debian:stretch, whose manifest list is linux/amd64, linux/arm/v5, linux/arm/v7, linux/arm64, linux/386, linux/ppc64le, linux/s390x), the previous behaviour was that kaniko, by way of go-containerregistry's current implementation, is to use the linux/amd64, image manifest if it exists.

This change uses runtime to construct a v1.Platform reference which is used as a platform option to remote.Image so that go-containerregistry will attempt to use the current platform's manifest, if it exists.

Motivation behind this change is to bring arm64 support to kaniko.

pkg/util/util.go Outdated
Config v1.Config
}

func ReproducibleDigest(img partial.WithManifestAndConfigFile) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

I dont think this function is used anywhere.

@tejal29
Copy link
Member

tejal29 commented Oct 4, 2019

@lisa Are you still interested in pursuing this PR?
Please rebase.

Thanks
Tejal

@lisa
Copy link
Author

lisa commented Oct 4, 2019

@lisa Are you still interested in pursuing this PR?
Please rebase.

Thanks
Tejal

Apologies, yes, I am. I'll try and tend to it this weekend.

@lisa
Copy link
Author

lisa commented Oct 6, 2019

@tejal29 The conflicts should be resolved.

lisa and others added 6 commits November 7, 2019 15:35
The goal of this changeset is to prefer the current platform
(`v1.Platform`, and `GOARCH`) to better support multiple (non-amd64)
architectures. There are two targets for this: 1) the Makefile (and
Dockerfiles), and 2) select the appropriate image manifest where
possible.

1. Makefile section Previously, the Makefile had set `GOARCH` to
`amd64`, which is problematic for portability. Setting it to the value
of `go env GOARCH` if not already set seems a good compromise.

**Note**: This changeset does *not* address the other inherent
portability issues in the Dockerfiles (a separate PR may be
forthcoming), but be aware that while the `Makefile` and code will
support the Platform and GOARCH "auto-detection", the Dockerfiles still
do not. All this section does is make a `GOARCH` kaniko binary.

2. For container images that have multiple manifests, select the one for
my platform

If an image has multiple manifests (such as debian:stretch, whose
manifest list is `linux/amd64, linux/arm/v5, linux/arm/v7, linux/arm64,
linux/386, linux/ppc64le, linux/s390x`), the previous behaviour was that
kaniko, by way of go-containerregistry's
[current](https://github.com/google/go-containerregistry/blob/8621d738a07bc74b2adeafd175a3c738423577a0/pkg/v1/remote/image.go#L92-L97)
[implementation](https://github.com/google/go-containerregistry/blob/8621d738a07bc74b2adeafd175a3c738423577a0/pkg/v1/remote/image.go#L36-L39),
is to use the `linux/amd64`, image manifest if it exists.

This change uses `runtime` to construct a `v1.Platform` reference which
is used as a [platform
option](https://github.com/google/go-containerregistry/blob/8621d738a07bc74b2adeafd175a3c738423577a0/pkg/v1/remote/options.go#L59-L64)
to `remote.Image` so that go-containerregistry will attempt to use the
current platform's manifest, if it exists.

Motivation behind this change is to bring arm64 support to kaniko.

Signed-off-by: Lisa Seelye <lisa@users.noreply.github.com>
@sgielen
Copy link

sgielen commented Nov 22, 2019

I am running Kaniko on arm64 and building images for arm64. Without the changes of this Diff applied, a simple build of the following Dockerfile:

FROM ubuntu
ENTRYPOINT ["/bin/bash", "-c", "echo hello"]

...results in a successful build but the following error when starting the resulting image on arm64:

$ kubectl logs kaniko-output
standard_init_linux.go:211: exec user process caused "exec format error"

However, with the changes to util/ applied to my local version of Kaniko, I can confirm that the image built from the same Dockerfile now results in a proper arm64 image:

$ kubectl logs kaniko-output
hello

@lisa
Copy link
Author

lisa commented Dec 4, 2019

I noticed this needs another rebase, so I'll take care of that when I have an opportunity.

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.

None yet

5 participants