Skip to content
This repository has been archived by the owner on Jun 30, 2019. It is now read-only.

Commit

Permalink
Export ENV_DIR variables into environment
Browse files Browse the repository at this point in the history
This way they can be used with collective.recipe.environment in `buildout.cfg`
files.
  • Loading branch information
zupo committed Apr 6, 2018
1 parent 15392e9 commit 791b06c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ branches:
- master

before_install:
- git clone https://github.com/kward/shunit2.git /tmp/shunit2
- git clone https://github.com/kward/shunit2.git /tmp/shunit2/src
- git clone https://github.com/heroku/heroku-buildpack-testrunner.git /tmp/testrunner

install: true
Expand All @@ -14,4 +14,4 @@ script: /tmp/testrunner/bin/run -c .

env:
global:
- SHUNIT_HOME="/tmp/shunit2/source/2.1"
- SHUNIT_HOME="/tmp/shunit2"
24 changes: 16 additions & 8 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ ENV_DIR=$3 # -> environment variables are stored as files inside here
# default to /app if not set
APP_DIR=${4:-/app}

# Export env vars from ENV_DIR to environment, so it's easier to access them
# Taken from https://devcenter.heroku.com/articles/buildpack-api
export_env_dir() {
env_dir=$1
whitelist_regex=${2:-''}
blacklist_regex=${3:-'^(PATH|GIT_DIR|CPATH|CPPATH|LD_PRELOAD|LIBRARY_PATH)$'}
if [ -d "$env_dir" ]; then
for e in $(ls $env_dir); do
echo "$e" | grep -E "$whitelist_regex" | grep -qvE "$blacklist_regex" &&
export "$e=$(cat $env_dir/$e)"
:
done
fi
}
export_env_dir "$ENV_DIR"

# make sure dirs exist
mkdir -p $CACHE_DIR

Expand All @@ -23,14 +39,6 @@ if [ ! -f "$BUILD_DIR/.heroku/python/bin/python" ]; then
exit 1
fi

# support for buildouts using collective.recipe.environment to set credentials
# for third party PyPI installations
if [ -f $ENV_DIR/PYPICLOUD_USERNAME ] && [ -f $ENV_DIR/PYPICLOUD_PASSWORD ]; then
echo "-----> Use PYPICloud"
export "PYPICLOUD_USERNAME=$(cat $ENV_DIR/PYPICLOUD_USERNAME)"
export "PYPICLOUD_PASSWORD=$(cat $ENV_DIR/PYPICLOUD_PASSWORD)"
fi

echo "-----> Use build cache"
if [ -d $CACHE_DIR/bin ]; then
echo "Get buildout results from the previous build" | indent
Expand Down
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These libraries are the minimum needed to bootstrap a buildout environment
# in current directory on Heroku. DO NOT put project dependencies here, they
# should be managed by buildout.
pip==9.0.1
setuptools==36.2.3
zc.buildout==2.9.3
# in current directory. DO NOT put project dependencies here, they should be
# managed by buildout.
pip==9.0.3
setuptools==38.7.0
zc.buildout==2.11.2
8 changes: 3 additions & 5 deletions test/compile_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ testCompile()
{
capture ${BUILDPACK_HOME}/bin/compile ${BUILD_DIR} ${CACHE_DIR} ${ENV_DIR} ${APP_DIR}
assertEquals 0 ${rtrn}
assertNotCaptured "-----> Use PYPICloud"
assertCaptured "Cache empty, start from scratch"
assertCaptured "Use default buildout.cfg"
assertCaptured "Use default buildout verbosity"
Expand All @@ -60,9 +59,9 @@ testCompile()
compileWithEnvVars()
{
#-* test compile with env vars set *-#
# set credentials for third party PyPI installations
echo "foo" > $ENV_DIR/PYPICLOUD_USERNAME
echo "bar" > $ENV_DIR/PYPICLOUD_PASSWORD
# set arbitrary env vars
echo "foo" > $ENV_DIR/FOO
echo "bar" > $ENV_DIR/BAR
# set BUILDOUT_CFG file
echo "buildout.cfg" > $ENV_DIR/BUILDOUT_CFG
# set Buildout verbosity
Expand All @@ -71,7 +70,6 @@ compileWithEnvVars()
capture ${BUILDPACK_HOME}/bin/compile ${BUILD_DIR} ${CACHE_DIR} ${ENV_DIR} ${APP_DIR}
assertEquals 0 ${rtrn}
assertCaptured "Get buildout results from the previous build" # cache worked
assertCaptured "-----> Use PYPICloud"
assertCaptured "Found ${BUILDOUT_CFG}"
assertCaptured "Use buildout verbosity: ${BUILDOUT_VERBOSITY}"
assertCaptured "Done"
Expand Down

0 comments on commit 791b06c

Please sign in to comment.