Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add multi-arch docker image build support
Update the Dockerfile to support cross-compile via GOOS and GOARCH. To use docker buildx cross-compile feature, the --platform=$BUILDPLATFORM is included for the builder stage. BUILDPLATFORM matches the runner machine platform and GOOS + GOARCH is used to tell Go to cross-compile for the specific combo passed. Move from go install to go build, because it can't install a cross-compiled binary; instead the output is saved in /usr/bin/k6 and copied from that path in the final stage. Change the build workflow from docker build to docker buildx create and docker buildx build. For the build command the --platform flag is transformed as TARGETOS and TARGETARCH variables. This provides a faster builder stage using the native architecture, with the slow part being left to the runtime stage which will only copy the final binary. The resulting OCI image will provide a OCI Index that contains both architecture images. Adding support for more platform/arch combos is as simple as adding more entries to the docker buildx create and docker buildx build --platform flags. More on this method of cross-compilation here: https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/
- Loading branch information