Skip to content

Make (certain) environment variables available at build time #63

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ RUST_CARGO_BUILD_FLAGS="--release -p some_package --bin some_exe --bin some_bin_
The default value of `RUST_CARGO_BUILD_FLAGS` is `--release`.
If the variable is not set in `RustConfig`, the default value will be used to build the project.

## Set variables to use during build

If you want to set variables that are needed at build time, prefix the variable with ```BUILDVAR_``` when adding to Heroku Config Vars.

```sh
$ heroku config:set BUILDVAR_API_KEY=myapikey
```

## Using the edge version of the buildpack

The `emk/rust` buildpack from the [Heroku Registry](https://devcenter.heroku.com/articles/buildpack-registry) contains the latest stable version of the buildpack. If you'd like to use the latest buildpack code from this Github repository, you can set your buildpack to the Github URL:
Expand Down
15 changes: 15 additions & 0 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ if [ -e "$ENV_DIR/DATABASE_URL" ]; then
export DATABASE_URL="$(cat $ENV_DIR/DATABASE_URL)";
fi

## Export BUILDVAR_ variables at build time.
## Useful in cases where application sets variables at build time.
## E.g. static API_KEY: &str = env!("BUILDVAR_API_KEY");
if ls "$ENV_DIR" 2>/dev/null | grep -q -e ^BUILDVAR_; then
echo "-----> Found BUILDVAR_ variable(s)"
for BUILDVAR in $(ls "$ENV_DIR" | grep -e ^BUILDVAR_); do
VAR_KEY=$BUILDVAR
VAR_VALUE=$(cat $ENV_DIR/$BUILDVAR)
echo "-----> Exporting $VAR_KEY"
export "$VAR_KEY=$VAR_VALUE"
done
else
echo "-----> Found no BUILDVAR_ variable"
fi

# Set defaults for our configuration variables. Stable Rust is sufficiently
# stable at this point that I think we can just default it.
VERSION=stable
Expand Down