-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added docker buildx support in cico scripts. #109
Changes from 4 commits
b970b3b
cf3297a
f868cfc
da4897c
4c02956
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,5 @@ export SCRIPT_DIR | |
|
||
load_jenkins_vars | ||
install_deps | ||
check_buildx_support | ||
build_and_push |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,5 +22,6 @@ export SCRIPT_DIR | |
|
||
load_jenkins_vars | ||
install_deps | ||
check_buildx_support | ||
set_nightly_tag | ||
build_and_push |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,5 +22,6 @@ export SCRIPT_DIR | |
|
||
load_jenkins_vars | ||
install_deps | ||
check_buildx_support | ||
set_release_tag | ||
build_and_push |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() { | ||
prabhav-thali marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just suspect that centos CI has the version lower than 19.03 - we might need to install new version of docker manually |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit iffy about relying on experimental features from Docker but if this is the One True Way to do multiarch builds, then so be it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
#Enable qemu and binfmt support | ||
docker run --rm --privileged docker/binfmt:66f9012c56a8316f9244ffd7622d7c21c1f6f28d | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this tag expected to be used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes @ibuziuk The tag is expected to be used. Available tags for the image docker/binfmt can be found [here].(https://hub.docker.com/r/docker/binfmt/tags) |
||
docker run --rm --privileged multiarch/qemu-user-static:4.2.0-7 --reset -p yes | ||
|
||
echo 'CICO: Dependencies installed' | ||
} | ||
|
||
|
@@ -66,12 +99,6 @@ function set_git_commit_tag() { | |
export GIT_COMMIT_TAG | ||
} | ||
|
||
function tag_push() { | ||
local TARGET=$1 | ||
docker tag "${IMAGE}" "$TARGET" | ||
docker push "$TARGET" | cat | ||
} | ||
|
||
function build_and_push() { | ||
REGISTRY="quay.io" | ||
DOCKERFILE="Dockerfile" | ||
|
@@ -86,13 +113,16 @@ function build_and_push() { | |
|
||
# Let's build and push image to 'quay.io' using git commit hash as tag first | ||
set_git_commit_tag | ||
docker build -t ${IMAGE} -f ./build/dockerfiles/${DOCKERFILE} . | cat | ||
tag_push "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${GIT_COMMIT_TAG}" | ||
echo "CICO: '${GIT_COMMIT_TAG}' version of images pushed to '${REGISTRY}/${ORGANIZATION}' organization" | ||
|
||
# If additional tag is set (e.g. "nightly"), let's tag the image accordingly and also push to 'quay.io' | ||
# 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" | ||
|
||
prabhav-thali marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# If additional tag is set (e.g. "nightly"), let's build the image accordingly and also push to 'quay.io' | ||
if [ -n "${TAG}" ]; then | ||
tag_push "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}" | ||
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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@prabhav-thali could you please make the function name more descriptive. For me it is not clear what exactly 'check_version' does
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the function name and added docs for the same.