heroku / heroku-buildpack-go

Heroku Go Buildpack
https://devcenter.heroku.com/categories/go
MIT License
792 stars 511 forks source link

Support ARM64 when using Heroku-24 Docker images #557

Open edmorley opened 3 months ago

edmorley commented 3 months ago

Heroku itself currently runs on AMD64 CPUs, however, some users use our buildpacks locally on machines with ARM64 CPUs (such as M1/M2/M3 MacBooks) with the Heroku base images published to Docker Hub.

As such there have been requests to support the ARM64 architecture, e.g.: https://github.com/heroku/base-images/issues/194

Starting with Heroku-24, the base images published to Docker Hub are now multi-architecture (AMD64 + ARM64), and our preview Cloud Native Buildpacks support ARM64 when using Heroku-24.

However, until CNBs leave preview there will still be users using our classic buildpacks with our base images from Docker Hub, so it would be ideal if we could add ARM64 support to our classic buildpacks too. This will not only make the images faster to run locally, but also avoid breaking local development workflows if users update to Heroku-24 and miss the mention in the stack upgrade notes about using --platform linux/amd64 to force the architecture back to AMD64.

For example, the buildpack should support:

  1. git clone https://github.com/heroku/go-getting-started && cd go-getting-started
  2. Add a Dockerfile with the below contents.
  3. docker build --tag arm-test --platform linux/arm64 .
  4. docker run --rm -e PORT=5001 -p 5001:5001 arm-test
  5. curl localhost:5001
FROM heroku/heroku:24-build as build
ENV STACK=heroku-24
COPY --chown=heroku . /app
WORKDIR /app
# This is after the COPY line so buildpack updates are picked up.
RUN mkdir -p /tmp/buildpack /tmp/cache /tmp/env \
  && curl https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku/go.tgz \
    | tar -xz -C /tmp/buildpack
RUN /tmp/buildpack/bin/compile /app /tmp/cache /tmp/env

FROM heroku/heroku:24
COPY --from=build --chown=heroku /app /app
ENV HOME=/app
WORKDIR /app
CMD ["bash", "-c", "for f in .profile.d/*; do source \"${f}\"; done && go-getting-started"]

Currently when I try the above, I get this error (which is expected, since support for ARM64 hasn't yet been added):

$ docker build --tag arm-test --platform linux/arm64 .
...
 > [build 5/5] RUN /tmp/buildpack/bin/compile /app /tmp/cache /tmp/env:                                                     
0.082 -----> Fetching jq... done                                                                                            
1.685 -----> Fetching stdlib.sh.v8... done                                                                                  
2.283 ----->                                                                                                                
2.283        Detected go modules via go.mod                                                                                 
2.283 -----> 
2.285        Detected Module Name: github.com/heroku/go-getting-started
2.285 -----> 
2.319 -----> New Go Version, clearing old cache
2.319 -----> Installing go1.20.14
2.373 -----> Fetching go1.20.14.linux-amd64.tar.gz... done
10.53 rosetta error: failed to open elf at /lib64/ld-linux-x86-64.so.2
10.53  -----> Determining packages to install
10.53 rosetta error: failed to open elf at /lib64/ld-linux-x86-64.so.2

cc @joshwlewis