buildpacks / samples

Samples for Cloud Native Buildpacks
Apache License 2.0
194 stars 146 forks source link

Provide arm64 image of sample builder(s) #114

Open retgits opened 2 years ago

retgits commented 2 years ago

Problem

I tried running the Build an app example in the Buildpack docs, but hit an error while doing so. Any thoughts on how to troubleshoot would be greatly appreciated.

Steps to reproduce

Outcome / Stack trace

$ pack build sample-app --path samples/apps/java-maven --builder cnbs/sample-builder:bionic
bionic: Pulling from cnbs/sample-builder
e4ca327ec0e7: Already exists 
55fae2d3d3bc: Pull complete 
6faf60e5f26d: Pull complete 
3baf523e9da9: Pull complete 
22012278af40: Pull complete 
58b1e653474f: Pull complete 
357fefdf9bc9: Pull complete 
a697cc8a1d5c: Pull complete 
5c2e4179bee1: Pull complete 
c4e3bdcbb8c3: Pull complete 
04f9e5a54d38: Pull complete 
c238db6a02a5: Pull complete 
53a52c7f9926: Pull complete 
0cceee8a8cb0: Pull complete 
a302059dbdba: Pull complete 
db1bbcc47135: Pull complete 
4f4fb700ef54: Pull complete 
Digest: sha256:01b9067fe10704647b0992b56699a4e59431d1162e769706dcf5da5dfda928c8
Status: Downloaded newer image for cnbs/sample-builder:bionic
bionic: Pulling from cnbs/sample-stack-run
e4ca327ec0e7: Already exists 
55fae2d3d3bc: Already exists 
6faf60e5f26d: Already exists 
Digest: sha256:38f19fee4ffd8caafb5550da2d26687feba159528d041101ad99cc7390a0f578
Status: Downloaded newer image for cnbs/sample-stack-run:bionic
0.11.3: Pulling from buildpacksio/lifecycle
5dea5ec2316d: Pull complete 
6d75e71a489d: Pull complete 
Digest: sha256:d6c578fbdf88f2e2594d9907307b17775e648656f62e1ae810d31c804f928cf9
Status: Downloaded newer image for buildpacksio/lifecycle:0.11.3
===> DETECTING
[detector] samples/java-maven 0.0.1
===> ANALYZING
[analyzer] Previous image with name "sample-app" not found
===> RESTORING
===> BUILDING
[builder] ---> Java buildpack
[builder] ---> Installing JDK
[builder] ---> Running Maven Wrapper
[builder] qemu: uncaught target signal 11 (Segmentation fault) - core dumped
[builder] /cnb/buildpacks/samples_java-maven/0.0.1/bin/build: line 116:    60 Segmentation fault      ./mvnw clean install -B -DskipTests
[builder] ERROR: failed to build: exit status 139
ERROR: failed to build: executing lifecycle. This may be the result of using an untrusted builder: failed with status code: 51

Environment

jromero commented 2 years ago

FWIW, this would be an issue with qemu, see https://github.com/docker/for-mac/issues/5123#issuecomment-784992589.

What we can do, and would need to test, is create an arm64 sample builder image. Marking this as a feature request and updating the title.

odidev commented 1 year ago

Hi Team, I am also interested in Linux/ARM64 support for the cnbs docker images. Do you have any plans to roll out the official Linux/ARM64 docker images soon?

natalieparellano commented 1 year ago

cc @AidanDelaney

I am not on the learning team, but my sense is that we could use some helping hands from folks willing to push this forward incrementally. If anyone would be interested in getting involved, I'd be happy to provide support based on my experience contributing to this repository.

odidev commented 1 year ago

Thank you for the response.

The cnbs images are built and pushed to dockerhub via the Makefile. It seems like we cannot create multi-arch docker images using pack. Pack can build native images for both Linux/AMD64 and Linux/ARM64 separately. So, to build and release images for ARM64 (image names different for amd64 and arm64), Makefile needs to be reframed with platform-specific checks to build and push images for separate platforms (AMD64 and ARM64) and then other files using these images also need to be reframed with platform-specific checks to work for both the platforms. Also, GitHub Actions config files will use self-hosted runners to support the build and push for Linux/ARM64 images.

May I know, is there a way we can build multi-arch images using pack? Or else, IMO, the above requires a lot of changes in the source code in multiple files.

Kindly provide your suggestions on the same.

odidev commented 1 year ago

Continuing with my previous comment, to create the application image for “myapp”, I tried creating the builder image “sample-builder:bionic” natively for Linux/ARM64. However, “myapp” failed with the following logs:

$ pack build myapp --builder sample-builder:bionic 

0.14.1: Pulling from buildpacksio/lifecycle 
Digest: sha256:56019ba74831e3444f33ee8c0201f18cc300213bac353b8b6a79c7a1669b7a49 
Status: Image is up to date for buildpacksio/lifecycle:0.14.1 
===> ANALYZING 
[analyzer] Previous image with name "myapp" not found 
===> DETECTING 
[detector] exec /cnb/lifecycle/detector: exec format error 

Below are the changes I did in the source code for Linux/ARM64:

Then, I built the sample-builder:bionic via make as below:

$ make build-linux-stacks build-linux-packages build-linux-builders 

Do you have any suggestions on the same?

natalieparellano commented 1 year ago

@odidev thank you for looking into this! You are right that we can't create cross-platform builders with pack today; this issue (https://github.com/buildpacks/pack/issues/1459) would change that, but is awaiting someone to take it up.

Regarding the error mentioned above - can you check if the lifecycle in the builder is compiled for arm? The error is either coming from the lifecycle or the buildpack, so we need to ensure both are able to run on arm architecture. I see that the analyzer ran fine, but pack might have been using the "lifecycle image" for that step so we need to confirm what was actually on the builder itself.

AidanDelaney commented 1 year ago

Only the very latest lifecycle has fixes to pick up arm64 builders. We would love some help with https://github.com/buildpacks/docs/issues/533 :)

odidev commented 1 year ago

I followed this document < https://buildpacks.io/docs/app-developer-guide/build-an-arm-app/ > to build the application image on Arm directly by invoking the lifecycle image, and successfully created the application container.

Also, I followed this document: < https://github.com/dmikusa/paketo-arm64#readme > in paketo-arm64 repo to natively build the builder image for Arm and created the application container bound to port 8080. I can curl localhost:8080 successfully.

$ curl -s http://localhost:8080/actuator/health | jq . 

{ 
  "status": "UP" 
} 
AidanDelaney commented 1 year ago

@odidev Congratulations on becoming an innovator in the multi-architecture buildpacks space :) If you have the time it would be great to see you in our regular Thursday meetings (https://buildpacks.io/community/). We would appreciate your perspective.

AidanDelaney commented 9 months ago

This is a longer term goal for us. We're now in a position that it should work, i.e. we've made all the necessary changes to pack. Keeping this open.