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

fix: fix Makefile and Dockerfile for idempotent images and to support multi-arch builds Fixes RHOAIENG-12078 #322

Merged
merged 8 commits into from
Sep 19, 2024

Conversation

dhirajsb
Copy link
Contributor

@dhirajsb dhirajsb commented Aug 30, 2024

Description

Cleanup Makefile and Dockerfile to make them reproducable
Add multi-arch platform builds

How Has This Been Tested?

CI will verify Makefile and Dockerfile changes
Dockerfile changes can be tested locally by updating model-registry.yaml

Merge criteria:

  • All the commits have been signed-off (To pass the DCO check)
  • The commits have meaningful messages; the author will squash them after approval or in case of manual merges will ask to merge with squash.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work.
  • Code changes follow the kubeflow contribution guidelines.

If you have UI changes

  • The developer has added tests or explained why testing cannot be added.
  • Included any necessary screenshots or gifs if it was a UI change.
  • Verify that UI/UX changes conform the UX guidelines for Kubeflow.

@dhirajsb
Copy link
Contributor Author

I'll continue on cleaning it up for multi-arch build support tomorrow.

There is something interesting happening though. Try editing model-registry.yaml to add a new endpoint (duplicate the first path with a different path and operationId) and see the behavior.

@dhirajsb
Copy link
Contributor Author

The type_asserts.go file is doing what @isinyaaa mentioned. Let's see if we can sort the output in some way to make it idempotent.

@dhirajsb dhirajsb force-pushed the feat/makefile-cleanup branch 2 times, most recently from d9af014 to c3f4f5a Compare August 30, 2024 03:30
@dhirajsb
Copy link
Contributor Author

I can use regular expressions for extracting and sorting the functions to fix this. I'll add that tomorrow.

@dhirajsb dhirajsb force-pushed the feat/makefile-cleanup branch from 03d0237 to 27a1dcf Compare August 31, 2024 02:13
@dhirajsb
Copy link
Contributor Author

dhirajsb commented Aug 31, 2024

Made gen_type_assert.sh idempotent. I'll add docker env variables for multi-platform builds and a makefile target next.

@dhirajsb dhirajsb marked this pull request as ready for review September 13, 2024 03:58
@dhirajsb
Copy link
Contributor Author

@tarilabs @isinyaaa you can try out multi-platform builds using a command similar to:

IMG_ORG=dhirajsb make image/buildx

This command built and pushed images to my dockerhub repo https://hub.docker.com/r/dhirajsb/model-registry/tags

Give it a try and let me know what happens on other platforms.

@dhirajsb
Copy link
Contributor Author

As an experiment, I built the project in different ways and on my admittedly beefy laptop I saw the following build times:

Buildx with emulation, no BUILDPLATFORM:
[+] Building 2184.9s (94/94) FINISHED                                    docker-container:model-registry-builder
Buildx with cross compilation with non-optimized Makefile build:
[+] Building 593.3s (82/82) FINISHED                                     docker-container:model-registry-builder
Buildx with cross compilation and optimized Makefile:
[+] Building 590.7s (86/86) FINISHED                                     docker-container:model-registry-builder

Copy link
Member

@tarilabs tarilabs left a comment

Choose a reason for hiding this comment

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

Thank you very much @dhirajsb , output as requested:

[+] Building 314.4s (86/86) FINISHED                                                                                                                                                                                                                                                                                              docker-container:model-registry-builder

Appreciate ordering in the type asserts file generation too!

We will need a way to test these, possibly by leveraging the e2e as mentioned before wiring it as the shipped images, but this is great progress imho and many thanks again!
🚀

/lgtm

Dockerfile Show resolved Hide resolved
@dhirajsb
Copy link
Contributor Author

@tarilabs is this supposed to auto-merge after your lgtm?

@dhirajsb dhirajsb changed the title [WIP] fix: fix Makefile and Dockerfile for idempotent images and to support multi-arch builds Fixes RHOAIENG-12078 fix: fix Makefile and Dockerfile for idempotent images and to support multi-arch builds Fixes RHOAIENG-12078 Sep 13, 2024
@dhirajsb dhirajsb requested a review from tarilabs September 13, 2024 16:29
@isinyaaa
Copy link
Contributor

isinyaaa commented Sep 13, 2024

