Closed edmorley closed 4 months ago
Thanks for finding all of these bugs @edmorley - we can fix this in the next patch
I wonder whether lifecycle
should emit a warning (or at least info message) if it's having to use the /etc/os-release
fallback to find out the distro name/version? It seems like it would be best to let base image authors know there is an optimisation they haven't made to their images (ie: adding the labels to allow skipping the /etc/os-release
invocation).
IMO ideally at some point in a future spec release (once more people have made the the stacks -> targets migration) setting all the base image io.buildpacks.base.*
labels would be changed from a SHOULD
to a MUST
, allowing the fallback to be removed entirely. Having a warning in the meantime would help with that goal.
Summary
The Platform API 0.12 spec says:
(https://github.com/buildpacks/spec/blob/platform/0.12/platform.md#analyzedtoml-toml)
As such
lifecycle
has an implementation for this: https://github.com/buildpacks/lifecycle/blob/feb0d757c9bc16b85f19cb07c80dc28f0bdd8504/platform/target_data.go#L66-L81However, it seems this implementation never actually gets used in practice since it's behind a
if tm.OS == ""
conditional, andOS
is always available, so the/etc/os-release
fallback isn't used even if other properties about the target (such as the distro name and version) are not available: https://github.com/buildpacks/lifecycle/blob/feb0d757c9bc16b85f19cb07c80dc28f0bdd8504/platform/target_data.go#L15-L19 (Also, why does that code comment say build image - surely it should be analysing the run image?)This means that for any run images where the
io.buildpacks.base.distro.*
Docker labels haven't been set (which is any run image that hasn't yet made the transition from stacks to targets), theCNB_TARGET_DISTRO_NAME
andCNB_TARGET_DISTRO_VERSION
env vars are correctly set in the buildpack environment.This can be seen by using one of our older run images from before we added the relevant Docker labels - by passing
--run-image heroku/heroku:22-cnb.v122
topack build
.Reproduction
Steps
pack buildpack new testcase-targets --api 0.10 --targets "linux/amd64"
sed -i 's/exit 0/printenv | grep CNB_TARGET | sort/' testcase-targets/bin/build
pack build --builder heroku/builder:22 --run-image heroku/heroku:22-cnb.v122 --buildpack testcase-targets/ --path testcase-targets/ testcase-targets --verbose
Current behavior
The
CNB_TARGET_DISTRO_NAME
andCNB_TARGET_DISTRO_VERSION
env vars are not set correctly in the buildpack env:Expected behavior
For the
CNB_TARGET_DISTRO_*
env vars to be set based on the contents of/etc/os-release
, ie:...given that
/etc/os-release
exists and has the necessaryID
andVERSION_ID
values:Context
lifecycle version
0.19.3
platform version(s)
The build is using Platform API 0.12 and Buildpack API 0.10.