Skip to content

Commit

Permalink
Merge pull request #2121 from code-elinka/cezarys-change
Browse files Browse the repository at this point in the history
Use hack script for e2e test image building
  • Loading branch information
k8s-ci-robot authored May 17, 2023
2 parents 0dab8fd + 601393b commit bc34d38
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
21 changes: 14 additions & 7 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,40 @@ options:
machineType: E2_HIGHCPU_8
steps:
- name: gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:v20230206-8160eea68e
id: build-binaries
id: push-images
entrypoint: bash
env:
- DOCKER_CLI_EXPERIMENTAL=enabled
- REGISTRY=gcr.io/k8s-ingress-image-push
- VERSION=$_PULL_BASE_REF
- VERBOSE=1
- HOME=/root
- USER=root
args:
args:
- -c
- |
make all-build ALL_ARCH="amd64 arm64"
# Build and push every image except e2e-test
make all-push ALL_ARCH="amd64 arm64" \
CONTAINER_BINARIES="glbc 404-server 404-server-with-metrics echo fuzzer"
- name: gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:v20230206-8160eea68e
id: push-images
waitFor: ["build-binaries"]
id: push-e2e-test-image
entrypoint: bash
env:
- DOCKER_CLI_EXPERIMENTAL=enabled
- REGISTRY="gcr.io/k8s-ingress-image-push"
- REGISTRY=gcr.io/k8s-ingress-image-push
- VERSION=$_PULL_BASE_REF
- VERBOSE=1
- HOME=/root
- USER=root
- BINARIES=e2e-test
args:
- -c
- |
make all-push ALL_ARCH="amd64 arm64"
# Build and push e2e-test image
# 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
substitutions:
_GIT_TAG: "12345"
_PULL_BASE_REF: "main"
38 changes: 23 additions & 15 deletions hack/push-multiarch.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/bin/bash

# Run commands that build and push images

# This script is used instead of build/rules.mk
# whenever you need to build multiarch image with
# docker buildx build --platform=smth
# (see Dockerfiles in the root directory)

# ENV variables:
Expand All @@ -21,8 +25,13 @@ ALL_ARCH=${ALL_ARCH:-"amd64 arm64"}
REGISTRY=${REGISTRY:-"gcr.io/example"}
VERSION=${VERSION:-"test"}

echo "building all `bin/<arch>/<binary-name>`.."
make build ALL_ARCH="${ALL_ARCH}" BINARIES="${BINARIES}"
echo BINARIES=${BINARIES}
echo ALL_ARCH=${ALL_ARCH}
echo REGISTRY=${REGISTRY}
echo VERSION=${VERSION}

echo "building all binaries"
make all-build ALL_ARCH="${ALL_ARCH}" CONTAINER_BINARIES="${BINARIES}"

# To create cross compiled images
echo "setting up docker buildx.."
Expand All @@ -32,27 +41,26 @@ docker buildx create --use
for binary in ${BINARIES}
do
MULTIARCH_IMAGE="${REGISTRY}/ingress-gce-${binary}"
DOCKER_PARAMETERS=""
MANIFEST_PARAMETERS=""
for arch in ${ALL_ARCH}
do
echo "building & pushing a docker image for ${binary} (${arch}).."
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}
-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 .
docker pull ${IMAGE_NAME}:${VERSION}
DOCKER_PARAMETERS="$DOCKER_PARAMETERS ${IMAGE_NAME}:${VERSION}"
-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 buildx imagetools create -t "${MULTIARCH_IMAGE}:${VERSION}" ${DOCKER_PARAMETERS}

echo "done, a result image: ${MULTIARCH_IMAGE}:${VERSION}."
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"
done

0 comments on commit bc34d38

Please sign in to comment.