Skip to content
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

Closed
wants to merge 5 commits into from

Conversation

prabhav-thali
Copy link
Contributor

@prabhav-thali prabhav-thali commented Jun 3, 2020

Signed-off-by: Prabhav Thali [email protected]

What does this PR do?
Adds docker buildx support in cico scripts to build multi-arch images.

What issues does this PR fix or reference?
This refers to #17124

@prabhav-thali
Copy link
Contributor Author

@AndrienkoAleksandr Could you please trigger build for this PR on ci.centos?

echo 'CICO: Dependencies installed'
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this code always work like expected?

For me:
$ uname -a
5.5.17-200.fc31.x86_64

result of function:

$ printf '%02d' $(echo "$(uname -r)" | tr . ' ' | sed -e 's/ 0*/ /g') 2>/dev/null
0505170000

Maybe we could simple split by '-':

$ kernel_version=$(uname -r); echo ${kernel_version%%-*}
5.5.17

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We wanted comparison between 2 whole numbers, checking whichever is greater, for this reason we added this check. This code is working as per our expectation. Do you sense any possible issue in this?

Code :-

# Kernel
kernel_version="$(uname -r)"
if [[ "${kernel_version%%-*}" < "4.8" ]]; then
        echo >&2 "Kernel $kernel_version too old - need >= 4.8." \
                " Install a newer kernel."
else
        echo >&2 "kernel $kernel_version has binfmt_misc fix-binary (F) support."
fi

If kernel Version = 3.10.0-1062.el7 (Works as expected)
Condition : 3.10.0 < 4.8
O/P : Kernel 3.10.0-1062.el7 too old - need >= 4.8. Install a newer kernel.

If Kernel Version = 4.15.0-66-generic (Doesn't work as expected)
Condition : 4.15.0 < 4.8
O/P : Kernel 4.15.0-66-generic too old - need >= 4.8. Install a newer kernel.

If kernel Version = 5.5.17-200.fc31 (Works as expected)
Condition : 5.5.17 < 4.8
O/P : kernel 5.5.17-200.fc31.x86_64 has binfmt_misc fix-binary (F) support.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, it's make sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndrienkoAleksandr Could you please tell me whether you are testing these changes on env similar to ci.centos?

Copy link
Contributor

@nickboldt nickboldt Jun 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On F31, I get:

$➔ cat /etc/os-release | grep NAME
NAME=Fedora
VERSION_CODENAME=""
PRETTY_NAME="Fedora 31 (Thirty One)"
CPE_NAME="cpe:/o:fedoraproject:fedora:31"

$➔ kernel_version="$(uname -r)"

$➔ if [[ "${kernel_version%%-*}" < "4.8" ]]; then
>         echo >&2 "Kernel $kernel_version too old - need >= 4.8." \
>                 " Install a newer kernel."
> else
>         echo >&2 "kernel $kernel_version has binfmt_misc fix-binary (F) support."
> fi
kernel 5.6.15-200.fc31.x86_64 has binfmt_misc fix-binary (F) support.

On RHEL7.7:

+ cat /etc/os-release
+ grep NAME
NAME="Red Hat Enterprise Linux Server"
PRETTY_NAME="Red Hat Enterprise Linux Server 7.7 (Maipo)"
CPE_NAME="cpe:/o:redhat:enterprise_linux:7.7:GA:server"
++ uname -r
+ kernel_version=3.10.0-957.el7.x86_64
+ [[ 3.10.0 < 4.8 ]]
+ echo 'Kernel 3.10.0-957.el7.x86_64 too old - need >= 4.8.' ' Install a newer kernel.'
Kernel 3.10.0-957.el7.x86_64 too old - need >= 4.8.  Install a newer kernel.

Copy link
Contributor

@amisevsk amisevsk Jun 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also on the side of this being too fragile here. Apparently sort has a flag (-V) for sorting version numbers, so something like

function check_version() {
  local query=$1
  local target=$2
  echo "$target" "$query" | tr ' ' '\n' | sort -V -c 2> /dev/null
}

could work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amisevsk Thanks for the suggestion. Implemented version check using sort with -V. Please review.

@AndrienkoAleksandr
Copy link
Contributor

I asked QA to help us test this changes on the Centos ci. It is important to take a look how it works on the changed job. I afraid that this pr will damage job, because I tested this changes locally on the fedora 31. And I saw that build hangs for me on the arch linux/s390x . Centos based on fedora...

@prabhav-thali
Copy link
Contributor Author

@AndrienkoAleksandr Thanks for getting these changes tested on Centos ci.
We had tested these change on RHEL 8.2 as the buildx requirements were satisfied. And build was successful on both the archs i.e amd64, s390x.

Could you please provide your env details? Such that we can try out at our end.

echo 'CICO: Dependencies installed'
}

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

