├── Readme.md └── bin ├── release ├── detect └── compile /Readme.md: -------------------------------------------------------------------------------- 1 | # Deprecated 2 | 3 | See 4 | - https://github.com/timanovsky/subdir-heroku-buildpack 5 | - https://github.com/lstoll/heroku-buildpack-monorepo 6 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /bin/detect: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ -z "$BUILDPACK" ]; then 4 | echo "Multipack looking for subdirectory" 5 | exit 0 6 | else 7 | echo "Missing BUILDPACK config var" 8 | exit 1 9 | fi 10 | -------------------------------------------------------------------------------- /bin/compile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | BUILD_DIR=${1:-} 6 | CACHE_DIR=${2:-} 7 | ENV_DIR=${3:-} 8 | BUILDPACK=$(cat $ENV_DIR/BUILDPACK) 9 | 10 | function indent() { 11 | c='s/^/ /' 12 | case $(uname) in 13 | Darwin) sed -l "$c";; 14 | *) sed -u "$c";; 15 | esac 16 | } 17 | 18 | unset GIT_DIR 19 | 20 | write_profile() { 21 | local root_dir="$1" 22 | # This assumes that Heroku initially looks for profiles at the $HOME folder, which it does 23 | local subdir="$2" 24 | mkdir -p $root_dir/.profile.d 25 | 26 | # Set the home directory to be the subdir and source all profiles that 27 | # were placed here by the invoked buildpack 28 | # The $HOME variable must be escaped, so that its value is resolved at runtime and not now. 29 | echo "export HOME=\"\$HOME/$subdir\" && source \"$subdir/.profile.d/\"*" > "$root_dir/.profile.d/heroku-subdir-init.sh" 30 | } 31 | 32 | 33 | # Looks for a buildpack argument with the format 34 | # subdir=https://github.com/my/buildpack.git 35 | execute_buildpack_at_subdir() { 36 | local buildpack="$1" 37 | dir=$(mktemp -t buildpackXXXXX) 38 | rm -rf $dir 39 | 40 | subdir="" 41 | if [[ $buildpack == *'='* ]]; then 42 | subdir=$(echo $buildpack | cut -d"=" -f 1) 43 | BUILDPACK=$(echo $buildpack | cut -d"=" -f 2) 44 | fi 45 | 46 | url=${BUILDPACK%#*} 47 | branch=${BUILDPACK#*#} 48 | 49 | if [ "$branch" == "$url" ]; then 50 | branch="" 51 | fi 52 | 53 | if [ "$url" != "" ]; then 54 | echo "=====> Downloading Buildpack: $url, branch: $branch, to tmp dir $dir, against source's subdir: $subdir" 55 | 56 | if [[ "$url" =~ \.tgz$ ]] || [[ "$url" =~ \.tgz\? ]]; then 57 | mkdir -p "$dir" 58 | curl -s "$url" | tar xvz -C "$dir" >/dev/null 2>&1 59 | else 60 | git clone $url $dir >/dev/null 2>&1 61 | if [ -f "$dir/.gitmodules" ]; then 62 | echo "=====> Detected git submodules. Initializing..." 63 | (cd $dir && git submodule update --init --recursive) 64 | fi 65 | fi 66 | cd $dir 67 | 68 | if [ "$branch" != "" ]; then 69 | git checkout $branch >/dev/null 2>&1 70 | fi 71 | 72 | # Ensure that these files exist. 73 | chmod -f +x $dir/bin/{detect,compile,release} || true 74 | 75 | framework=$($dir/bin/detect $BUILD_DIR/$subdir) 76 | 77 | if [ $? == 0 ]; then 78 | echo "=====> Detected Framework: $framework" 79 | # echo "-----> Compiling with BUILD_DIR: $1, SUB_DIR: $subdir" 80 | # echo "-----> Ls BUILD_DIR: $(ls -la $1)" 81 | # echo "-----> Ls \$3: $(ls -la $3)" 82 | # echo "-----> Ls \$2: $(ls -la $2)" 83 | # echo "-----> Ls SUB_DIR(\$1/\$subdir): $(ls -la $1/$subdir)" 84 | # bin/compile BUILD_DIR CACHE_DIR ENV_DIR 85 | $dir/bin/compile $BUILD_DIR/$subdir $CACHE_DIR $ENV_DIR 86 | 87 | if [ $? != 0 ]; then 88 | exit 1 89 | fi 90 | 91 | # check if the buildpack left behind an environment for subsequent ones 92 | if [ -e $dir/export ]; then 93 | source $dir/export 94 | fi 95 | 96 | if [ -x $dir/bin/release ]; then 97 | $dir/bin/release $BUILD_DIR/$subdir > $BUILD_DIR/$subdir/last_pack_release.out 98 | fi 99 | 100 | # Copies the Procfile from the subdir to the root directory 101 | echo 'Copying Procfile...' 102 | cp $BUILD_DIR/$subdir/Procfile $BUILD_DIR/ 103 | 104 | # Writes the profile file which initializes paths and sources 105 | # other profile files 106 | echo 'Creating .profile.d...' 107 | write_profile "$BUILD_DIR" "$subdir" 108 | else 109 | echo "Couldn't detect any framework for this buildpack. Exiting." 110 | exit 1 111 | fi 112 | fi 113 | } 114 | 115 | # BUILDPACK should be set as a Heroku config var 116 | execute_buildpack_at_subdir "$BUILDPACK" 117 | 118 | if [[ -e $BUILD_DIR/last_pack_release.out ]]; then 119 | echo "Using release configuration from last framework ($framework)." 120 | fi 121 | --------------------------------------------------------------------------------