Skip to content

Commit

Permalink
add cloudbuild
Browse files Browse the repository at this point in the history
Change-Id: Ib6a89c7c2f88dd3fbfa526a1458e8cb58ab356f0
  • Loading branch information
aojea committed Sep 2, 2024
1 parent 7a321a4 commit 17ddcaf
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 5 deletions.
24 changes: 19 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,31 @@ 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
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}
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
11 changes: 11 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -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']
38 changes: 38 additions & 0 deletions hack/init-buildx.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 17ddcaf

Please sign in to comment.