Open edmorley opened 4 days ago
I think there might be two overlapping (or at least related) bugs here:
GetTargetOSFromFileSystem
only attempts to populate distro data and not OS/arch data: https://github.com/buildpacks/lifecycle/blob/f2a3bd78a819d433eeee7561ec81c02e840db476/platform/target_data.go#L100-L102 Also, I feel like lifecycle
should never be setting the CNB_TARGET_*
env vars to the empty string here:
https://github.com/buildpacks/lifecycle/blob/f2a3bd78a819d433eeee7561ec81c02e840db476/platform/target_data.go#L115-L119
Instead it should either:
As is, the fact they are set to the empty string, means we never hit the error case here in our libcnb.rs
framework:
https://github.com/heroku/libcnb.rs/blob/ed91ba6f9c14bf1c0305bfa72fd66d281538a99d/libcnb/src/runtime.rs#L364-L365
https://github.com/heroku/libcnb.rs/blob/ed91ba6f9c14bf1c0305bfa72fd66d281538a99d/libcnb/src/error.rs#L26-L30
...which would have made https://github.com/heroku/buildpacks-php/issues/121 easier to debug.
Summary
The Buildpack API v0.10 spec says that the
CNB_TARGET_ARCH
andCNB_TARGET_OS
env vars will always be set: https://github.com/buildpacks/spec/blob/buildpack/v0.10/buildpack.md#targetsHowever, this is not the case iff the Platform API is 0.9 or below, even if the buildpack is using Buildpack API 0.10, and the builder is using latest
lifecycle
(which has all the previous fixes for the targets related bugs).This scenario can occur when a user uses an outdated Pack CLI version that does not support Platform API 0.10, such as Pack CLI v0.27.0 which only supports Platform API <= 0.9.
This came up in: https://github.com/heroku/buildpacks-php/issues/121
If Buildpack API 0.10 isn't compatible with older Platform APIs, then
lifecycle
should exit with a suitable error message. Otherwise the Buildpack API 0.10 spec should be honoured.Reproduction
Steps
curl -fL https://github.com/buildpacks/pack/releases/download/v0.27.0/pack-v0.27.0-macos-arm64.tgz | tar -xz && mv ./pack ./pack-0.27.0
mkdir -p testcase/bin
echo -e 'api = "0.10"\n\n[buildpack]\nid = "testcase"\nversion = "0.0.1"\n\n[[stacks]]\nid = "*"' > testcase/buildpack.toml
echo -e '#!/usr/bin/env bash\n\nprintenv | grep CNB_TARGET | sort && exit 1' > testcase/bin/detect
./pack-0.27.0 build --builder heroku/builder:24 --trust-builder --buildpack testcase/ --path testcase/ testapp --verbose
Current behavior
When using Pack CLI 0.27.0 (which only supports Platform API <= 0.9), the
CNB_TARGET_ARCH
andCNB_TARGET_OS
env vars are not set correctly (they are set to the empty string, instead ofarm64
andlinux
respectively):Compare this to when latest Pack CLI is used, which supports Platform API 0.10:
Expected behavior
Either:
CNB_TARGET_ARCH
andCNB_TARGET_OS
correctly.Context
lifecycle version
platform version(s)