diff --git a/Makefile b/Makefile index 899220a9..2a5e0ec4 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,7 @@ lint: update: go mod tidy && go mod vendor + # get image name from directory we're building IMAGE_NAME=cloud-provider-kind # docker image registry, default to upstream @@ -37,10 +38,23 @@ REGISTRY?=gcr.io/k8s-staging-kind # tag based on date-sha TAG?=$(shell echo "$$(date +v%Y%m%d)-$$(git describe --always --dirty)") # the full image tag -IMAGE?=$(REGISTRY)/$(IMAGE_NAME):$(TAG) +CPK_IMAGE?=$(REGISTRY)/$(IMAGE_NAME):$(TAG) +PLATFORMS?=linux/amd64,linux/arm64 + +.PHONY: ensure-buildx +ensure-buildx: + ./hack/init-buildx.sh -# required to enable buildx -export DOCKER_CLI_EXPERIMENTAL=enabled image-build: -# docker buildx build --platform=${PLATFORMS} $(OUTPUT) --progress=$(PROGRESS) -t ${IMAGE} --pull $(EXTRA_BUILD_OPT) . - docker build . -t ${IMAGE} \ No newline at end of file + docker buildx build . \ + --tag="${CPK_IMAGE}" \ + --load + +image-push: + docker buildx build . \ + --platform="${PLATFORMS}" \ + --tag="${CPK_IMAGE}" \ + --push + +.PHONY: release # Build a multi-arch docker image +release: ensure-buildx image-push \ No newline at end of file diff --git a/cloudbuild.yaml b/cloudbuild.yaml new file mode 100644 index 00000000..f212e416 --- /dev/null +++ b/cloudbuild.yaml @@ -0,0 +1,11 @@ +# See https://cloud.google.com/cloud-build/docs/build-config +options: + substitution_option: ALLOW_LOOSE + machineType: E2_HIGHCPU_32 +steps: +- name: gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:v20240718-5ef92b5c36 + entrypoint: make + env: + - REGISTRY=gcr.io/k8s-staging-kind + - IMAGE_NAME=cloud-provider-kind + args: ['release'] diff --git a/hack/init-buildx.sh b/hack/init-buildx.sh new file mode 100755 index 00000000..610b60b1 --- /dev/null +++ b/hack/init-buildx.sh @@ -0,0 +1,38 @@ +#!/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 + +# We can skip setup if the current builder already has multi-arch +# AND if it isn't the docker driver, which doesn't work +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 "^Driver: docker$" <<<"${current_builder}" && \ + 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 tonistiigi/binfmt:qemu-v7.0.0-28@sha256:66e11bea77a5ea9d6f0fe79b57cd2b189b5d15b93a2bdb925be22949232e4e55 --install all +fi + +# Ensure we use a builder that can leverage it (the default on linux will not) +docker buildx rm knp-builder || true +docker buildx create --use --name=knp-builder