I haven't been able to run make image/buildx using podman desktop on mac. Made sure to update it and I'm still getting:

$ make image/buildx
docker buildx create --use --name model-registry-builder
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
Error: unknown flag: --use
See 'podman buildx --help'
make: *** [image/buildx] Error 125

when I list the commands, however, there's not even a create cmd. @tarilabs can you confirm your podman and podman-desktop version? Mine are v1.12.0 for desktop and 5.2.2 for podman.

@dhirajsb
Copy link
Contributor Author

@isinyaaa podman doesn't support the same options for buildx. I'm testing a change locally to fix that.

@google-oss-prow google-oss-prow bot removed the lgtm label Sep 13, 2024
@dhirajsb dhirajsb force-pushed the feat/makefile-cleanup branch from 08b782b to e43d21f Compare September 13, 2024 20:44
@dhirajsb
Copy link
Contributor Author

dhirajsb commented Sep 13, 2024

I added podman support for using buildx. But unfortunately there is no command parity. And, the podman buildx build also seems to run in a very un-optimized fashion.

@isinyaaa test it and let us know.

@isinyaaa
Copy link
Contributor

I was able to test with docker and podman on mac using:

make image/buildx

and

DOCKER=podman make image/buildx

respectively. Can report it worked fine, although I've lost track of the running times because I had to reboot.
Can try again if you need that info.

# architectures. (i.e. make docker-buildx). To use this option you need to:
# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
# - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
# - be able to push the image to your registry (i.e. if you do not set a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
Copy link
Contributor

Choose a reason for hiding this comment

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

can't we make a separate rule for pushing? we're not only building for that purpose AFAIK, but also to be able to have those images locally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Docker doesn't support that, it doesn't keep manifests locally and have to be pushed to a registry.

Copy link
Contributor

@isinyaaa isinyaaa Sep 16, 2024

Choose a reason for hiding this comment

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

IIUC it does cache results, but they're not exported to docker by default.
To do that, you can use --load on the build cmd.
I'm not sure if you can push it subsequently at no cost though, or if you have to build again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are open issues with --load and it didn't work for me. Multi-platform builds are useful for publishing to remote repos, not as much for local use.
E.g. we'll do it in CI on PR merge and not for pulls.

@isinyaaa
Copy link
Contributor

strangely, I'm also not able to build again:

$ make image/buildx
# docker uses builder containers
docker buildx create --use --name model-registry-builder
ERROR: existing instance for "model-registry-builder" but no append mode, specify the node name to make changes for existing instances
make: *** [image/buildx] Error 1

@dhirajsb
Copy link
Contributor Author

The rebuild error sounds like the docker buildx rm... command didn't run the last time. You can modify it to avoid this error by adding the append flag as well. Feel free to do so if you want to try it.

Signed-off-by: Dhiraj Bokde <dhirajsb@users.noreply.github.com>
fix gen/openapi-server make target to generate go-server if model-registry.yaml file is newer

Signed-off-by: Dhiraj Bokde <dhirajsb@users.noreply.github.com>
Signed-off-by: Dhiraj Bokde <dhirajsb@users.noreply.github.com>
… to type_asserts.go

Signed-off-by: Dhiraj Bokde <dhirajsb@users.noreply.github.com>
…s using docker buildx,

split 'build' target into 'build/prepare' and 'build/compile' to optimize multi-platform builds

Signed-off-by: Dhiraj Bokde <dhirajsb@users.noreply.github.com>
…tion, optimize build steps

Signed-off-by: Dhiraj Bokde <dhirajsb@users.noreply.github.com>
Signed-off-by: Dhiraj Bokde <dhirajsb@users.noreply.github.com>
@dhirajsb dhirajsb force-pushed the feat/makefile-cleanup branch from bf67a92 to 1edf825 Compare September 18, 2024 16:02
Signed-off-by: Dhiraj Bokde <dhirajsb@users.noreply.github.com>
@dhirajsb dhirajsb force-pushed the feat/makefile-cleanup branch from 1edf825 to 83e9c87 Compare September 18, 2024 17:49
Copy link
Contributor

@isinyaaa isinyaaa left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: isinyaaa, tarilabs

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow google-oss-prow bot merged commit 3b00296 into kubeflow:main Sep 19, 2024
16 checks passed
@isinyaaa isinyaaa mentioned this pull request Sep 19, 2024
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants