From f3bc179d053f9415f4e2836b301e5a79d93b4dff Mon Sep 17 00:00:00 2001 From: Aditi Jadhav Date: Thu, 4 Jun 2020 04:23:14 -0700 Subject: [PATCH] Added buildx support in cico scripts Signed-off-by: Aditi Jadhav --- cico_build_nightly.sh | 1 + cico_functions.sh | 47 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/cico_build_nightly.sh b/cico_build_nightly.sh index 76103b7124..2ff06aa937 100644 --- a/cico_build_nightly.sh +++ b/cico_build_nightly.sh @@ -22,5 +22,6 @@ export SCRIPT_DIR load_jenkins_vars install_deps +check_buildx_support set_nightly_tag build_and_push diff --git a/cico_functions.sh b/cico_functions.sh index 5ac3816c9a..4ad136cc7c 100644 --- a/cico_functions.sh +++ b/cico_functions.sh @@ -33,6 +33,30 @@ function load_jenkins_vars() { fi } +function check_version() { + local query=$1 + local target=$2 + echo "$target" "$query" | tr ' ' '\n' | sort -V | head -n1 2> /dev/null +} + +function check_buildx_support() { + docker_version="$(docker --version | cut -d' ' -f3 | tr -cd '0-9.')" + if [[ $(check_version "$docker_version" "19.03") != 19.03 ]]; then + echo "CICO: Docker $docker_version greater than or equal to 19.03 is required." + exit 1 + else + # Kernel + kernel_version="$(uname -r)" + if [[ $(check_version "$kernel_version" "4.8") != "4.8" ]]; then + echo "Kernel $kernel_version too old - need >= 4.8." \ + " Install a newer kernel." + exit 1 + else + echo "kernel $kernel_version has binfmt_misc fix-binary (F) support." + fi + fi +} + function install_deps() { # We need to disable selinux for now, XXX /usr/sbin/setenforce 0 || true @@ -44,6 +68,15 @@ function install_deps() { git service docker start + + #set buildx env + export DOCKER_BUILD_KIT=1 + export DOCKER_CLI_EXPERIMENTAL=enabled + + #Enable qemu and binfmt support + docker run --rm --privileged docker/binfmt:66f9012c56a8316f9244ffd7622d7c21c1f6f28d + docker run --rm --privileged multiarch/qemu-user-static:4.2.0-7 --reset -p yes + echo 'CICO: Dependencies installed' } @@ -52,12 +85,6 @@ function set_nightly_tag() { export TAG="nightly" } -function tag_push() { - local TARGET=$1 - docker tag "${IMAGE}" "$TARGET" - docker push "$TARGET" -} - function build_and_push() { REGISTRY="quay.io" ORGANIZATION="eclipse" @@ -72,7 +99,11 @@ function build_and_push() { fi # Let's build and push images to 'quay.io' - docker build -t ${IMAGE} . - tag_push "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}" + # Create a new builder instance using buildx + docker buildx create --use --name builder + docker buildx inspect --bootstrap + + docker buildx build --platform linux/amd64,linux/s390x -t ${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG} --push --progress plain --no-cache . + echo "CICO: '${TAG}' version of image pushed to '${REGISTRY}/${ORGANIZATION}' organization" }