Skip to content

Commit

Permalink
add cross build for base image
Browse files Browse the repository at this point in the history
  • Loading branch information
BenTheElder committed Feb 27, 2020
1 parent caf9041 commit 6d5ec59
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
38 changes: 38 additions & 0 deletions hack/build/init-buildx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
#!/usr/bin/env bash
# Copyright 2020 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit -o nounset -o pipefail

export DOCKER_CLI_EXPERIMENTAL=enabled

# We can skip setup if the current builder already has multi-arch
current_builder="$(docker buildx inspect)"
# linux/amd64, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6
if grep -q "linux/amd64" <<<"${current_builder}" && grep -q "linux/arm64" <<<"${current_builder}"; then
exit 0
fi

# Ensure qemu is in binfmt_misc
# Docker desktop already has these in versions recent enough to have buildx
# We only need to do this setup on linux hosts
if [ "$(uname)" == 'Linux' ]; then
# NOTE: this is pinned to a digest for a reason!
docker run --rm --privileged multiarch/qemu-user-static@sha256:c772ee1965aa0be9915ee1b018a0dd92ea361b4fa1bcab5bbc033517749b2af4 --reset -p yes
fi

# Ensure we use a builder that can leverage it (the default on linux will not)
docker buildx rm kind-builder || true
docker buildx create --use --name=kind-builder
27 changes: 27 additions & 0 deletions images/base/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
TAG?=$(shell echo "$$(date +v%Y%m%d)-$$(git describe --always --dirty)")
IMAGE?=kindest/base:$(TAG)

# build with buildx
PLATFORMS?=linux/amd64,linux/arm64
OUTPUT=
build: ensure-buildx
docker buildx build --platform=${PLATFORMS} $(OUTPUT) -t ${IMAGE} --pull .

# push the cross built image
push: OUTPUT=--push
push: build

# quick can be used to do a build that will be imported into the local docker
# for sanity checking before doing a cross build push
# cross builds cannot be imported locally at the moment
# https://github.com/docker/buildx/issues/59
quick: PLATFORMS=linux/amd64
quick: OUTPUT=--load
quick: build

# enable buildx
DOCKER_CLI_EXPERIMENTAL=enabled
ensure-buildx:
./../../hack/build/init-buildx.sh

.PHONY: push build quick ensure-buildx

0 comments on commit 6d5ec59

Please sign in to comment.