@amisevsk amisevsk Jun 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also on the side of this being too fragile here. Apparently sort has a flag (-V) for sorting version numbers, so something like

function check_version() {
  local query=$1
  local target=$2
  echo "$target" "$query" | tr ' ' '\n' | sort -V -c 2> /dev/null
}

could work

cico_functions.sh Outdated Show resolved Hide resolved
cico_functions.sh Outdated Show resolved Hide resolved
@prabhav-thali
Copy link
Contributor Author

And I saw that build hangs for me on the arch linux/s390x .

@AndrienkoAleksandr As we used latest multiarch/qemu-user-static image, build used to hang for s390x on go build. After switching to multiarch/qemu-user-static:4.2.0-7 image, build is successful on both the architectures. Could you please test the updated changes?

@prabhav-thali
Copy link
Contributor Author

@AndrienkoAleksandr any update?

@AndrienkoAleksandr
Copy link
Contributor

Sorry, Some time ago I asked QA about set up test job and check this pr. But they were busy. I will ask them again. Without test job we don't know how this change will affect CI.

@dmytro-ndp
Copy link

dmytro-ndp commented Jul 14, 2020

@AndrienkoAleksandr: I am sorry, but QE team doesn't support che-machine-exec build scripts at the moment, and we don't have enough expertise to verify corresponding changes.

@prabhav-thali
Copy link
Contributor Author

@dmytro-ndp
We are working on adding docker buildx support in other Che code repositores as well. If you could point us to any other Che code repository which is maintained by QE team, we can work/discuss that repository first. We have draft PRs for docker buildx support ready for following Che images:
che-operator
che-jwtproxy
che-plugin-broker
che-plugin-registry
che-devfile-registry

@@ -33,6 +33,30 @@ function load_jenkins_vars() {
fi
}

function check_version() {
Copy link
Member

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

Copy link
Contributor Author

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.

cico_functions.sh Outdated Show resolved Hide resolved
export DOCKER_CLI_EXPERIMENTAL=enabled

#Enable qemu and binfmt support
docker run --rm --privileged docker/binfmt:66f9012c56a8316f9244ffd7622d7c21c1f6f28d
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this tag expected to be used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
Also, updated the tag to the latest one.

Copy link
Member

@ibuziuk ibuziuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple of comments but in general LGTM


#set buildx env
export DOCKER_BUILD_KIT=1
export DOCKER_CLI_EXPERIMENTAL=enabled
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The buildah discussion appears to be here: containers/buildah#1590

Renamed method check_version
Extracted docker buildx in separate method

Signed-off-by: Prabhav Thali <[email protected]>
function check_buildx_support() {
docker_version="$(docker --version | cut -d' ' -f3 | tr -cd '0-9.')"
if [[ $(check_supported_version "$docker_version" "19.03") != 19.03 ]]; then
echo "CICO: Docker $docker_version greater than or equal to 19.03 is required."
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Member

@ibuziuk ibuziuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving this PR conceptually, but CI will very likely to fail due to the fact that it is unlikely that 19.03 version of docker will be installed by default on centos CI. So, the solution would be installing the right version of docker in the scripts. please wait for @nickboldt approval before merging

@prabhav-thali
Copy link
Contributor Author

@ibuziuk @nickboldt @AndrienkoAleksandr Any update?

@nickboldt
Copy link
Contributor

I haven't had time to look at this, as it doesn't impact downstream builds at all.

So, the solution would be installing the right version of docker in the scripts.

Can you make that change?

@mkuznyetsov do you have any thoughts on whether this will work?

@AndrienkoAleksandr
Copy link
Contributor

@ibuziuk @nickboldt @AndrienkoAleksandr Any update?

I don't have access to the CI to check this pr...

@nickboldt
Copy link
Contributor

@nickboldt nickboldt closed this Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants