Skip to content
This repository was archived by the owner on Nov 13, 2020. It is now read-only.

Add ENV variables to customize buildpack #29

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Usage:
#
# $ bin/compile <build-dir> <cache-dir>
# $ bin/compile <build-dir> <cache-dir> <env-dir>


# Fail fast and fail hard.
Expand All @@ -16,6 +16,7 @@ BIN_DIR=$(cd $(dirname $0); pwd) # absolute path
ROOT_DIR=$(dirname $BIN_DIR)
BUILD_DIR=$1
CACHE_DIR=$2
ENV_DIR=$3

CACHED_DIRS=".heroku"

Expand All @@ -31,6 +32,7 @@ export BUILD_DIR CACHE_DIR BIN_DIR PROFILE_PATH
# Syntax sugar.
source $BIN_DIR/utils


# Directory Hacks for path consistiency.
APP_DIR='/app'
TMP_APP_DIR=$CACHE_DIR/tmp_app_dir
Expand Down Expand Up @@ -73,7 +75,11 @@ set -e
# Make profile.d directory.
mkdir -p $(dirname $PROFILE_PATH)

# Actuall do the conda steps.
# Add environment variables
export_env_dir $ENV_DIR


# Actually do the conda steps.
source $BIN_DIR/steps/conda_compile

# ### Finalize
Expand Down
24 changes: 19 additions & 5 deletions bin/steps/conda_compile
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,32 @@ fi

echo "nomkl" > $HOME/.heroku/miniconda/conda-meta/pinned
echo "added pinned file in $HOME/.heroku/miniconda/conda-meta/pinned"
conda install nomkl

if [ -n "${CONDA_CHANNELS}" ]; then
for channel in ${CONDA_CHANNELS}; do
puts-step "Add conda channel $channel"
conda config --add channels $channel
done
fi

conda install nomkl

if [ -f conda-requirements.txt ]; then
puts-step "Installing dependencies using Conda"
conda install --file conda-requirements.txt --yes | indent
puts-step "Looking for conda deps in ${CONDA_REQ_FILE:-conda-requirements.txt}"
if [ -f ${CONDA_REQ_FILE:-conda-requirements.txt} ]; then
puts-step "Installing dependencies using Conda form ${CONDA_REQ_FILE}"
conda install --file ${CONDA_REQ_FILE:-conda-requirements.txt} --yes | indent
fi

puts-step "Looking for deps in requirements.txt"
if [ -f requirements.txt ]; then
puts-step "Installing dependencies using Pip"
puts-step "Installing dependencies using Pip from requirements.txt"
pip install -r requirements.txt --exists-action=w --allow-all-external | indent
fi

if [ -f setup.py ]; then
puts-step "Installing setup.py using pip install -e ."
pip install --exists-action=w --allow-all-external -e . | indent
fi

# Clean up the installation environment .
conda clean -pt --yes > /dev/null
13 changes: 13 additions & 0 deletions bin/utils
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,16 @@ function deep-mv (){
rm -fr $1/!(tmp)
find -H $1 -maxdepth 1 -name '.*' -a \( -type d -o -type f -o -type l \) -exec rm -fr '{}' \;
}

export_env_dir() {
env_dir=$1
whitelist_regex=${2:-''}
blacklist_regex=${3:-'^(PATH|GIT_DIR|CPATH|CPPATH|LD_PRELOAD|LIBRARY_PATH|JAVA_OPTS)$'}
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
}