Merge buildpack build environments #18

Merged
merged 2 commits into from Nov 7, 2014

5 participants

@mojodna

This is very similar to #11, although it merges responsibility from after_compile into compile to avoid having to hardcode paths.

I don't like the idea of dropping build_env.sh in the app's root directory (which is also where last_pack_release.out lands), but I'm not sure what a better location for communication would be...

Like @davidjrice, I have a buildpack that's just responsible for vendoring dependencies. My vendor function looks like:

function vendor() {
  binary="$1"
  path="$2"

  echo "Fetching $binary" | indent
  mkdir -p $path
  curl $binary -s -o - | tar xz -C $path -f -

  [ -d "$path/bin" ] && export PATH=$path/bin:$PATH
  export CPPPATH="$path/include:$CPPPATH"
  export CPATH="$path/include:$CPATH"
  export LIBRARY_PATH="$path/lib:$LIBRARY_PATH"
  export LD_LIBRARY_PATH="$path/lib:$LD_LIBRARY_PATH"
  [ -d "$path/lib/pkgconfig" ] && export PKG_CONFIG_PATH="$path/lib/pkgconfig:$PKG_CONFIG_PATH"

  true
}

...and is used like so:

vendor "https://s3.amazonaws.com/<bucket>/protobuf-2.5.0-1.tar.gz" "$1/vendor/protobuf"

This way vendor builds up the environment and creates a file in .profile.d (re-pointing to /app) via:

cat <<EOF > $BUILD_DIR/.profile.d/deps.sh
# build and runtime paths
export PATH="${PATH//$BUILD_DIR//app}:\$PATH"
export LD_LIBRARY_PATH="\$LD_LIBRARY_PATH:${LD_LIBRARY_PATH//$BUILD_DIR//app}"
export LIBRARY_PATH="\$LIBRARY_PATH:${LIBRARY_PATH//$BUILD_DIR//app}"
export PKG_CONFIG_PATH="\$PKG_CONFIG_PATH:${PKG_CONFIG_PATH//$BUILD_DIR//app}"
export CPPPATH="\$CPPPATH:${CPPPATH//$BUILD_DIR//app}"
export CPATH="\$CPATH:${CPATH//$BUILD_DIR//app}"
EOF

It writes out $BUILD_DIR/build_env.sh via:

cat <<EOF > $BUILD_DIR/build_env.sh
export PATH="$PATH:\$PATH"
export LD_LIBRARY_PATH="\$LD_LIBRARY_PATH\":$LD_LIBRARY_PATH"
export LIBRARY_PATH="\$LIBRARY_PATH\":$LIBRARY_PATH"
export PKG_CONFIG_PATH="\$PKG_CONFIG_PATH\":$PKG_CONFIG_PATH"
export CPPPATH="\$CPPPATH\":$CPPPATH"
export CPATH="\$CPATH\":$CPATH"
EOF

...which is then picked up by the multipack's compile.

@mojodna

b49c7aa changes $BUILD_DIR/build_env.sh to $dir/export to avoid polluting the app being deployed.

@benalavi

+1 -- FWIW I ran into this issue because I use a rubygem that builds a native extension, so I wrote a buildpack to install the necessary libraries and used multi to run it before heroku's ruby buildpack installs the gems. Without this change it fails because the library buildpack can't set the load paths for the ruby buildpack (basically the same issue). It seems like a general-enough use case for composing buildpacks.

@mojodna mojodna referenced this pull request in heroku/heroku-buildpack-nodejs Feb 15, 2014
Closed

Set $NPM_REBUILD to rebuild cached deps #84

@alex88

👍 I totally need this! I've to set PKG_CONFIG_PATH into the ruby buildpack to install ruby-vips native gem

@bobbus

👍 This would help to solve #5

@ddollar
Owner

Hello. I apologize for not responding earlier but I am currently declaring Github bankruptcy. If this pull request or issue is still valid please feel free to re-open and explain.

@ddollar ddollar closed this Nov 7, 2014
@mojodna

I have several buildpacks that are just responsible for vendoring dependencies that may be used during the build stage of other buildpacks (https://github.com/mojodna/heroku-buildpack-cairo is the main one). Without this patch, there's no way to communicate to subsequent buildpacks appropriate values for INCLUDE_PATH, CPATH, etc.

(Consider this me re-opening this PR, despite the button not being available.)

@ddollar ddollar reopened this Nov 7, 2014
@ddollar ddollar merged commit ae76f29 into ddollar:master Nov 7, 2014
@ddollar
Owner

Thanks :)

@mojodna

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment