Skip to content

Commit

Permalink
Use one docker buildx command for e2e-test
Browse files Browse the repository at this point in the history
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 <elinka@google.com>
  • Loading branch information
code-elinka committed May 19, 2023
1 parent 77aa2ec commit 3246298
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Dockerfile.e2e-test
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
3 changes: 2 additions & 1 deletion cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
32 changes: 12 additions & 20 deletions hack/push-multiarch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand All @@ -40,27 +44,15 @@ docker buildx create --use

for binary in ${BINARIES}
do
# "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}"
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 "building ${MULTIARCH_IMAGE}:${VERSION} image.."
docker buildx build --push \
--platform ${PLATFORMS} \
--tag ${MULTIARCH_IMAGE} \
-f Dockerfile.${binary} .
echo "done, pushed $MULTIARCH_IMAGE:$VERSION image"
done

0 comments on commit 3246298

Please sign in to comment.