using `set_default_env` in a post_compile script
Not sure if this is the right place to write this. Please let me know if not.
I used to be able to run set_default_env in a post_compile script:
source $BIN_DIR/utils
set_default_env ENV_VAR default_value
I was using v238 at the time.
Now this is no longer possible – $BIN_DIR no longer exists.
Just copying the function fails as $PROFILE_PATH is not present in the env where the post_compile script is run.
Is there another way to use the function?
My use case:
I am using review apps. I currently use my post compile script to do the following:
- Check if it's a review app
- Create a new database for the review app in an AWS RDS using a pre-seeded template database
- Use
set_default_envto set the DATABASE_URL config var to point to this new database
I am also using it to set up a stripe webhook per review app and then store the webhook secret as a config variable.
Thanks
@guybowden Hi!
I'd recommend writing the profile file directly - the buildpack's own scripts are considered an internal implementation detail and not part of the public API. Also, I would recommend using a separate profile script instead of writing into the file created by this buildpack (.profile.d/python.sh is considered owned by this buildpack and not really meant for modification by anything else).
eg use:
#!/usr/bin/env bash
set -euo pipefail
mkdir -p .profile.d/
echo "DATABASE_URL='...'" > .profile.d/rds_database_config.sh
(The behaviour here changed as of #1595, which intentionally stopped some env vars leaking into subprocesses: https://github.com/heroku/heroku-buildpack-python/blob/main/CHANGELOG.md#v252---2024-06-17)
The docs for .profile.d/ are here, in case it helps :-)
https://devcenter.heroku.com/articles/buildpack-api#profile-d-scripts
Thankyou @edmorley
Closing since this is answered, but feel free to comment if you have any more questions :-)