mirror of
https://github.com/kennethreitz/heroku-buildpack-python.git
synced 2026-06-05 23:10:16 +00:00
Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 63cea99415 | |||
| 5ecd27e3b8 | |||
| 206a2dbc04 | |||
| 2a083791b6 | |||
| d5b2b0b464 | |||
| 2eab1ad845 | |||
| 2b16420d41 | |||
| 9fa0889499 | |||
| 99b17fabeb | |||
| 933d3014d7 | |||
| 018e0f31de | |||
| cf1647e937 | |||
| b9f154bf38 | |||
| 4cc18ce0af | |||
| f5ea1c24a3 | |||
| 952b0bb735 | |||
| 8b7edad8a2 | |||
| 02787ac910 | |||
| bcc3ba09ca | |||
| 31e65dc58b | |||
| 9a227e6c73 | |||
| ddc9c24d34 | |||
| 42488a2be7 | |||
| 839486c25b | |||
| 5d56200179 |
@@ -45,10 +45,10 @@ Specify a Runtime
|
|||||||
You can also provide arbitrary releases Python with a `runtime.txt` file.
|
You can also provide arbitrary releases Python with a `runtime.txt` file.
|
||||||
|
|
||||||
$ cat runtime.txt
|
$ cat runtime.txt
|
||||||
python-3.3.0
|
python-3.3.2
|
||||||
|
|
||||||
Runtime options include:
|
Runtime options include:
|
||||||
|
|
||||||
- python-2.7.4
|
- python-2.7.4
|
||||||
- python-3.3.1
|
- python-3.3.2
|
||||||
- pypy-1.9 (experimental)
|
- pypy-1.9 (experimental)
|
||||||
|
|||||||
+60
-52
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
# Usage:
|
# Usage:
|
||||||
#
|
#
|
||||||
# $ bin/compile <build-dir> <cache-dir>
|
# $ bin/compile <build-dir> <cache-dir> <env-path>
|
||||||
|
|
||||||
|
|
||||||
# Fail fast and fail hard.
|
# Fail fast and fail hard.
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
@@ -16,6 +15,8 @@ BIN_DIR=$(cd $(dirname $0); pwd) # absolute path
|
|||||||
ROOT_DIR=$(dirname $BIN_DIR)
|
ROOT_DIR=$(dirname $BIN_DIR)
|
||||||
BUILD_DIR=$1
|
BUILD_DIR=$1
|
||||||
CACHE_DIR=$2
|
CACHE_DIR=$2
|
||||||
|
ENV_FILE=$3
|
||||||
|
|
||||||
|
|
||||||
CACHED_DIRS=".heroku"
|
CACHED_DIRS=".heroku"
|
||||||
|
|
||||||
@@ -30,16 +31,17 @@ PYTHON_EXE="/app/.heroku/python/bin/python"
|
|||||||
PIP_VERSION="1.3.1"
|
PIP_VERSION="1.3.1"
|
||||||
DISTRIBUTE_VERSION="0.6.36"
|
DISTRIBUTE_VERSION="0.6.36"
|
||||||
|
|
||||||
|
# Setup bpwatch
|
||||||
export PATH=$PATH:$ROOT_DIR/vendor/bpwatch
|
export PATH=$PATH:$ROOT_DIR/vendor/bpwatch
|
||||||
|
|
||||||
LOGPLEX_KEY="t.b396af7f-ad75-4643-8b9e-ebb288acc624"
|
LOGPLEX_KEY="t.b396af7f-ad75-4643-8b9e-ebb288acc624"
|
||||||
BUILDPACK_VERSION=HEAD
|
|
||||||
|
|
||||||
export BPWATCH_STORE_PATH=$CACHE_DIR/bpwatch.json
|
export BPWATCH_STORE_PATH=$CACHE_DIR/bpwatch.json
|
||||||
|
BUILDPACK_VERSION=v28
|
||||||
|
|
||||||
|
# Support Anvil Build_IDs
|
||||||
[ ! "$REQUEST_ID" ] && REQUEST_ID=$SLUG_ID
|
[ ! "$REQUEST_ID" ] && REQUEST_ID=$SLUG_ID
|
||||||
|
|
||||||
|
# Sanitizing environment variables.
|
||||||
|
unset GIT_DIR PYTHONHOME PYTHONPATH LD_LIBRARY_PATH LIBRARY_PATH
|
||||||
|
|
||||||
bpwatch init $LOGPLEX_KEY
|
bpwatch init $LOGPLEX_KEY
|
||||||
bpwatch build python $BUILDPACK_VERSION $REQUEST_ID
|
bpwatch build python $BUILDPACK_VERSION $REQUEST_ID
|
||||||
@@ -48,9 +50,6 @@ TMP_APP_DIR=$CACHE_DIR/tmp_app_dir
|
|||||||
bpwatch start compile
|
bpwatch start compile
|
||||||
|
|
||||||
|
|
||||||
# Sanitizing environment variables.
|
|
||||||
unset GIT_DIR PYTHONHOME PYTHONPATH LD_LIBRARY_PATH LIBRARY_PATH
|
|
||||||
|
|
||||||
# We'll need to send these statics to other scripts we `source`.
|
# We'll need to send these statics to other scripts we `source`.
|
||||||
export BUILD_DIR CACHE_DIR BIN_DIR PROFILE_PATH
|
export BUILD_DIR CACHE_DIR BIN_DIR PROFILE_PATH
|
||||||
|
|
||||||
@@ -63,13 +62,17 @@ TMP_APP_DIR=$CACHE_DIR/tmp_app_dir
|
|||||||
|
|
||||||
# Copy Anvil app dir to temporary storage...
|
# Copy Anvil app dir to temporary storage...
|
||||||
bpwatch start anvil_appdir_stage
|
bpwatch start anvil_appdir_stage
|
||||||
mkdir -p $TMP_APP_DIR
|
if [ "$SLUG_ID" ]; then
|
||||||
deep-mv $APP_DIR $TMP_APP_DIR
|
mkdir -p $TMP_APP_DIR
|
||||||
|
deep-mv $APP_DIR $TMP_APP_DIR
|
||||||
|
else
|
||||||
|
deep-rm $APP_DIR
|
||||||
|
fi
|
||||||
bpwatch stop anvil_appdir_stage
|
bpwatch stop anvil_appdir_stage
|
||||||
|
|
||||||
# Copy Application code in.
|
# Copy Application code in.
|
||||||
bpwatch start appdir_stage
|
bpwatch start appdir_stage
|
||||||
deep-mv $BUILD_DIR $APP_DIR
|
deep-mv $BUILD_DIR $APP_DIR
|
||||||
bpwatch stop appdir_stage
|
bpwatch stop appdir_stage
|
||||||
|
|
||||||
# Set new context.
|
# Set new context.
|
||||||
@@ -77,18 +80,21 @@ ORIG_BUILD_DIR=$BUILD_DIR
|
|||||||
BUILD_DIR=$APP_DIR
|
BUILD_DIR=$APP_DIR
|
||||||
|
|
||||||
# Prepend proper path buildpack use.
|
# Prepend proper path buildpack use.
|
||||||
export PATH=$BUILD_DIR/.heroku/python/bin:$PATH
|
export PATH=$BUILD_DIR/.heroku/python/bin:$BUILD_DIR/.heroku/vendor/bin:$PATH
|
||||||
export PYTHONUNBUFFERED=1
|
export PYTHONUNBUFFERED=1
|
||||||
export LANG=en_US.UTF-8
|
export LANG=en_US.UTF-8
|
||||||
export LIBRARY_PATH=/app/.heroku/vendor/lib
|
export C_INCLUDE_PATH=/app/.heroku/vendor/include:$BUILD_DIR/.heroku/vendor/include
|
||||||
export LD_LIBRARY_PATH=/app/.heroku/vendor/lib
|
export CPLUS_INCLUDE_PATH=/app/.heroku/vendor/include:$BUILD_DIR/.heroku/vendor/include
|
||||||
|
export LIBRARY_PATH=/app/.heroku/vendor/lib:$BUILD_DIR/.heroku/vendor/lib
|
||||||
|
export LD_LIBRARY_PATH=/app/.heroku/vendor/lib:$BUILD_DIR/.heroku/vendor/lib
|
||||||
|
export PKG_CONFIG_PATH=/app/.heroku/vendor/lib/pkg-config:$BUILD_DIR/.heroku/vendor/lib/pkg-config
|
||||||
|
|
||||||
# Switch to the repo's context.
|
# Switch to the repo's context.
|
||||||
cd $BUILD_DIR
|
cd $BUILD_DIR
|
||||||
|
|
||||||
# Experimental pre_compile hook.
|
# Experimental pre_compile hook.
|
||||||
bpwatch start pre_compile
|
bpwatch start pre_compile
|
||||||
source $BIN_DIR/steps/hooks/pre_compile
|
source $BIN_DIR/steps/hooks/pre_compile
|
||||||
bpwatch stop pre_compile
|
bpwatch stop pre_compile
|
||||||
|
|
||||||
# If no requirements given, assume `setup.py develop`.
|
# If no requirements given, assume `setup.py develop`.
|
||||||
@@ -108,15 +114,15 @@ mkdir -p $CACHE_DIR
|
|||||||
|
|
||||||
# Purge "old-style" virtualenvs.
|
# Purge "old-style" virtualenvs.
|
||||||
bpwatch start clear_old_venvs
|
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/$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
|
[ -d $CACHE_DIR/$VIRTUALENV_LOC ] && rm -fr $CACHE_DIR/.heroku/venv $CACHE_DIR/.heroku/src
|
||||||
bpwatch stop clear_old_venvs
|
bpwatch stop clear_old_venvs
|
||||||
|
|
||||||
# Restore old artifacts from the cache.
|
# Restore old artifacts from the cache.
|
||||||
bpwatch start restore_cache
|
bpwatch start restore_cache
|
||||||
for dir in $CACHED_DIRS; do
|
for dir in $CACHED_DIRS; do
|
||||||
cp -R $CACHE_DIR/$dir . &> /dev/null || true
|
cp -R $CACHE_DIR/$dir . &> /dev/null || true
|
||||||
done
|
done
|
||||||
bpwatch stop restore_cache
|
bpwatch stop restore_cache
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
@@ -133,8 +139,8 @@ PYTHON_VERSION=$(cat runtime.txt)
|
|||||||
if [ -f .heroku/python-version ]; then
|
if [ -f .heroku/python-version ]; then
|
||||||
if [ ! $(cat .heroku/python-version) = $PYTHON_VERSION ]; then
|
if [ ! $(cat .heroku/python-version) = $PYTHON_VERSION ]; then
|
||||||
bpwatch start uninstall_python
|
bpwatch start uninstall_python
|
||||||
puts-step "Found $(cat .heroku/python-version), removing."
|
puts-step "Found $(cat .heroku/python-version), removing."
|
||||||
rm -fr .heroku/python
|
rm -fr .heroku/python
|
||||||
bpwatch stop uninstall_python
|
bpwatch stop uninstall_python
|
||||||
else
|
else
|
||||||
SKIP_INSTALL=1
|
SKIP_INSTALL=1
|
||||||
@@ -144,14 +150,14 @@ fi
|
|||||||
|
|
||||||
if [ ! "$SKIP_INSTALL" ]; then
|
if [ ! "$SKIP_INSTALL" ]; then
|
||||||
bpwatch start install_python
|
bpwatch start install_python
|
||||||
puts-step "Preparing Python runtime ($PYTHON_VERSION)"
|
puts-step "Preparing Python runtime ($PYTHON_VERSION)"
|
||||||
curl http://envy-versions.s3.amazonaws.com/$PYTHON_VERSION.tar.bz2 -s | tar jx &> /dev/null
|
curl http://envy-versions.s3.amazonaws.com/$PYTHON_VERSION.tar.bz2 -s | tar jx &> /dev/null
|
||||||
if [[ $? != 0 ]] ; then
|
if [[ $? != 0 ]] ; then
|
||||||
puts-warn "Requested runtime ($PYTHON_VERSION) was not found."
|
puts-warn "Requested runtime ($PYTHON_VERSION) was not found."
|
||||||
puts-warn "Aborting. More info: https://devcenter.heroku.com/articles/python-support"
|
puts-warn "Aborting. More info: https://devcenter.heroku.com/articles/python-support"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
mv python .heroku/python
|
mv python .heroku/python
|
||||||
bpwatch stop install_python
|
bpwatch stop install_python
|
||||||
|
|
||||||
# Record for future reference.
|
# Record for future reference.
|
||||||
@@ -170,18 +176,18 @@ if [ "$FRESH_PYTHON" ] || [[ ! $(pip --version) == *$PIP_VERSION* ]]; then
|
|||||||
bpwatch start prepare_environment
|
bpwatch start prepare_environment
|
||||||
|
|
||||||
bpwatch start install_distribute
|
bpwatch start install_distribute
|
||||||
# Prepare it for the real world
|
# Prepare it for the real world
|
||||||
puts-step "Installing Distribute ($DISTRIBUTE_VERSION)"
|
puts-step "Installing Distribute ($DISTRIBUTE_VERSION)"
|
||||||
cd $ROOT_DIR/vendor/distribute-$DISTRIBUTE_VERSION/
|
cd $ROOT_DIR/vendor/distribute-$DISTRIBUTE_VERSION/
|
||||||
python setup.py install &> /dev/null
|
python setup.py install &> /dev/null
|
||||||
cd $WORKING_DIR
|
cd $WORKING_DIR
|
||||||
bpwatch stop install_distribute
|
bpwatch stop install_distribute
|
||||||
|
|
||||||
bpwatch start install_pip
|
bpwatch start install_pip
|
||||||
puts-step "Installing Pip ($PIP_VERSION)"
|
puts-step "Installing Pip ($PIP_VERSION)"
|
||||||
cd $ROOT_DIR/vendor/pip-$PIP_VERSION/
|
cd $ROOT_DIR/vendor/pip-$PIP_VERSION/
|
||||||
python setup.py install &> /dev/null
|
python setup.py install &> /dev/null
|
||||||
cd $WORKING_DIR
|
cd $WORKING_DIR
|
||||||
|
|
||||||
bpwatch stop install_pip
|
bpwatch stop install_pip
|
||||||
bpwatch stop prepare_environment
|
bpwatch stop prepare_environment
|
||||||
@@ -193,13 +199,13 @@ hash -r
|
|||||||
# Pylibmc support.
|
# Pylibmc support.
|
||||||
# See [`bin/steps/pylibmc`](pylibmc.html).
|
# See [`bin/steps/pylibmc`](pylibmc.html).
|
||||||
bpwatch start pylibmc_install
|
bpwatch start pylibmc_install
|
||||||
source $BIN_DIR/steps/pylibmc
|
source $BIN_DIR/steps/pylibmc
|
||||||
bpwatch stop pylibmc_install
|
bpwatch stop pylibmc_install
|
||||||
|
|
||||||
# Install Mercurial if it appears to be required.
|
# Install Mercurial if it appears to be required.
|
||||||
if (grep -Fiq "hg+" requirements.txt) then
|
if (grep -Fiq "hg+" requirements.txt) then
|
||||||
bpwatch start mercurial_install
|
bpwatch start mercurial_install
|
||||||
/app/.heroku/python/bin/pip install --use-mirrors mercurial | cleanup | indent
|
/app/.heroku/python/bin/pip install mercurial | cleanup | indent
|
||||||
bpwatch stop mercurial_install
|
bpwatch stop mercurial_install
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -210,14 +216,14 @@ puts-step "Installing dependencies using Pip ($PIP_VERSION)"
|
|||||||
[ ! "$FRESH_PYTHON" ] && bpwatch start pip_install
|
[ ! "$FRESH_PYTHON" ] && bpwatch start pip_install
|
||||||
[ "$FRESH_PYTHON" ] && bpwatch start pip_install_first
|
[ "$FRESH_PYTHON" ] && bpwatch start pip_install_first
|
||||||
|
|
||||||
/app/.heroku/python/bin/pip install --use-mirrors -r requirements.txt --exists-action=w --src=./.heroku/src | cleanup | indent
|
/app/.heroku/python/bin/pip install -r requirements.txt --exists-action=w --src=./.heroku/src | cleanup | indent
|
||||||
|
|
||||||
[ ! "$FRESH_PYTHON" ] && bpwatch stop pip_install
|
[ ! "$FRESH_PYTHON" ] && bpwatch stop pip_install
|
||||||
[ "$FRESH_PYTHON" ] && bpwatch stop pip_install_first
|
[ "$FRESH_PYTHON" ] && bpwatch stop pip_install_first
|
||||||
|
|
||||||
# Django collectstatic support.
|
# Django collectstatic support.
|
||||||
bpwatch start collectstatic
|
bpwatch start collectstatic
|
||||||
source $BIN_DIR/steps/collectstatic
|
sub-env $BIN_DIR/steps/collectstatic
|
||||||
bpwatch stop collectstatic
|
bpwatch stop collectstatic
|
||||||
|
|
||||||
# ### Finalize
|
# ### Finalize
|
||||||
@@ -236,24 +242,26 @@ set-default-env PYTHONPATH /app/
|
|||||||
|
|
||||||
# Experimental post_compile hook.
|
# Experimental post_compile hook.
|
||||||
bpwatch start post_compile
|
bpwatch start post_compile
|
||||||
source $BIN_DIR/steps/hooks/post_compile
|
source $BIN_DIR/steps/hooks/post_compile
|
||||||
bpwatch stop post_compile
|
bpwatch stop post_compile
|
||||||
|
|
||||||
# Store new artifacts in cache.
|
# Store new artifacts in cache.
|
||||||
bpwatch start dump_cache
|
bpwatch start dump_cache
|
||||||
for dir in $CACHED_DIRS; do
|
for dir in $CACHED_DIRS; do
|
||||||
rm -rf $CACHE_DIR/$dir
|
rm -rf $CACHE_DIR/$dir
|
||||||
cp -R $dir $CACHE_DIR/
|
cp -R $dir $CACHE_DIR/
|
||||||
done
|
done
|
||||||
bpwatch stop dump_cache
|
bpwatch stop dump_cache
|
||||||
|
|
||||||
# ### Fin.
|
# ### Fin.
|
||||||
bpwatch start appdir_commit
|
bpwatch start appdir_commit
|
||||||
deep-mv $BUILD_DIR $ORIG_BUILD_DIR
|
deep-mv $BUILD_DIR $ORIG_BUILD_DIR
|
||||||
bpwatch stop appdir_commit
|
bpwatch stop appdir_commit
|
||||||
|
|
||||||
bpwatch start anvil_appdir_commit
|
bpwatch start anvil_appdir_commit
|
||||||
deep-mv $TMP_APP_DIR $APP_DIR
|
if [ "$SLUG_ID" ]; then
|
||||||
bpwatch stop anvil_appdir_commit
|
deep-mv $TMP_APP_DIR $APP_DIR
|
||||||
|
fi
|
||||||
|
|
||||||
|
bpwatch stop anvil_appdir_commit
|
||||||
bpwatch stop compile
|
bpwatch stop compile
|
||||||
|
|||||||
+1
-1
@@ -18,6 +18,6 @@ if [[ $MANAGE_FILE ]]; then
|
|||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
|
||||||
addons:
|
addons:
|
||||||
heroku-postgresql:dev
|
heroku-postgresql:hobby-dev
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|||||||
Regular → Executable
Regular → Executable
+1
-1
@@ -3,5 +3,5 @@
|
|||||||
if [ -f bin/post_compile ]; then
|
if [ -f bin/post_compile ]; then
|
||||||
echo "-----> Running post-compile hook"
|
echo "-----> Running post-compile hook"
|
||||||
chmod +x bin/post_compile
|
chmod +x bin/post_compile
|
||||||
bin/post_compile
|
sub-env bin/post_compile
|
||||||
fi
|
fi
|
||||||
Regular → Executable
+1
-1
@@ -3,5 +3,5 @@
|
|||||||
if [ -f bin/pre_compile ]; then
|
if [ -f bin/pre_compile ]; then
|
||||||
echo "-----> Running pre-compile hook"
|
echo "-----> Running pre-compile hook"
|
||||||
chmod +x bin/pre_compile
|
chmod +x bin/pre_compile
|
||||||
bin/pre_compile
|
sub-env bin/pre_compile
|
||||||
fi
|
fi
|
||||||
@@ -52,3 +52,13 @@ function deep-mv (){
|
|||||||
rm -fr $1/!(tmp)
|
rm -fr $1/!(tmp)
|
||||||
find -H $1 -maxdepth 1 -name '.*' -a \( -type d -o -type f -o -type l \) -exec rm -fr '{}' \;
|
find -H $1 -maxdepth 1 -name '.*' -a \( -type d -o -type f -o -type l \) -exec rm -fr '{}' \;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Does some serious deleting.
|
||||||
|
function deep-rm (){
|
||||||
|
rm -fr $1/!(tmp)
|
||||||
|
find -H $1 -maxdepth 1 -name '.*' -a \( -type d -o -type f -o -type l \) -exec rm -fr '{}' \;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sub-env (){
|
||||||
|
(export $(egrep -v '^(GIT_DIR|PYTHONHOME|PYTHONPATH|LD_LIBRARY_PATH|LIBRARY_PATH|PATH)' $ENV_FILE); $1)
|
||||||
|
}
|
||||||
|
|||||||
Vendored
+3
-3
@@ -1,12 +1,12 @@
|
|||||||
#!/usr/local/bin/python
|
#!/usr/bin/env python2
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
DEFUALT_PATH = '{}.zip'.format(os.path.abspath(__file__))
|
DEFAULT_PATH = '{0}.zip'.format(os.path.abspath(__file__))
|
||||||
BPWATCH_DISTRO_PATH = os.environ.get('BPWATCH_DISTRO_PATH', DEFUALT_PATH)
|
BPWATCH_DISTRO_PATH = os.environ.get('BPWATCH_DISTRO_PATH', DEFAULT_PATH)
|
||||||
|
|
||||||
sys.path.insert(0, BPWATCH_DISTRO_PATH)
|
sys.path.insert(0, BPWATCH_DISTRO_PATH)
|
||||||
|
|
||||||
|
|||||||
Vendored
BIN
Binary file not shown.
Reference in New Issue
Block a user