Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Merge buildpack build environments #18

Merged
merged 2 commits into from

5 participants

Seth Fitzsimmons Ben Alavi Alessandro Tagliapietra Adrien Coquio David Dollar
Seth Fitzsimmons

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.

Seth Fitzsimmons

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

Ben Alavi

+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.

Seth Fitzsimmons mojodna referenced this pull request in heroku/heroku-buildpack-nodejs
Closed

Set $NPM_REBUILD to rebuild cached deps #84

Alessandro Tagliapietra

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

Adrien Coquio

:+1: This would help to solve #5

David Dollar
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.

David Dollar ddollar closed this
Seth Fitzsimmons

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.)

David Dollar ddollar reopened this
David Dollar ddollar merged commit ae76f29 into from
David Dollar
Owner

Thanks :)

Seth Fitzsimmons

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 0 deletions.
  1. +5 −0 bin/compile
5 bin/compile
View
@@ -51,6 +51,11 @@ for BUILDPACK in $(cat $1/.buildpacks); do
exit 1
fi
+ # check if the buildpack left behind an environment for subsequent ones
+ if [ -e $dir/export ]; then
+ source $dir/export
+ fi
+
if [ -x $dir/bin/release ]; then
$dir/bin/release $1 > $1/last_pack_release.out
fi
Something went wrong with that request. Please try again.