Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CNB_TARGET_ environment variables are not set when expected #1308

Closed
joshwlewis opened this issue Mar 1, 2024 · 1 comment · Fixed by #1309
Closed

CNB_TARGET_ environment variables are not set when expected #1308

joshwlewis opened this issue Mar 1, 2024 · 1 comment · Fixed by #1309
Labels
status/ready type/bug Something isn't working

Comments

@joshwlewis
Copy link
Member

joshwlewis commented Mar 1, 2024

Summary

In Buildpack API 0.10, it says:

The following environment variables MUST be set by the lifecycle during the detect and build phases to describe the target runtime image, if inputs are provided.

But lifecycle fails to provide these CNB_TARGET_* environment variables if the Platform API is less than 0.12:

if a.PlatformAPI.AtLeast("0.12") {
runImageName = a.RunImage.Name()
atm, err = platform.GetTargetMetadata(a.RunImage)
if err != nil {
return files.Analyzed{}, errors.Wrap(err, "unpacking metadata from image")
}
if atm.OS == "" {
platform.GetTargetOSFromFileSystem(&fsutil.Detect{}, atm, a.Logger)
}
}

This means that a buildpack using Buildpack API 0.10 running on a platform using Platform API 0.9 won't have CNB_TARGET_OS and CNB_TARGET_ARCH set, even though these should be set according to the Buildpack API.


Reproduction

Steps
  1. Use an older version of pack, like v0.27.0, that uses a Platform API version < 0.12
  2. Run pack build myapp --builder heroku/builder@sha256:5856c2e1f6c55ec5e289453b872f57f4ebe1a32a6da31f053cd27eddccbf21c5
  3. Observe that the build fails (some of the included buildpacks try to read CNB_TARGET_OS, which is not present)
  4. Use a newer version of pack that uses Platform API version >= 0.12
  5. Run pack build myapp --builder heroku/builder@sha256:5856c2e1f6c55ec5e289453b872f57f4ebe1a32a6da31f053cd27eddccbf21c5 again.
  6. Observe that the build doesn't error on missing environment variables.
Current behavior

Buildpacks using Buildpack API 0.10 may not receive CNB_TARGET_OS / CNB_TARGET_PLATFORM env vars when an older Platform API is in use.

Expected behavior

Buildpacks using Buildpack API 0.10 always receive CNB_TARGET_OS / CNB_TARGET_PLATFORM (regardless of Platform API version).


Context

lifecycle version

0.18.5 in my testing, but I think older versions are affected as well.

platform version(s)

Anything < 0.12.

anything else?
@natalieparellano
Copy link
Member

Related Slack conversation: https://cloud-native.slack.com/archives/C0333LG7C9J/p1709323194121239

We can fix this in 0.19

natalieparellano added a commit that referenced this issue Mar 4, 2024
when the Buildpack API version is at least 0.10.

Previously, we only set these variables when the Platform API version was at least 0.12.
But, newer Buildpack APIs expect these variables regardless of the Platform API version.
If we are on an older platform, derive the target variables from the base image OS.

Fixes #1308

Signed-off-by: Natalie Arellano <[email protected]>
natalieparellano added a commit that referenced this issue Mar 4, 2024
…1309)

* Always set CNB_TARGET_* variables during detect, build, and generate
when the Buildpack API version is at least 0.10.

Previously, we only set these variables when the Platform API version was at least 0.12.
But, newer Buildpack APIs expect these variables regardless of the Platform API version.
If we are on an older platform, derive the target variables from the base image OS.

Fixes #1308

Signed-off-by: Natalie Arellano <[email protected]>

* Fix unit

Signed-off-by: Natalie Arellano <[email protected]>

* Fix unit again

Signed-off-by: Natalie Arellano <[email protected]>

---------

Signed-off-by: Natalie Arellano <[email protected]>
edmorley added a commit to heroku/base-images that referenced this issue Mar 11, 2024
These were added recently in #251 to work around this upstream
`lifecycle` bug:
buildpacks/lifecycle#1308

The fix for that has since been released in lifecycle 0.19.0:
https://github.com/buildpacks/lifecycle/releases/tag/v0.19.0

Which our builder images are now using:
heroku/cnb-builder-images#475

As such, we no longer need the workaround here (and in fact, setting
these env vars now cannot have an effect, since `lifecycle` now ignores
them).
edmorley added a commit to heroku/base-images that referenced this issue Mar 11, 2024
These were added recently in #251 to work around this upstream
`lifecycle` bug:
buildpacks/lifecycle#1308

The fix for that has since been released in lifecycle 0.19.0:
https://github.com/buildpacks/lifecycle/releases/tag/v0.19.0

Which our builder images are now using:
heroku/cnb-builder-images#475

As such, we no longer need the workaround here (and in fact, setting
these env vars now cannot have an effect, since `lifecycle` now ignores
them).

GUS-W-15225541.
natalieparellano added a commit that referenced this issue Mar 12, 2024
when the Buildpack API version is at least 0.10.

Previously, we only set these variables when the Platform API version was at least 0.12.
But, newer Buildpack APIs expect these variables regardless of the Platform API version.
If we are on an older platform, derive the target variables from the base image OS.

Fixes #1308

Signed-off-by: Natalie Arellano <[email protected]>
natalieparellano added a commit that referenced this issue Mar 12, 2024
…1317)

when the Buildpack API version is at least 0.10.

Previously, we only set these variables when the Platform API version was at least 0.12.
But, newer Buildpack APIs expect these variables regardless of the Platform API version.
If we are on an older platform, derive the target variables from the base image OS.

Fixes #1308

Signed-off-by: Natalie Arellano <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/ready type/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants