Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
Added buildx support in cico scripts
Browse files Browse the repository at this point in the history
Signed-off-by: Aditi Jadhav <[email protected]>
  • Loading branch information
Aditi Jadhav committed Jun 24, 2020
1 parent 3e04c92 commit fa376cd
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 9 deletions.
8 changes: 7 additions & 1 deletion cico_build_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ export SCRIPT_DIR
load_jenkins_vars
install_deps
setup_environment
build_and_push
check="$(check_buildx_support)"
export check
if [[ $check = "true" ]]; then
build_and_push_using_buildx
else
build_and_push
fi
9 changes: 8 additions & 1 deletion cico_build_nightly.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ setup_environment

build_patched_base_images
build_happy_path_image
build_and_push
check="$(check_buildx_support)"
export check
if [[ $check = "true" ]]; then
build_and_push_using_buildx
else
build_and_push
fi

9 changes: 8 additions & 1 deletion cico_build_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ setup_environment

build_patched_base_images
build_happy_path_image
build_and_push_release
check="$(check_buildx_support)"
export check
if [[ $check = "true" ]]; then
build_and_push_release_using_buildx
else
build_and_push_release
fi

68 changes: 62 additions & 6 deletions cico_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,34 @@ function load_jenkins_vars() {
fi
}

function check_buildx_support() {
export DOCKER_BUILD_KIT=1
export DOCKER_CLI_EXPERIMENTAL=enabled

docker_version="$(docker --version | cut -d' ' -f3 | tr -cd '0-9.')"
if [[ "$(version "$docker_version")" < "$(version '19.03')" ]]; then
echo "CICO: Docker $docker_version is too old. Greater than or equal to 19.03 is required."
buildx="false"
else
# Kernel
kernel_version="$(uname -r)"
if [[ "$(version "$kernel_version")" < "$(version '4.8')" ]]; then
echo >&2 "Kernel $kernel_version too old - need >= 4.8." \
" Install a newer kernel."
buildx="false"
else
echo >&2 "kernel $kernel_version has binfmt_misc fix-binary (F) support."
buildx="true"
fi
fi

echo "$buildx"
}

function version() {
printf '%02d' "$(echo "$1" | tr . ' ' | sed -e 's/ 0*/ /g')" 2>/dev/null
}

function install_deps() {
# We need to disable selinux for now, XXX
/usr/sbin/setenforce 0 || true
Expand All @@ -46,6 +74,11 @@ function install_deps() {
git

service docker start

#Enable qemu and binfmt support
docker run --rm --privileged docker/binfmt:66f9012c56a8316f9244ffd7622d7c21c1f6f28d
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

echo 'CICO: Dependencies installed'
}

Expand All @@ -61,12 +94,6 @@ function set_nightly_tag() {
export TAG="nightly"
}

function tag_push() {
local TARGET=$1
docker tag "${IMAGE}" "$TARGET"
docker push "$TARGET" | cat
}

# Set appropriate environment variables and login to the docker registry
# as the required user.
function setup_environment() {
Expand Down Expand Up @@ -110,6 +137,22 @@ function build_and_push() {
fi
}

function build_and_push_using_buildx() {
# Let's build and push image to 'quay.io' using git commit hash as tag first
# 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}:"${GIT_COMMIT_TAG}" -f ./build/dockerfiles/"${DOCKERFILE}" --push --progress plain --no-cache .
echo "CICO: '${GIT_COMMIT_TAG}' version of images pushed to '${REGISTRY}/${ORGANIZATION}' organization"

# If additional tag is set (e.g. "nightly"), let's build the image accordingly and also push to 'quay.io'
if [ -n "${TAG}" ]; then
docker buildx build --platform linux/amd64,linux/s390x -t ${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG} -f ./build/dockerfiles/"${DOCKERFILE}" --push --progress plain --no-cache .
echo "CICO: '${TAG}' version of images pushed to '${REGISTRY}/${ORGANIZATION}' organization"
fi
}

# Build release version of devfile registry, using ${TAG} / ${GIT_COMMIT_TAG} as a tag. For release
# versions, the devfiles are rewritten to refer to ${TAG}-tagged images with the
# arbitrary user patch
Expand All @@ -128,6 +171,19 @@ function build_and_push_release() {
echo "CICO: release '${TAG}' version of devfile registry pushed to '${REGISTRY}/${ORGANIZATION}' organization"
}

function buildx_and_push_release_using_buildx() {
# Create a new builder instance using buildx
docker buildx create --use --name builder
docker buildx inspect --bootstrap

echo "CICO: building release '${TAG}' / '${GIT_COMMIT_TAG}' version of devfile registry"
docker buildx build --platform=linux/amd64,linux/s390x --build-arg PATCHED_IMAGES_TAG=${TAG} -t ${REGISTRY}/${ORGANIZATION}/${IMAGE}:"${GIT_COMMIT_TAG}" -f ${DOCKERFILE_PATH} --target registry . --push --progress plain --no-cache
echo "CICO: '${GIT_COMMIT_TAG}' version of devfile registry built and pushed to '${REGISTRY}/${ORGANIZATION}' organization"

docker buildx build --platform=linux/amd64,linux/s390x --build-arg PATCHED_IMAGES_TAG=${TAG} -t ${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG} -f ${DOCKERFILE_PATH} --target registry . --push --progress plain --no-cache
echo "CICO: release '${TAG}' version of devfile registry built and pushed to '${REGISTRY}/${ORGANIZATION}' organization"
}

# Build images patched to work on OpenShift (work with arbitrary user IDs) and push
# them to registry. NOTE: 'arbitrary-users-patch' images will be pushed only to the public
# 'https://quay.io/organization/eclipse' organization
Expand Down

0 comments on commit fa376cd

Please sign in to comment.