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

Build arm64 Docker image #115

Merged
merged 6 commits into from
Oct 24, 2023

Conversation

felixvanoost
Copy link
Contributor

@felixvanoost felixvanoost commented Oct 14, 2023

Builds and tests a multi-architecture Docker image for both linux/amd64 and linux/arm64 platforms as discussed in this comment and in #114. This allows ARM-based machines to run the image natively with no emulation.

manifest-digest

This includes the following changes:

  • Builds the linux/amd64 and linux/arm64 images on dedicated native runners. The typical "low-effort" QEMU-based approach to building multi-arch images is not possible in this case due to memory constraints with the free GitHub runners, so the changes in this PR rely on a 3rd-party integration with BuildJet to provide the native arm64 runner. BuildJet provides $5 of free runner time to get started, which equates to $5 / $0.008 = 625 minutes total with the runner I chose (see pricing info). Each build takes about 15 minutes, so I don't anticipate this project needing to spend any money whatsoever on this for the forseeable future. They also didn't collect credit card information from me when I signed up, so there's no danger of being accidentally charged.
  • Tests the image using the examples/nfldb.er diagram and stores the resulting PNG as an artifact for review.
  • Switches the base image to haskell:8-slim, which is about half the size of haskell:8 (341MB vs 635MB).

I appreciate that this reliance on a 3rd party is far from optimal and fully understand if the decision is made to reject this PR. The only two other viable approaches to build multi-archecture binaries would be to:

  • Set up a self-hosted arm64 runner.
  • Set up a GHC cross-compiler and run everything on the free GitHub amd64 runners. This is apparently quite complex to do with Haskell and beyond the effort I'm willing to contribute.

Closes #40
Closes #114

Hard-code tag for testing

Fix Docker image name

Attempt to build multi-arch image

Free up runner disk space and disable Docker parallelism

Attempt to build arm64 image only

Test build on BuildJet arm64 runner

Attempt to build images on native runners

Remove duplicate 'runs-on' key

Fix YAML syntax error

Check ghcr.io login first

Fix another YAML syntax issue

This better work...

Run build only on tags
@felixvanoost
Copy link
Contributor Author

@mmzx mentioning you in case GitHub doesn't send notifications for PRs. 😅

@felixvanoost felixvanoost force-pushed the build-multiarch-docker-image branch from ee1d784 to 0fdcdb8 Compare October 18, 2023 04:42
@mmzx
Copy link
Collaborator

mmzx commented Oct 24, 2023

I think we can do this! Thank you!

@mmzx mmzx merged commit 90ca649 into BurntSushi:master Oct 24, 2023
@felixvanoost felixvanoost deleted the build-multiarch-docker-image branch November 5, 2023 23:37
@felixvanoost
Copy link
Contributor Author

@mmzx Any idea when the next Erd release might be available to include these changes? I'm just looking for a rough idea when I can start integrating this in downstream projects. ✌🏻

@felixvanoost
Copy link
Contributor Author

@mmzx I noticed the CI build job failed after merging these changes. Adding this step at the beginning of the workflow should resolve the repository naming issue seen here:

- name: Make the image name lowercase
  run: |
    echo "IMAGE_NAME_LOWERCASE=${IMAGE_NAME,,}" >>${GITHUB_ENV}
  env:
    IMAGE_NAME: '${{ github.repository }}'

And then use IMAGE_NAME_LOWERCASE instead of IMAGE_NAME in the rest of the workflow. I can test these changes locally and submit another PR, but it's difficult to validate without directly testing in this repo. The solution above is taken from another GitHub discussion.

For the other job that failed on the BuildJet runner, you'll have to set up BuildJet on your account here. If this is an issue because @BurntSushi is the repo owner and it can only be done by him, I may have to build and publish the images in my fork instead.

@felixvanoost
Copy link
Contributor Author

Hey @mmzx, is this still something you'd be willing to look into?

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.

Publish arm container Build a statically linked binary
2 participants