-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
CI: Use cross compilation for arm64 #4106
base: master
Are you sure you want to change the base?
Conversation
bdabf89
to
058618d
Compare
docker/Dockerfile.arm64-cross
Outdated
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.
Could we use the official crystal docker image here?
This would require to compile the binary outside the Dockerfile then for each architecture copy the file in the correct location.
This is actually a technique used by a lot of golang projects.
My idea is to finally have a docker image for all the architecture instead of having separate docker images.
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.
They don't provide official ARM64 images:
https://hub.docker.com/r/crystallang/crystal/tags
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.
Nah you did not understood what I meant. You use the official docker image for crystal just for crosscompiling the binary then you create a separate docker image with just alpine where you copy the binary for each architecture.
Now that I think of it, we can also compile the binary on the host and not inside docker. But that would make that much more difficult for anyone to compile invidious using only docker.
I'm on the phone so I can't easily find an example but most golang projects do it like this.
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.
Ah, I see. The problem with that is we need two dockerfiles (one for each arch), and AFAIK, you can't COPY --from
between different build contexts.
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.
You should look into how they are doing in this article, it's well explained: https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/
It's pretty clever. No need for separate docker images.
More articles:
c9689a9
to
a56eeda
Compare
This is a perfect example of "works on my machine" ... |
7795216
to
cbc34ad
Compare
Ahhh, finally :D |
It's great but my issue is that I don't want to have many Dockerfile for building invidious, this may confuse our users. If this new Dockerfile Ideally we should still keep a Dockerfile that works out of the box, or we create a make command that do all of that. I know it's just testing for the moment but let's not forget about that. I'm fine in the future with becoming the main way to build invidious but we have to keep the ability to easily build invidious through a single command or (two). |
I should have added all the necessary targets into the Makefile. For regular people, either of the following will build invidious:
Then, for user wanting to cross-compile (e.g if the Crystal compiler is not available, or the destination is not very powerful, like a RPi-like SBC), invidious can be compiled using this process:
|
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.
For me I prefer to implement the solution done in #4106 (comment)
So I don't accept this merge request for now sorry.
Realistically, cross-compilation with Docker is only required for CI/CD, right? |
Not being required to install crystal locally. My idea was to have the cross-compilation Dockerfile used by default Dockerfile. It works great for intel x86 processors and this will now allow anyone to build custom images for other architectures out of the box with docker buildx. About the people that are using ARM processor, we can keep the Dockerfile.arm64 for now until crystal release one. This way we can keep just two Dockerfile in the repository. |
Yeah, but given that most people will be building for the same target as their host, can't we simplify and only have one Dockerfile (i.e adapt the "arm" one to be generic, and stop using the upstream one? Also, given that the work is almost done, I was thinking of adding support for armhf (ARM v7 hard float EABI).
Can it be done so that a single Dockerfile works all ways? (either arm64 or amd64 host -> either arm64 or amd64 target) |
That would be very difficult to do and much more maintenance for us to maintain a whole crystal docker image.
We would have to use crystal package with alpine linux for that, but the issue is that we can't easily control the crystal version we want to use, because alpine linux doesn't offer the ability to use a specific crystal version. We have to use the crystal version shipped the alpine linux version we would use. So if one day for example we have to use crystal 10.10.1 due to breaking changes in the newer version but 10.10.2 is only available on alpine linux we are screwed. |
Note: I'm putting this PR aside until I have the time/willingness to address unixfox's remark. For whoever finds this in-between: the code is fully functional, feel free to reuse it. |
cbc34ad
to
e2866b4
Compare
e2866b4
to
b99dabd
Compare
PCRE2 support was added in Crystal v1.7.0, and used by default in Crystal v1.8.0. As we don't want to have to guess what version of the PCRE was used on the build host, force the use of the legacy version until we drop support for older versions of Crystal.
b99dabd
to
ad9ba38
Compare
No description provided.