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

Improve IPDK cli and ci build/run with buildx, multiarch, artefacts and push to registries #102

Merged
merged 3 commits into from
Feb 18, 2022

Conversation

stolsma
Copy link
Contributor

@stolsma stolsma commented Feb 9, 2022

Implements large parts of #101

Expanded IPDK CLI commands and options with:

  • Support ipdk config [key]=[value] for setting key=value in ~/.ipdk/ipdk.env
  • Support ipdk build --platform [docker buildx supported platforms] for local and multiarch builds
  • Support ipdk build --tags [taglist] --labels [labellist] --push --export [filename]
  • Support ipdk start --platform [docker buildx supported platform]
  • Support ipdk tag [tag] for local image builds
  • Support ipdk export [filename] for local image builds
  • Support ipdk push [tag] for local image builds
  • check for support of docker buildx on host system

Example:
ipdk build --no-cache --platform linux/arm64 builds a ARM64 based ipdk image if run on a linux/amd-64 based host system
ipdk start --platform linux/arm64 starts a ARM64 based image on a linux/amd-64 based host system by using qemu emulation

Expanded the Github makefile.yml action file with:

  • concurrency option to prevent running multiple build actions for the same PR or push.
  • install of qemu runtimes
  • install of buildx
  • (for now disabled) login to dockerhub
  • login to Github Container Registry (ghcr)
  • create build metadata (tags and labels)
  • use ipdk cli build command
  • push the created multiarch container images to the registries when run from push
  • upload created multiarch container images as artefacts when the action is run from PR
  • Currently only building containers for one architecture platform (linux/amd-64)

Signed-off-by: stolsma github@tolsma.net

@stolsma
Copy link
Contributor Author

stolsma commented Feb 9, 2022

First stab at implementing multi platform docker images! Please review + need a lot to test and figure out. One of the things to figure out is how to get buildx support on github actions 😉

@mestery
Copy link
Contributor

mestery commented Feb 9, 2022

Won't this take a really long time to run because of the Qemu emulation?

@stolsma
Copy link
Contributor Author

stolsma commented Feb 9, 2022

Won't this take a really long time to run because of the Qemu emulation?

Hahaha, yes, thats why I didn't use --platform linux/arm64 (for example) to start with ;-) but it fails anyway as buildx needs to be installed on the github actions ubuntu image....

I need to find out how exactly to cross compile together with buildx platforms, but I have an idea, will work on it tomorrow!

@stolsma stolsma force-pushed the ci-architectures branch 3 times, most recently from 5b52df0 to 8712575 Compare February 10, 2022 15:08
@mestery
Copy link
Contributor

mestery commented Feb 10, 2022

Looks like the arm64 requests are taking too long. I think I'll try to setup the OCI GitHub runner today to get that part working and we can do arm64 builds there.

@stolsma
Copy link
Contributor Author

stolsma commented Feb 10, 2022

Yeah, those aarch64 builds are taking too long, but what is worse is that some commands take more then the maximum intermediate response time of github so the runner thinks its dead... Hopefully the Arm runners will help here!!!

@stolsma
Copy link
Contributor Author

stolsma commented Feb 10, 2022

Is it also possible to add docker hub or github registry credentials to the org ? Then we can push the build result there so people don't need to build containers themselves anymore if they don't want to...

@mestery
Copy link
Contributor

mestery commented Feb 10, 2022

Is it also possible to add docker hub or github registry credentials to the org ? Then we can push the build result there so people don't need to build containers themselves anymore if they don't want to...

Yes, this is next on my list today, I pushed out a few PRs fixing a few nit-pick things in the meantime. Will work on Dockerhub account and ability to push there next.

@stolsma stolsma force-pushed the ci-architectures branch 8 times, most recently from 840e8de to aa35aad Compare February 11, 2022 12:46
@stolsma stolsma changed the title Implement cross platform build/run with buildx Improve docker build/run with buildx and matrix job action Feb 11, 2022
@stolsma stolsma force-pushed the ci-architectures branch 2 times, most recently from aa62aae to a9e9cc5 Compare February 11, 2022 14:41
@stolsma stolsma marked this pull request as ready for review February 11, 2022 14:46
@stolsma
Copy link
Contributor Author

