Giter VIP home page Giter VIP logo

heroku-buildpack-run's Introduction

Heroku Buildpack: Run

Run custom commands during the build process.

Description

This buildpack allows specifying custom scripts or other commands that will be run during the build process. If any command exits with a non-zero status code, the build is aborted.

Usage

Using the buildpack-run.sh script

By default, the buildpack looks for a script named buildpack-run.sh in the root directory of your app. So, you can do the following:

echo -e '#!/bin/bash\necho "Hello World"' >buildpack-run.sh
chmod +x buildpack-run.sh
git add buildpack-run.sh && git commit
git push heroku master

The above example will print Hello World during the build.

Using the BUILDPACK_RUN config variable

Alternatively to using buildpack-run.sh, you can specify custom commands in the BUILDPACK_RUN config variable:

heroku config:set BUILDPACK_RUN='echo "Hello World"

The above example will print Hello World during the build.

You can also specify multiple commands by separating them with colons:

heroku config:set BUILDPACK_RUN='echo "Hello World":uname -a:./myscript.sh foo bar

In the above example, the buildpack will execute the following commands in sequence:

  1. echo "Hello World"
  2. uname -a
  3. ./myscript.sh foo bar

Loading config variables

By default, the app's config variables are only available as files in a specific directory in the build environment (see ENV_DIR below). You can load all these config variables as environment variables by setting the BUILDPACK_RUN_LOAD_CONFIG config variable:

heroku config:set BUILDPACK_RUN_LOAD_CONFIG=1

Now, all the app's config variables will be available to your commands as environment variables.

If you want to prevent certain config variables from being loaded as environment variables (for example, to prevent overwriting native environment variables), you can specify them in the BUILDPACK_RUN_LOAD_CONFIG_SKIP config variable (separated by colons):

heroku config:set BUILDPACK_RUN_LOAD_CONFIG_SKIP=FOO:BAR:BAZ

In the above example, the config variables named FOO, BAR, and BAZ will not be loaded as environment variables. Note that this may be especially useful for config variables like PATH that you might not want to overwrite in the build environment.

Default environment variables

The following special environment variables are always available to your commands:

  • BUILD_DIR: your app's root directory in the build environment
  • CACHE_DIR: directory that persists between builds and can be used as a cache
  • ENV_DIR: directory containing the app's config variables as files

License

Licensed under the MIT License. See LICENSE.md file.

heroku-buildpack-run's People

Contributors

nelsonjchen avatar weibeld avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

heroku-buildpack-run's Issues

Custom script name

Would it be possible to configure the script name? For instance compile-assets.sh instead of buildpack-run.sh, which doesn't mean anything to me.
Not exactly sure how to configure this though: env variable?

Buildpack failing during Heroku build

The buildpack has stopped working (on Heroku) today, with the following error:

Running: ./buildpack-run.sh
/app/tmp/buildpacks/d4963cfdc610c1afed0921a93443e079284fcd2706707c8a33c3d1220c492dbfcb751a745f252dfc67a3828cf1f3cdd01d6bf5d0fc25fa0b511b62c391305643/bin/compile: line 61: ./buildpack-run.sh: Permission denied
-----> Aborting build because './buildpack-run.sh' exited with a non-zero code (126)

I'm using buildpack-run.sh to run custom commands. I've made several deploys to Heroku yesterday which all worked fine. I've not made any changes to buildpack-run.sh which makes me think that something in the commits on 9 Oct is responsible. The error message would indicate it's on line 61.

To illustrate the problem, even a buildpack-run.sh file with

#!/bin/sh

echo "-----> Run custom steps"

fails to build on Heroku (with the same error message).

Could we get an example of how to read Heroku config vars?

The documentation mentions ENV_DIR as a source for the Heroku environment. How does one use this?

It would make the package far more useful if all the Heroku environment variables were available in the runtime environment. This does not seem to be the case?

Thanks

Change folder permission

Hello.
I installed this buildpack and test the hello world (worked").
Put i need to execute chmod 777 -R Storage, to change my folder permisson.
the script executed successful, but after deployed, when I execute: heroku run "ls -la" to see the permissions, the permissions aren't set.

Can you help me?

Stop the build if a script fails

Hi,

Thank you very much for this useful tool!

My issue is that the buildpack doesn't abort the build if a script exits with a non-zero code. For example, a script could be downloading a vital file for your application. If it fails to download it, the script would exit with a non-zero exit code. The buildpack should stop the build to prevent deploying a partially built application. I believe this may be achieved simply by adding set -e at the beginning of /bin/compile, but I haven't verified this.

This is a duplicate of #2, but the issue was closed by the submitter, without any explanation.

Best regards,
Victor

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.