├── bin ├── detect ├── release └── compile └── readme.md /bin/detect: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ -f $1/.buildpacks ]; then 4 | echo "Multipack" 5 | exit 0 6 | else 7 | echo "Missing .buildpacks file" 8 | exit 1 9 | fi 10 | -------------------------------------------------------------------------------- /bin/release: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ -e $1/last_pack_release.out ]; then 4 | cat $1/last_pack_release.out 5 | rm $1/last_pack_release.out 6 | else 7 | echo "--- {}" 8 | fi 9 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Heroku Buildpack Subdir 2 | 3 | Allows you to compose multiple buildpacks with apps in multiple directories. For information regarding adding multiple buildpacks, check out the official docs [here](https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app#adding-a-buildpack). 4 | 5 | This buildpack must be at index 1 and all buildpacks following should be at index 2 through N. 6 | 7 | ## Usage 8 | 9 | $ heroku buildpacks:set https://github.com/negativetwelve/heroku-buildpack-subdir 10 | 11 | Example `.buildpacks` file: 12 | 13 | $ cat .buildpacks 14 | api=https://github.com/heroku/heroku-buildpack-ruby.git 15 | web=https://github.com/heroku/heroku-buildpack-nodejs.git 16 | https://github.com/heroku/heroku-buildpack-go 17 | 18 | This would run: 19 | 20 | * The first buildpack would `cd` into an `api` directory and use a `ruby` buildpack. 21 | * The second would `cd` into a `web` directory and use a `node.js` buildpack. 22 | * The third would be in the root directory and use a `go` buildpack. 23 | 24 | ## License 25 | 26 | MIT 27 | -------------------------------------------------------------------------------- /bin/compile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | function indent() { 6 | c='s/^/ /' 7 | case $(uname) in 8 | Darwin) sed -l "$c";; 9 | *) sed -u "$c";; 10 | esac 11 | } 12 | 13 | unset GIT_DIR 14 | 15 | for BUILDPACK in $(cat $1/.buildpacks); do 16 | dir=$(mktemp -t buildpackXXXXX) 17 | rm -rf $dir 18 | 19 | subdir="" 20 | if [[ $BUILDPACK == *'='* ]]; then 21 | subdir=$(echo $BUILDPACK | cut -d"=" -f 1) 22 | BUILDPACK=$(echo $BUILDPACK | cut -d"=" -f 2) 23 | fi 24 | 25 | url=${BUILDPACK%#*} 26 | branch=${BUILDPACK#*#} 27 | 28 | if [ "$branch" == "$url" ]; then 29 | branch="" 30 | fi 31 | 32 | if [ "$url" != "" ]; then 33 | echo "=====> Downloading Buildpack: $url, branch: $branch, to tmp dir $dir, against source's subdir: $subdir" 34 | 35 | if [[ "$url" =~ \.tgz$ ]] || [[ "$url" =~ \.tgz\? ]]; then 36 | mkdir -p "$dir" 37 | curl -s "$url" | tar xvz -C "$dir" >/dev/null 2>&1 38 | else 39 | git clone $url $dir >/dev/null 2>&1 40 | if [ -f "$dir/.gitmodules" ]; then 41 | echo "=====> Detected git submodules. Initializing..." 42 | (cd $dir && git submodule update --init --recursive) 43 | fi 44 | fi 45 | cd $dir 46 | 47 | if [ "$branch" != "" ]; then 48 | git checkout $branch >/dev/null 2>&1 49 | fi 50 | 51 | # Ensure that these files exist. 52 | chmod -f +x $dir/bin/{detect,compile,release} || true 53 | 54 | framework=$($dir/bin/detect $1/$subdir) 55 | 56 | if [ $? == 0 ]; then 57 | echo "=====> Detected Framework: $framework" 58 | # echo "-----> Compiling with BUILD_DIR: $1, SUB_DIR: $subdir" 59 | # echo "-----> Ls BUILD_DIR: $(ls -la $1)" 60 | # echo "-----> Ls \$3: $(ls -la $3)" 61 | # echo "-----> Ls \$2: $(ls -la $2)" 62 | # echo "-----> Ls SUB_DIR(\$1/\$subdir): $(ls -la $1/$subdir)" 63 | # bin/compile BUILD_DIR CACHE_DIR ENV_DIR 64 | $dir/bin/compile $1/$subdir $2/services/$subdir $3 65 | 66 | if [ $? != 0 ]; then 67 | exit 1 68 | fi 69 | 70 | # check if the buildpack left behind an environment for subsequent ones 71 | if [ -e $dir/export ]; then 72 | source $dir/export 73 | fi 74 | 75 | if [ ! -z $subdir ]; then 76 | # check if the buildpack left any executables behind 77 | if [ -d $1/$subdir/.heroku ]; then 78 | mkdir -p $1/.heroku 79 | cp -R $1/$subdir/.heroku/* $1/.heroku 80 | fi 81 | 82 | # check if the buildpack left any .profile.d scripts behind 83 | if [ -d $1/$subdir/.profile.d ]; then 84 | mkdir -p $1/.profile.d 85 | cp -R $1/$subdir/.profile.d/* $1/.profile.d 86 | fi 87 | fi 88 | 89 | if [ -x $dir/bin/release ]; then 90 | $dir/bin/release $1/$subdir > $1/$subdir/last_pack_release.out 91 | fi 92 | else 93 | echo "Couldn't detect any framework for this buildpack. Exiting." 94 | exit 1 95 | fi 96 | fi 97 | done 98 | 99 | if [[ -e $1/last_pack_release.out ]]; then 100 | echo "Using release configuration from last framework ($framework)." 101 | fi 102 | --------------------------------------------------------------------------------