buildpacks / lifecycle

Reference implementation of the Cloud Native Buildpacks lifecycle
https://buildpacks.io
Apache License 2.0
185 stars 103 forks source link

UX: Call out ordering of buildpacks when failing detection #1366

Open schneems opened 1 week ago

schneems commented 1 week ago

Summary

The build plan output when passing it two buildpacks does not make it clear that order can be a problem


Reproduction

Steps
$ mkdir -p /tmp/f24a08bca473d7a34ed391f4b8c76d12; cd /tmp/f24a08bca473d7a34ed391f4b8c76d12
$ git clone https://github.com/heroku/ruby-getting-started
$ git clone https://github.com/heroku/buildpacks-ruby
$ cd buildpacks-ruby
$ git checkout aaa72f317ee7b4700de35ea27112c1ad15334def

Follow steps to install https://github.com/heroku/buildpacks-ruby/blob/aaa72f317ee7b4700de35ea27112c1ad15334def/CONTRIBUTING.md#development

$ cargo libcnb package
# ...
$ pack build mon-jun-17 --buildpack packaged/x86_64-unknown-linux-musl/debug/heroku_ruby --path /tmp/f24a08bca473d7a34ed391f4b8c76d12/ruby-getting-started --builder heroku/builder:24 --buildpack heroku/nodejs-engine
Current behavior

When I run that command, I get a failure

$ pack build mon-jun-17 --buildpack packaged/x86_64-unknown-linux-musl/debug/heroku_ruby --path /tmp/f24a08bca473d7a34ed391f4b8c76d12/ruby-getting-started --builder heroku/builder:24 --buildpack heroku/nodejs-engine
24: Pulling from heroku/builder
Digest: sha256:ebbea500fc0f86924edac9f3bf6cb48426308ea2f8413bd25a12bc40db46c57e
Status: Image is up to date for heroku/builder:24
24: Pulling from heroku/heroku
Digest: sha256:09851f0d8c298913aa8e441c9139d5645d281b120525379430013317bcc253db
Status: Image is up to date for heroku/heroku:24
===> ANALYZING
Image with name "mon-jun-17" not found
===> DETECTING
======== Results ========
pass: heroku/ruby@3.0.0
pass: heroku/nodejs-engine@3.2.4
Resolving plan... (try buildpacks/pack#1)
fail: heroku/ruby@3.0.0 requires node
Resolving plan... (try buildpacks/pack#2)
fail: heroku/ruby@3.0.0 requires node
ERROR: No buildpack groups passed detection.
ERROR: Please check that you are running against the correct path.
ERROR: failed to detect: no buildpacks participating
ERROR: failed to build: executing lifecycle: failed with status code: 20

Which, was odd because heroku/nodejs-engine provides node and you can see from the output that it passes detection.

The issue turned out to be the order of the buildpacks was incorrect, it should have been using Node first:

$ pack build mon-jun-17 --path /tmp/f24a08bca473d7a34ed391f4b8c76d12/ruby-getting-started --builder heroku/builder:24 --buildpack heroku/nodejs-engine --buildpack packaged/x86_64-unknown-linux-musl/debug/heroku_ruby/
Expected behavior

I expect that minor mistakes in a build plan (from package.toml or passed in via CLI) are highlighted by the failure output. Ideally I would get a message like:

The heroku/ruby@<version>` buildpack depends on "node" which is provided by `heroku/nodejs@<version>`, however `heroku/nodejs@<version>` will not execute until after `heroku/ruby@<version>`. Consider re-ordering which buildpack comes first.

Environment

pack info
$ pack report
Pack:
  Version:  0.34.2+git-ce8db3c.build-6005
  OS/Arch:  darwin/arm64

Default Lifecycle Version:  0.19.6

Supported Platform APIs:  0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.10, 0.11, 0.12, 0.13

Config:
  default-builder-image = "[REDACTED]"
docker info
$ docker info
Client:
 Version:    26.1.1
 Context:    desktop-linux
# ...
natalieparellano commented 1 week ago

We should probably move this issue over to the lifecycle. It might be hard to give such a detailed error message, but we could append something like "check the provided order to ensure that buildpacks providing dependencies run before the buildpacks that require them"

jjbustamante commented 1 week ago

Yes, I was thinking about how to get such detailed information without doing a lot of work, but I am not sure if it is possible. I like the idea, but the implementation is not straight forward