-
Notifications
You must be signed in to change notification settings - Fork 63
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
Push multi-arch images #38
Conversation
Signed-off-by: ddelange <14880945+ddelange@users.noreply.github.com>
Signed-off-by: ddelange <14880945+ddelange@users.noreply.github.com> Signed-off-by: ddelange <14880945+ddelange@users.noreply.github.com>
Signed-off-by: ddelange <14880945+ddelange@users.noreply.github.com>
To avoid some of the arch related errors while installing libraries, we should probably use ubi8/go-toolset as base image instead of Alternatively, we could add another variable / docker build https://docs.docker.com/build/building/multi-platform/#building-multi-platform-images
https://github.com/kserve/modelmesh-runtime-adapter/blob/main/Dockerfile#L44 ... Archive files listed on the corresponding download page:
Default in the Dockerfile should probably be: ARG TARGETARCH=amd64 But we might have to disable |
Signed-off-by: Christian Kadner <ckadner@us.ibm.com>
Signed-off-by: Christian Kadner <ckadner@us.ibm.com>
Signed-off-by: Christian Kadner <ckadner@us.ibm.com>
Signed-off-by: Christian Kadner <ckadner@us.ibm.com>
Signed-off-by: Christian Kadner <ckadner@us.ibm.com>
Signed-off-by: Christian Kadner <ckadner@us.ibm.com>
Signed-off-by: Christian Kadner <ckadner@us.ibm.com>
Signed-off-by: Christian Kadner <ckadner@us.ibm.com>
Signed-off-by: Christian Kadner <ckadner@us.ibm.com>
Signed-off-by: Christian Kadner <ckadner@us.ibm.com>
Signed-off-by: Christian Kadner <ckadner@us.ibm.com>
Signed-off-by: Christian Kadner <ckadner@us.ibm.com>
The directory '/opt/app-root/src/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled Signed-off-by: Christian Kadner <ckadner@us.ibm.com>
Signed-off-by: Christian Kadner <ckadner@us.ibm.com>
@tjohnson31415 -- thanks for the pointer to not override the |
Signed-off-by: Christian Kadner <ckadner@us.ibm.com>
Signed-off-by: Christian Kadner <ckadner@us.ibm.com>
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.
I confirmed that I could build images with binaries for two different CPU archs using the approach coded up here.
Cool Stuff!
Makefile
Outdated
@@ -49,4 +47,4 @@ proto.compile: | |||
$(eval $(RUN_ARGS):;@:) | |||
|
|||
# Remove $(MAKECMDGOALS) if you don't intend make to just be a taskrunner | |||
.PHONY: all $(MAKECMDGOALS) | |||
.PHONY: all build build.develop develop run test fmt proto.compile $(MAKECMDGOALS) |
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.
I think $(MAKECMDGOALS)
will cover most of these; it injects the set of targets passed into make
on the cmd-line. The only explicit .PHONY you need then are ones that are dependent targets (so build.develop
should be in here).
Or its fine to make this list explicit with all targets but then don't need $(MAKECMDGOALS)
in here too.
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.
Thanks. I learned something and reinstated the original line :-)
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.
Though the original line also has a problem I think. $(MAKECMDGOALS)
is the set of goals specified on the cmd-line, but more targets will run if any of those goals have dependencies. So .PHONY: all $(MAKECMDGOALS)
is only sufficient if no targets in the Makefile have dependencies. If there is a dependency, it will not be .PHONY unless explicitly listed. In this case, build.develop
should still be in there.
So adding all the targets to .PHONY isn't a bad idea IMO, but there's no reason to add them all and also have $(MAKECMDGOALS)
.
Makefile hackery 😅
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.
Since this is tricky to understand -- and apparently was not understood by all developers who made updates to the Makefile
before ;-) -- I suggest we go with explicitly listing of all goals.
However, in the current form, this still leaves the door wide open for future developers who add new goals (or remove unused ones, or rename existing ones) to overlook/forget to update the .PHONY pseudo target at the end of the Makefile. So I would prefer to “tag” each individual goal like so:
.PHONY: fmt
fmt:
./scripts/fmt.sh
.PHONY: test
test:
go test -coverprofile cover.out `go list ./...`
This way, the .PHONY
"tag" would get deleted when the corresponding target gets deleted (or renamed along with renaming a target) and when new targets are added, very likely an existing target would be used as a “template” and the .PHONY
“tag” would get copy-pasted or added for sheer “consistency” by the uninitiated
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.
Makefiles are fun 😅 I came across a help command that regexes double hashtag above the command, and forms a helptext https://github.com/ddelange/mapply/blob/0.1.21/Makefile
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.
Signed-off-by: Christian Kadner <ckadner@us.ibm.com>
Thanks @tjohnson31415 -- I updated the PR with the straight-forward changes you suggested and resolved the corresponding conversations. I left the others as unresolved for you to respond :-) |
Signed-off-by: Christian Kadner <ckadner@us.ibm.com>
Dockerfile
Outdated
ARG PIP_CACHE_DIR=/root/.cache/pip | ||
RUN --mount=type=cache,target=/root/.cache/pip \ |
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.
So I've been experimenting with this a bit. Does this match your understanding?
- the $HOME for
root
ingo-toolset
is not/root/
so we need to set thePIP_CACHE_DIR
env var to configure pip's cache directory ARG
interpolation doesn't work in the--mount
, so the value is copied instead of usingtarget=$PIP_CACHE_DIR
If that's the case, I think it is slightly cleaner to set the PIP_CACHE_DIR env var in the RUN
command since the ARG
is not really configurable.
Though I also found moby/buildkit#815 and it sounds like using ARGs in --mount
can now work, but requires a newer Dockerfile syntax # syntax=docker/dockerfile:1.3.0
.
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.
Hi 👋
Unless the host system (github actions) would build python wheels from source, there is no speedup from mounting pip's cache dir. We generally recommend to set PIP_NO_CACHE_DIR and rely on docker layer caching by running pip install before copying over source code. That way, you reuse the registry's layer as long as your requirements.txt
doesn't change. Here's a live multi-arch example that combines a compiled C binary (libpostal) with python builds that use it.
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.
Good comments/questions @tjohnson31415 @ddelange !
Unless the host system (github actions) would build python wheels from source, there is no speedup from mounting pip's cache dir.
The cache mount is useful for subsequent builds, multi-stage and multi-platform builds. I have seen it being used and speedup the GitHub action builds quite a bit, with significant time savings for installing grpc
and tensorflow
the $HOME for
root
ingo-toolset
is not/root/
so we need to set thePIP_CACHE_DIR
env var to configure pip's cache directory
Yes, otherwise we see this error:
#13 12.99 The directory '/opt/app-root/src/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
#13 13.00 The directory '/opt/app-root/src/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
However, for pip
, the inline --cache-dir
CLI flag did not set the cache correctly for both HTTP download and the Wheel cache directories. So I use the ARG PIP_CACHE_DIR=/root/.cache/pip
which works for both.
ARG
interpolation doesn't work in the--mount
, so the value is copied instead of usingtarget=$PIP_CACHE_DIR
Yes. I have not tried the new syntax # syntax=docker/dockerfile:1.3.0
though. That's a good find.
References:
- https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/
- https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#run---mounttypecache
- https://docs.docker.com/build/cache/
- mount=type=cache more in-depth explanation? moby/buildkit#1673
- Allow controlling cache mounts storage location moby/buildkit#1512
Signed-off-by: Christian Kadner <ckadner@us.ibm.com>
Signed-off-by: Christian Kadner <ckadner@us.ibm.com>
Signed-off-by: Christian Kadner <ckadner@us.ibm.com>
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.
LGTM
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ddelange, tjohnson31415 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 |
awesome work @ckadner!! |
Motivation
Create multi-platform images for
modelmesh-runtime-adapter
images.Modifications
linux/amd64
,linux/arm64
(linux/ppc64le
,linux/s390x
are not supported bytensorflow
)pip
anddnf
installs as well asgo build
spull_request
as well as onpush
to catch build breaks during PR review;only push images to DockerHub on PR merge (push to
main
)ubi8/go-toolset:1.17
for developer image instead ofubi8/ubi-minimal:8.4
checkout
actionmake run fmt
inside the developer containerRelated PRs
modelmesh
(Push multi-arch images modelmesh#80)modelmesh-serving
(Push multi-arch images modelmesh-serving#314)rest-proxy
(Push multi-arch images rest-proxy#24)modelmesh-minio-examples
(Enable multi-platform build modelmesh-minio-examples#3)Resolves kserve/modelmesh-serving#162