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

Multi arch Dockerfile and CI #63

Merged
merged 13 commits into from
Jul 8, 2021
Merged

Multi arch Dockerfile and CI #63

merged 13 commits into from
Jul 8, 2021

Conversation

qdm12
Copy link
Contributor

@qdm12 qdm12 commented Jul 7, 2021

Dockerfile changes

  • Use Debian based :1-bullseye-slim Rust image for cross compilation instead of :1-alpine3.13, because:
    • it's 20MB smaller
    • Alpine 3.13 does not work well on 32 bit systems with an older libseccomp like on Raspberry Pis
    • it does not require to install musl cross building tools for the build platform so it's faster ⚡
    • it's available on more platforms than just amd64 and arm64 so users could build the image on their raspberry pis if they want to
  • Cross compile on native build platform so it's faster than Docker QEMU emulation ⚡
  • Compile static binaries by bundling musl in the binary (as before, note that this uses +3MB)
  • Set variables correctly for all Docker supported platforms
    • ppc64le, s390x and riscv64 do not support the Rust standard lib so it will fail for these
    • Persist target platform variables through files in /tmp/
  • Define linkers to use for each musl target in .cargo/config
  • Cache dependencies properly for target platform (so it's fast ⚡ with 1s rebuilds 🎉)
  • Scratch stage to test the binary is static and built correctly for the target platform
  • Remove useless (and long) cargo install instruction ⚡
  • Move statically compiled binary to /tmp to have a shorter COPY instruction for readability

Github Actions

Github Actions workflows were changed to build for 386, arm64, armv6 and armv7 on top of amd64.

See #48 for an updated list of things left to do.

@MindFlavor feel free to ask questions/suggestions and approve the PR so we can finally have cross built Docker images 🎉

qdm12 added 2 commits July 6, 2021 21:58
- Use rustup from Docker image
- Give up on cross compilation (ring issue)
- Remove useless duplicate cargo install step
- No need to specify target as it is built statically for the docker platform targeted
- Shorten binary path output for shorter COPY
@qdm12 qdm12 removed the request for review from MindFlavor July 7, 2021 02:59
qdm12 added 4 commits July 7, 2021 13:16
- Use Debian based Rust for compilation
- Cross compile on build platform
- Compile static binaries using musl
- Set variables correctly for all Docker supported platforms
- Note: ppc64le, s390x and riscv64 do not support the Rust standard lib
- Persist target platform variables through files
- Define linkers in .cargo/config
- Cache dependencies properly for target platform
- Scratch stage to test the binary for target platform
@qdm12 qdm12 requested a review from MindFlavor July 7, 2021 17:33
Copy link
Owner

@MindFlavor MindFlavor left a comment

Choose a reason for hiding this comment

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

This is awesome! Thank you @qdm12 ! 👍 👍

@MindFlavor MindFlavor merged commit 3a74f8b into master Jul 8, 2021
@qdm12 qdm12 deleted the multi-arch-dockerfile branch July 17, 2021 19:44
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.

2 participants