mirror of
https://github.com/kennethreitz/heroku-buildpack-python.git
synced 2026-06-05 23:10:16 +00:00
47c40ce086
commit 60a2a9d0720693b9438b0f1c75f570dc96bf3a4b Author: Kenneth Reitz <me@kennethreitz.com> Date: Fri Aug 1 14:58:29 2014 -0400 silent mode commit 20368e741993a2c96739aa1de457618a5272bfe7 Author: Kenneth Reitz <me@kennethreitz.com> Date: Fri Aug 1 14:56:00 2014 -0400 pylibmc commit 8a512995d806ad58e4a8cab9cd712e762277dcf3 Author: Kenneth Reitz <me@kennethreitz.com> Date: Fri Aug 1 14:55:25 2014 -0400 fix for pip-grep commit 0b83a0ac11ee67f08dc843b01ecfe72c9b9c2938 Author: Kenneth Reitz <me@kennethreitz.com> Date: Fri Aug 1 14:50:35 2014 -0400 cat that shit commit 27095d320f4e6c0a6bccec945efbdb6f09598cfc Author: Kenneth Reitz <me@kennethreitz.com> Date: Fri Aug 1 14:49:11 2014 -0400 don't silence the output commit db15ac279169467e1e78cfcc55cb740660d4b4c9 Author: Kenneth Reitz <me@kennethreitz.com> Date: Fri Aug 1 14:46:55 2014 -0400 hello commit 6b851815b07331bf185f218c40d62123df048b7b Author: Kenneth Reitz <me@kennethreitz.com> Date: Fri Aug 1 14:41:37 2014 -0400 cleanup commit b2ccf76ccb244976e5ee71164cfe591925cb13a4 Author: Kenneth Reitz <me@kennethreitz.com> Date: Fri Aug 1 14:41:14 2014 -0400 remove last debugging statement commit fdcb7a210327f01fdc49dba00c3928cbb4778c72 Author: Kenneth Reitz <me@kennethreitz.com> Date: Fri Aug 1 14:39:10 2014 -0400 remove debugging statements commit dd58a898e4e5244f3b78ce0402537a1b730a3cc3 Author: Kenneth Reitz <me@kennethreitz.com> Date: Fri Aug 1 14:36:02 2014 -0400 bp watch commit c722f6e964b2a25f91d153c65f0c473ff22ff4c8 Author: Kenneth Reitz <me@kennethreitz.com> Date: Fri Aug 1 14:34:34 2014 -0400 install finished commit 81644ba1956798c06f55a8ce4c86239ca4ee8036 Author: Kenneth Reitz <me@kennethreitz.com> Date: Fri Aug 1 14:33:04 2014 -0400 install started commit 62d0e3b81a5ac25e8ceab735e25cf2bb8d161f0b Author: Kenneth Reitz <me@kennethreitz.com> Date: Thu Jul 31 14:54:59 2014 -0400 debug commit 1775a1b206780fd99d013ca7c0cb8d8de17a8461 Author: Kenneth Reitz <me@kennethreitz.com> Date: Thu Jul 31 13:01:15 2014 -0400 test0 commit 3d20cf89ae0f9436a54c456779a544a3b9d226ac Author: Kenneth Reitz <me@kennethreitz.com> Date: Thu Jul 31 12:57:07 2014 -0400 test2/2 commit 751d7496893bc84430a93cd479511786bce9abb9 Author: Kenneth Reitz <me@kennethreitz.com> Date: Thu Jul 31 12:50:11 2014 -0400 silent mode commit f927b7b3dee18c6ee58b36a3f96ad66e53b8d46d Author: Kenneth Reitz <me@kennethreitz.com> Date: Thu Jul 31 12:44:58 2014 -0400 pylibmc with pip-grep commit 00dfc36701bf72191f0ad7b7d5533ba7a9ac3b10 Author: Kenneth Reitz <me@kennethreitz.com> Date: Thu Jul 31 12:41:11 2014 -0400 no debug echo commit 38d78d800583fc89100cadc551ce715c5800f0b8 Author: Kenneth Reitz <me@kennethreitz.com> Date: Thu Jul 31 12:40:06 2014 -0400 source, not subenv commit f455de19a8c1150aa2a4df164b90c2dc9a195942 Author: Kenneth Reitz <me@kennethreitz.com> Date: Thu Jul 31 12:36:35 2014 -0400 don't print "installing dependencies with pip" twice commit e72ed7ddbafa0722d2ac6f0cdaf4ac4d0ca0f634 Author: Kenneth Reitz <me@kennethreitz.com> Date: Thu Jul 31 12:35:47 2014 -0400 refactor commit 64819d9fd7ac042ef56499750b47214eb863f8d2 Author: Kenneth Reitz <me@kennethreitz.com> Date: Thu Jul 31 12:24:26 2014 -0400 pip-grep commit 5e075dd7dbeda9084ea7ce0151dc17924251c258 Author: Kenneth Reitz <me@kennethreitz.com> Date: Thu Jul 31 12:24:13 2014 -0400 no more travis commit bc9baba04436dc7b8aefeaee24e820a9720ee9e8 Author: Kenneth Reitz <me@kennethreitz.com> Date: Tue Jul 29 13:32:40 2014 -0400 if not requirement commit 0918d781e50e6190d1045c19c5c5a37e00d669dc Author: Kenneth Reitz <me@kennethreitz.com> Date: Tue Jul 29 13:28:28 2014 -0400 only use requirments that are truthy commit 4f0f750407eae6bc7faea50c7b607a10a11ad1c5 Author: Kenneth Reitz <me@kennethreitz.com> Date: Tue Jul 29 13:25:15 2014 -0400 new version of pip-diff commit d13b397a21733d0a0a5e31c4995dc6a3b65cd977 Author: Kenneth Reitz <me@kennethreitz.com> Date: Tue Jul 29 13:12:23 2014 -0400 ignore errors for pip-diff commit bb09fb0d5051f69a35e086030b11fd39d1539f84 Author: Kenneth Reitz <me@kennethreitz.com> Date: Tue Jul 29 12:55:55 2014 -0400 uninstall the packages commit 29b2e1f2dbe7761e3f7f55827d0adcd0025aeb4b Author: Kenneth Reitz <me@kennethreitz.com> Date: Tue Jul 29 12:47:21 2014 -0400 maybe this one should be relative commit 2448558624fdce634350e904eaad5fd3aa725c22 Author: Kenneth Reitz <me@kennethreitz.com> Date: Tue Jul 29 12:44:04 2014 -0400 docopt commit 47010d297330869516f6add46ace97a41cdccb8d Author: Kenneth Reitz <me@kennethreitz.com> Date: Tue Jul 29 12:40:36 2014 -0400 first pass at pip-pop integration commit 59ac5912e1322be771d1969687891ebeb9f4b5f0 Author: Kenneth Reitz <me@kennethreitz.com> Date: Tue Jul 22 14:42:08 2014 -0400 copy requirements
208 lines
5.4 KiB
Bash
Executable File
208 lines
5.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Usage:
|
|
#
|
|
# $ bin/compile <build-dir> <cache-dir> <env-path>
|
|
|
|
# Fail fast and fail hard.
|
|
set -eo pipefail
|
|
|
|
# Prepend proper path for virtualenv hackery. This will be deprecated soon.
|
|
export PATH=:/usr/local/bin:$PATH
|
|
|
|
# Paths.
|
|
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"
|
|
|
|
# Static configurations for virtualenv caches.
|
|
VIRTUALENV_LOC=".heroku/venv"
|
|
LEGACY_TRIGGER="lib/python2.7"
|
|
PROFILE_PATH="$BUILD_DIR/.profile.d/python.sh"
|
|
|
|
DEFAULT_PYTHON_VERSION="python-2.7.8"
|
|
DEFAULT_PYTHON_STACK="cedar"
|
|
PYTHON_EXE="/app/.heroku/python/bin/python"
|
|
PIP_VERSION="1.5.6"
|
|
SETUPTOOLS_VERSION="5.4.1"
|
|
|
|
# Setup bpwatch
|
|
export PATH=$PATH:$ROOT_DIR/vendor/bpwatch
|
|
LOGPLEX_KEY="t.b90d9d29-5388-4908-9737-b4576af1d4ce"
|
|
export BPWATCH_STORE_PATH=$CACHE_DIR/bpwatch.json
|
|
BUILDPACK_VERSION=v28
|
|
|
|
# Setup pip-pop (pip-diff)
|
|
export PATH=$PATH:$ROOT_DIR/vendor/pip-pop
|
|
|
|
# Support Anvil Build_IDs
|
|
[ ! "$SLUG_ID" ] && SLUG_ID="defaultslug"
|
|
[ ! "$REQUEST_ID" ] && REQUEST_ID=$SLUG_ID
|
|
[ ! "$STACK" ] && STACK=$DEFAULT_PYTHON_STACK
|
|
|
|
# Sanitizing environment variables.
|
|
unset GIT_DIR PYTHONHOME PYTHONPATH LD_LIBRARY_PATH LIBRARY_PATH
|
|
|
|
bpwatch init $LOGPLEX_KEY
|
|
bpwatch build python $BUILDPACK_VERSION $REQUEST_ID
|
|
TMP_APP_DIR=$CACHE_DIR/tmp_app_dir
|
|
|
|
bpwatch start compile
|
|
|
|
|
|
# We'll need to send these statics to other scripts we `source`.
|
|
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
|
|
|
|
# Copy Anvil app dir to temporary storage...
|
|
bpwatch start anvil_appdir_stage
|
|
if [ "$SLUG_ID" ]; then
|
|
mkdir -p $TMP_APP_DIR
|
|
deep-mv $APP_DIR $TMP_APP_DIR
|
|
else
|
|
deep-rm $APP_DIR
|
|
fi
|
|
bpwatch stop anvil_appdir_stage
|
|
|
|
# Copy Application code in.
|
|
bpwatch start appdir_stage
|
|
deep-mv $BUILD_DIR $APP_DIR
|
|
bpwatch stop appdir_stage
|
|
|
|
# Set new context.
|
|
ORIG_BUILD_DIR=$BUILD_DIR
|
|
BUILD_DIR=$APP_DIR
|
|
|
|
# Prepend proper path buildpack use.
|
|
export PATH=$BUILD_DIR/.heroku/python/bin:$BUILD_DIR/.heroku/vendor/bin:$PATH
|
|
export PYTHONUNBUFFERED=1
|
|
export LANG=en_US.UTF-8
|
|
export C_INCLUDE_PATH=/app/.heroku/vendor/include:$BUILD_DIR/.heroku/vendor/include:/app/.heroku/python/include
|
|
export CPLUS_INCLUDE_PATH=/app/.heroku/vendor/include:$BUILD_DIR/.heroku/vendor/include:/app/.heroku/python/include
|
|
export LIBRARY_PATH=/app/.heroku/vendor/lib:$BUILD_DIR/.heroku/vendor/lib:/app/.heroku/python/lib
|
|
export LD_LIBRARY_PATH=/app/.heroku/vendor/lib:$BUILD_DIR/.heroku/vendor/lib:/app/.heroku/python/lib
|
|
export PKG_CONFIG_PATH=/app/.heroku/vendor/lib/pkg-config:$BUILD_DIR/.heroku/vendor/lib/pkg-config:/app/.heroku/python/lib/pkg-config
|
|
|
|
# Switch to the repo's context.
|
|
cd $BUILD_DIR
|
|
|
|
# Experimental pre_compile hook.
|
|
bpwatch start pre_compile
|
|
source $BIN_DIR/steps/hooks/pre_compile
|
|
bpwatch stop pre_compile
|
|
|
|
# If no requirements given, assume `setup.py develop`.
|
|
if [ ! -f requirements.txt ]; then
|
|
echo "-e ." > requirements.txt
|
|
fi
|
|
|
|
# Sticky runtimes.
|
|
if [ -f $CACHE_DIR/.heroku/python-version ]; then
|
|
DEFAULT_PYTHON_VERSION=$(cat $CACHE_DIR/.heroku/python-version)
|
|
fi
|
|
|
|
# Stack fallback for non-declared caches.
|
|
if [ -f $CACHE_DIR/.heroku/python-stack ]; then
|
|
CACHED_PYTHON_STACK=$(cat $CACHE_DIR/.heroku/python-stack)
|
|
else
|
|
CACHED_PYTHON_STACK=$DEFAULT_PYTHON_STACK
|
|
fi
|
|
|
|
# If no runtime given, assume default version.
|
|
if [ ! -f runtime.txt ]; then
|
|
echo $DEFAULT_PYTHON_VERSION > runtime.txt
|
|
fi
|
|
|
|
# ### The Cache
|
|
mkdir -p $CACHE_DIR
|
|
|
|
# Purge "old-style" virtualenvs.
|
|
bpwatch start clear_old_venvs
|
|
[ -d $CACHE_DIR/$LEGACY_TRIGGER ] && rm -fr $CACHE_DIR/.heroku/bin $CACHE_DIR/.heroku/lib $CACHE_DIR/.heroku/include
|
|
[ -d $CACHE_DIR/$VIRTUALENV_LOC ] && rm -fr $CACHE_DIR/.heroku/venv $CACHE_DIR/.heroku/src
|
|
bpwatch stop clear_old_venvs
|
|
|
|
# Restore old artifacts from the cache.
|
|
bpwatch start restore_cache
|
|
for dir in $CACHED_DIRS; do
|
|
cp -R $CACHE_DIR/$dir . &> /dev/null || true
|
|
done
|
|
bpwatch stop restore_cache
|
|
|
|
set +e
|
|
# Create set-aside `.heroku` folder.
|
|
mkdir .heroku &> /dev/null
|
|
set -e
|
|
|
|
mkdir -p $(dirname $PROFILE_PATH)
|
|
|
|
# Install Python.
|
|
source $BIN_DIR/steps/python
|
|
|
|
# Uninstall removed dependencies with Pip.
|
|
source $BIN_DIR/steps/pip-uninstall
|
|
|
|
# Mercurial support.
|
|
source $BIN_DIR/steps/mercurial
|
|
|
|
# Pylibmc support.
|
|
source $BIN_DIR/steps/pylibmc
|
|
|
|
# Install dependencies with Pip.
|
|
source $BIN_DIR/steps/pip-install
|
|
|
|
# Django collectstatic support.
|
|
source $BIN_DIR/steps/collectstatic
|
|
|
|
|
|
# ### Finalize
|
|
#
|
|
|
|
# Set context environment variables.
|
|
set-env PATH '$HOME/.heroku/python/bin:$PATH'
|
|
set-env PYTHONUNBUFFERED true
|
|
set-env PYTHONHOME /app/.heroku/python
|
|
set-env LIBRARY_PATH /app/.heroku/vendor/lib:/app/.heroku/python/lib
|
|
set-env LD_LIBRARY_PATH '/app/.heroku/vendor/lib:/app/.heroku/python/lib:$LD_LIBRARY_PATH'
|
|
set-default-env LANG en_US.UTF-8
|
|
set-default-env PYTHONHASHSEED random
|
|
set-default-env PYTHONPATH /app/
|
|
|
|
|
|
# Experimental post_compile hook.
|
|
bpwatch start post_compile
|
|
source $BIN_DIR/steps/hooks/post_compile
|
|
bpwatch stop post_compile
|
|
|
|
# Store new artifacts in cache.
|
|
bpwatch start dump_cache
|
|
for dir in $CACHED_DIRS; do
|
|
rm -rf $CACHE_DIR/$dir
|
|
cp -R $dir $CACHE_DIR/
|
|
done
|
|
bpwatch stop dump_cache
|
|
|
|
# ### Fin.
|
|
bpwatch start appdir_commit
|
|
deep-mv $BUILD_DIR $ORIG_BUILD_DIR
|
|
bpwatch stop appdir_commit
|
|
|
|
bpwatch start anvil_appdir_commit
|
|
if [ "$SLUG_ID" ]; then
|
|
deep-mv $TMP_APP_DIR $APP_DIR
|
|
fi
|
|
|
|
bpwatch stop anvil_appdir_commit
|
|
bpwatch stop compile
|