From 0bc498e75b4bebc59122987964379b01f642fce0 Mon Sep 17 00:00:00 2001 From: Elina Akhmanova Date: Thu, 18 May 2023 11:16:11 +0000 Subject: [PATCH] Use one docker buildx command for e2e-test 1) Docker buildx cmd can build a multiarch image in one run. Use it instead of many commands 2) The hack/push-multiarch.sh script is used for e2e build via docker buildx (/root/.docker/cli-plugins/docker-buildx). It requires to specify HOME=/root so buildx works as expected. See: github.com/kubernetes/test-infra/tree/master/config/jobs/image-pushing Signed-off-by: Elina Akhmanova --- Dockerfile.e2e-test | 4 ++-- cloudbuild.yaml | 3 ++- hack/push-multiarch.sh | 37 ++++++++++++++----------------------- 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/Dockerfile.e2e-test b/Dockerfile.e2e-test index 5033dac628..11581a0113 100644 --- a/Dockerfile.e2e-test +++ b/Dockerfile.e2e-test @@ -18,8 +18,8 @@ # and has curl, gcloud, and ca-certificated preinstalled FROM gcr.io/google.com/cloudsdktool/google-cloud-cli:debian_component_based -#ARG_ARCH & ARG_BIN are replaces with sed in build/rules.mk -ADD bin/ARG_ARCH/ARG_BIN /ARG_BIN +ARG TARGETARCH +ADD bin/${TARGETARCH}/e2e-test /e2e-test COPY cmd/e2e-test/run.sh /run.sh ENTRYPOINT ["/run.sh"] diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 1e18bc2cdb..8c45046c2b 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -38,7 +38,8 @@ steps: # This image is built separately because it has # additional dependencies (curl, gcloud-cli), and # requires `docker buildx` for multiarch building process - ./hack/push-multiarch.sh + gcloud auth configure-docker \ + && ./hack/push-multiarch.sh substitutions: _GIT_TAG: "12345" _PULL_BASE_REF: "main" diff --git a/hack/push-multiarch.sh b/hack/push-multiarch.sh index b2d2dcd291..e0ce986821 100755 --- a/hack/push-multiarch.sh +++ b/hack/push-multiarch.sh @@ -17,6 +17,10 @@ set -o errexit set -o nounset set -o pipefail set -o xtrace + +# docker buildx is in /root/.docker/cli-plugins/docker-buildx +HOME=/root + REPO_ROOT=$(git rev-parse --show-toplevel) cd ${REPO_ROOT} @@ -40,27 +44,14 @@ docker buildx create --use for binary in ${BINARIES} do - MULTIARCH_IMAGE="${REGISTRY}/ingress-gce-${binary}" - MANIFEST_PARAMETERS="" - for arch in ${ALL_ARCH} - do - echo "building pushing a docker image for $binary and $arch.." - # creates arch dependant dockerfiles for every binary - sed \ - -e "s|ARG_ARCH|${arch}|g" \ - -e "s|ARG_BIN|${binary}|g" \ - "Dockerfile.${binary}" > ".dockerfile-${arch}.${binary}" - - # buildx builds and pushes images for any arch - IMAGE_NAME="${REGISTRY}/ingress-gce-${binary}-$arch" - docker buildx build --platform=linux/$arch \ - -f ".dockerfile-${arch}.${binary}" \ - -t "${IMAGE_NAME}:${VERSION}" --push . - MANIFEST_PARAMETERS="$MANIFEST_PARAMETERS ${IMAGE_NAME}:${VERSION}" - done - - echo "creating a multiatch manifest $MULTIARCH_IMAGE from a list of images.." - docker manifest create ${MULTIARCH_IMAGE}:${VERSION} ${MANIFEST_PARAMETERS} - docker manifest push ${MULTIARCH_IMAGE}:${VERSION} - echo "done, pushed $MULTIARCH_IMAGE:$VERSION image" + # "arm64 amd64" ---> "linux/arm64,linux/amd64" + PLATFORMS="linux/$(echo ${ALL_ARCH} | sed 's~ ~,linux/~g')" + echo "docker buildx platform parameters: ${PLATFORMS}" + MULTIARCH_IMAGE="${REGISTRY}/ingress-gce-${binary}:${VERSION}" + echo "building ${MULTIARCH_IMAGE} image.." + docker buildx build --push \ + --platform ${PLATFORMS} \ + --tag ${MULTIARCH_IMAGE} \ + -f Dockerfile.${binary} . + echo "done, pushed $MULTIARCH_IMAGE image" done