stolsma commented Feb 11, 2022

Added concurrency to prevent several checks for the same PR at the same time, the last push will be run by Github Actions. If more are running they are cancelled.

Added Artefact saving, tagging and prepared DockerHub saving and Github Container Registry saving.

Will let it rest until after the weekend! Please review!

Copy link
Contributor

@mestery mestery left a comment

Choose a reason for hiding this comment

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

Do you want to separate out the platform support from this PR? It seems as if you're making enhancements to the CI which are not related to the arm platform anymore. Also, I think we should just the OCI arm runners for arm builds. I am going to work on getting that up and running at some point today.

@stolsma stolsma force-pushed the ci-architectures branch 2 times, most recently from dbfc254 to a3afa07 Compare February 14, 2022 12:45
@stolsma stolsma changed the title Improve docker build/run with buildx and matrix job action Improve IPDK cli and ci build/run with buildx, multiarch, artefacts and push to registries Feb 15, 2022
@stolsma
Copy link
Contributor Author

stolsma commented Feb 15, 2022

Ok, I think everything is implemented to support several solutions of building IPDK containers. Support is available for base distribution selection, single/multi architecture image builds, tags & label adding, save to artefacts and push to registries. All those options also work for local builds and Github CI builds but with the caveat that the local docker image store only supports single architecture images! (that's a docker limitation!!!)

The three remaining questions are:

  1. are we going to support multiarch images and how are we going to build them ? See also 3.
  2. how we are going to speed up build time and get the images smaller
    • my opinion is that we need to split the build in a development image build (with all extra tools installed) and a production image build used in CI (only with the libraries to get the IPDK programs running). Both can be made available on Dockerhub & GHCR. The development image can for example automatically be build and pushed to registries once a day and the production images build and pushed to registries on push to main (and for testing with PRs).
  3. how are we going to integrate private build environments like OCI for ARM64.
    • Two options to select from:
      1. use buildx builder nodes to add a OCI based docker buildx ARM64 environment and create multiarch images
      2. use a OCI based ARM64 runner and create single arch images

@mestery and others, what would you think????

@mestery
Copy link
Contributor

mestery commented Feb 16, 2022

Ok, I think everything is implemented to support several solutions of building IPDK containers. Support is available for base distribution selection, single/multi architecture image builds, tags & label adding, save to artefacts and push to registries. All those options also work for local builds and Github CI builds but with the caveat that the local docker image store only supports single architecture images! (that's a docker limitation!!!)

The three remaining questions are:

  1. are we going to support multiarch images and how are we going to build them ? See also 3.

I think we should, but I don't think we can do it using docker buildx with Qemu on the default runners GitHub Actions uses because it's too slow. Ideally, we'd use something like OCI and have our own native arm64 runners.

  1. how we are going to speed up build time and get the images smaller

    • my opinion is that we need to split the build in a development image build (with all extra tools installed) and a production image build used in CI (only with the libraries to get the IPDK programs running). Both can be made available on Dockerhub & GHCR. The development image can for example automatically be build and pushed to registries once a day and the production images build and pushed to registries on push to main (and for testing with PRs).

My thinking is that IPDK should not be building P4-OVS each time, and that we should move to focus on the OVS repository and get proper CI which builds P4-OVS and stores it somewhere. The IPDK build will then pull the latest version of P4-OVS. This means the IPDK build would be really fast, and only people modifying P4-OVS would require the hour long build we currently have.

  1. how are we going to integrate private build environments like OCI for ARM64.

    • Two options to select from:

      1. use buildx builder nodes to add a OCI based docker buildx ARM64 environment and create multiarch images
      2. use a OCI based ARM64 runner and create single arch images

I think we'd just integrate arm64 runners on OCI by making them runners.

@mestery and others, what would you think????

@stolsma
Copy link
Contributor Author

stolsma commented Feb 16, 2022

I think we'd just integrate arm64 runners on OCI by making them runners.

@mestery I will change the PR then to use a os and platform matrix to create (at this moment) a Ubuntu18.04-amd64, Ubuntu20.04-amd-64 and fedora33-amd64 container image. When OCI for arm64 is added as runner then arm64 can be added to the platform matrix and three *-arm64 will also be created next to the previous three. Agreed?

My thinking is that IPDK should not be building P4-OVS each time, and that we should move to focus on the OVS repository and get proper CI which builds P4-OVS and stores it somewhere. The IPDK build will then pull the latest version of P4-OVS. This means the IPDK build would be really fast, and only people modifying P4-OVS would require the hour long build we currently have.

Agree, I think we should split a "once a day build" for p4c as well. That shouldn't be a big problem as the (container) build examples already exist for Ubuntu and Fedora and can easily be merged with the IPDK build just like p4-ovs.

@mestery
Copy link
Contributor

mestery commented Feb 17, 2022

@stolsma Is this ready for review and merge?

@stolsma
Copy link
Contributor Author

stolsma commented Feb 18, 2022

@mestery If the last run checks out ok it is ready for review and merge!!! Changed the action so OCI runner support can be added later by changing matrix.runner directive!

…nd push to registries

Implements large parts of ipdk-io#101

Expanded IPDK CLI commands and options with:
- Support `ipdk config [key]=[value]` for setting key=value in ~/.ipdk/ipdk.env
- Support `ipdk build --platform [docker buildx supported platforms]` for local and multiarch builds
- Support `ipdk build --tags [taglist] --labels [labellist] --push --export [filename]`
- Support `ipdk start --platform [docker buildx supported platform]`
- Support `ipdk tag [tag]` for local image builds
- Support `ipdk export [filename]` for local image builds
- Support `ipdk push [tag]` for local image builds
- check for support of `docker buildx` on host system

Example:
`ipdk build --no-cache --platform linux/arm64` builds a ARM64 based ipdk image if run on a linux/amd-64 based host system
`ipdk start --platform linux/arm64` starts a ARM64 based image on a linux/amd-64 based host system by using qemu emulation

Expanded the Github `makefile.yml` action file with:
- concurrency option to prevent running multiple build actions for the same PR or push.
- install of qemu runtimes
- install of buildx
- (for now disabled) login to dockerhub
- login to Github Container Registry (ghcr)
- create build metadata (tags and labels)
- use ipdk cli build command
- push the created multiarch container images to the registries when run from push
- upload created multiarch container images as artefacts when the action is run from PR
- Currently only building containers for one architecture platform (linux/amd-64)

Signed-off-by: stolsma <github@tolsma.net>
build/scripts/ipdk-lib.sh Outdated Show resolved Hide resolved
build/scripts/ipdk-lib.sh Outdated Show resolved Hide resolved
@mestery
Copy link
Contributor

mestery commented Feb 18, 2022

@mestery If the last run checks out ok it is ready for review and merge!!! Changed the action so OCI runner support can be added later by changing matrix.runner directive!

This is great! I'll merge this one once it passes (and I fix @rst0git's comments), and then this afternoon I'll create an OCI account and try to get an arm64 runner working there!

A more reliable way of getting docker versions.

Signed-off-by: Kyle Mestery <mestery@mestery.com>
If it's not enabled by default on the GitHub runner, try to enable.

Signed-off-by: Kyle Mestery <mestery@mestery.com>
Copy link
Contributor

@mestery mestery left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @stolsma!

@mestery mestery merged commit ba79684 into ipdk-io:main Feb 18, 2022
docker_experimental="$(docker version --format='{{.Server.Experimental}}')"
if [[ "$docker_experimental" != 'true' ]]; then
echo "docker experimental flag not enabled: Set with 'export DOCKER_CLI_EXPERIMENTAL=enabled'" >&2
return 1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I only check and do not install because in the build code I fall back to the old docker build command if the host doesnt comply to the new docker buildx functionalities... By trying to reconfigure the host you use sudo so the cli will crash instead of using the old command if the user is not allowed to use sudo but is allowed to use docker. Prefer not change the host system but warn....

Just had a 110mph gust around the house... We are still save but trees are coming down in the neighbourhood 😔

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem was that your original code was not working, and in fact, buildx wasn't enabled on the GitHub runners, and things failed. However, re-enabling it here makes things work ok, so this is what I merged. Feel free to submit a followup which fixes this is if you want.

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.

3 participants