Skip to content

Commit

Permalink
Added buildx support in cico scripts
Browse files Browse the repository at this point in the history
Signed-off-by: Aditi Jadhav <aditi.jadhav@ibm.com>
  • Loading branch information
Aditi Jadhav committed Jul 6, 2020
1 parent 81f733a commit f3bc179
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
1 change: 1 addition & 0 deletions cico_build_nightly.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ export SCRIPT_DIR

load_jenkins_vars
install_deps
check_buildx_support
set_nightly_tag
build_and_push
47 changes: 39 additions & 8 deletions cico_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
}

Expand All @@ -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"
Expand All @@ -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"
}

0 comments on commit f3bc179

Please sign in to comment.