-
Notifications
You must be signed in to change notification settings - Fork 10
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
Set $HOME
to $CNB_APP_DIR
when running .profile.d/
scripts at launch
#23
Conversation
@edmorley may have more thoughts here as well. See issue buildpacks/spec#186. |
This suggestion around runtime env vars was posted a few days ago: buildpacks/community#61. It might be helpful in this context by removing this responsibility from cnb-shim. |
…scripts See: heroku#23 Squashed commit of the following: commit 1c3d01d Author: Kamal Nasser <[email protected]> Date: Tue Feb 2 00:42:02 2021 +0200 set HOME env to app dir at runtime for profile.d scripts
Recently I've been exploring changing the build directory used for standard (non-CI) Heroku builds, from a path like As part of that work, it's become apparent that we should absolutely not have As such, it's likely I'll be needing to change the build time value of It would cause a significant amount of breakage to also try and change the runtime value for As such I wonder if |
Yeah, I think that sounds like a good option given the additional context. What the subdir buildpack does should work here too. And since we're modifying the profile scripts we might as well use |
Awesome. Thanks again for putting this together. |
06da1b2
to
49486fe
Compare
@hone I've made some changes to be more in line with the suggested approach. Let me know what you think! I haven't yet tested them with an actual buildpack but I did add a test to validate overall functionality.
|
905191b
to
90a8db8
Compare
Required now that we have the EOL warning/error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR and sorry for the delay in coming back to this!
As part of adding the upcoming Heroku-24 stack, we audited the current Heroku-20/22 CNB base image variants to try and bring them closer in line with the spec and/or what other providers are using for their base images. One of the changes made as a result, was to drop the somewhat hacky overriding of HOME
to a fixed value of /app
.
As such, longer term I'd also like to backport this HOME
hack removal to our Heroku-20/22 CNB base image variants, since our non-shimmed builders (heroku/builder:20
and heroku/builder:22
use the same base images, and are therefore currently exposed to this hack, and will end up being inconsistent with heroku/builder:24
).
However, before we could think about making that change, we'd need cnb-shim
to set HOME
to a value that still works for the shimmed buildpacks, which this PR does. (IMO this PR is what should have landed in the first place rather than setting HOME=/app
in the base images themselves back in the early proof of concept days.)
As such, even though cnb-shim is EOL (and doesn't work with our modern builders, so we're not really investing in the tool for now), I'm going to merge/release this change now - before we stop building our legacy builders (at which point they won't pick up any cnb-shim changes) to unblock that potential base image cleanup in the future.
I've tested this PR using the legacy builder images smoke tests - by editing the builder.toml
configs to use the Review App URL instead of the main cnb-shim
app's URL - and all tests pass:
https://github.com/heroku/cnb-builder-images/actions/runs/8753865189
Plus ran another test run emulating what would happen when we eventually stop overriding HOME
in the run images (this CI run uses a custom run image that restores HOME
to its correct value) - and all tests pass here too:
https://github.com/heroku/cnb-builder-images/actions/runs/8754431732
As such, I'm happy to merge/release this -- I've rebased on main
to resolve conflicts, added ALLOW_EOL_SHIMMED_BUILDER=1
to the test so it passes now that #90 has landed, and made a couple of style/quoting tweaks, but otherwise everything else is the same and looks great - thank you :-)
$HOME
to $CNB_APP_DIR
when running .profile.d/
scripts at launch
Some buildpacks (such as heroku-buildpack-php) use
profile.d
scripts to set up the runtime environment. The expectation is that the app source code is located at$HOME
.Usually this can be addressed by building the stack run image in a way that sets
HOME
to the same path asCNB_APP_DIR
, but this won't work ifCNB_APP_DIR
is determined during build time.This configuresHOME
usingenv.launch
on theprofile.d
cnb-shim layer. There doesn't seem to be a way for exporter to set custom env vars on the OCI image itself.Edit: After review this PR now uses approach (2) below instead.
Other approaches:
profile.d
script that setsHOME
to$(pwd)
instead of relying on the fact thatCNB_APP_DIR
is consistent at build and run time, but that would be more complicated because we would need to ensure that it is run before otherprofile.d
scripts.profile.d
script from the shimmed buildpack and add anexport HOME=$(PWD)
line at the top of the file.