From 9a69793da60cb81ee4e2583d6cf0ec1f93de2e10 Mon Sep 17 00:00:00 2001 From: Noah Zoschke Date: Tue, 17 May 2011 18:26:46 -0700 Subject: [PATCH] slug-compiler lp import --- bin/compile | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ bin/detect | 8 ++++++ bin/release | 29 ++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100755 bin/compile create mode 100755 bin/detect create mode 100755 bin/release diff --git a/bin/compile b/bin/compile new file mode 100755 index 0000000..0267f0f --- /dev/null +++ b/bin/compile @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +# bin/compile + +set -e + +BIN_DIR=$(dirname $0) +BUILD_DIR=$1 +CACHE_DIR=$2 + +NAME=$($BIN_DIR/detect $BUILD_DIR) +PIP_DOWNLOAD_CACHE=${PIP_DOWNLOAD_CACHE:-$CACHE_DIR/pip_downloads} +VIRTUALENV_DIRS="bin include lib" + +function sed() { + # prefer GNU sed over BSD sed on OS X + $(which gsed || which sed) "$@" +} + +cd $BUILD_DIR + +# copy artifacts out of cache if exists +mkdir -p $CACHE_DIR +for dir in $VIRTUALENV_DIRS; do + cp -R $CACHE_DIR/$dir . &> /dev/null || true +done + +echo "-----> Preparing virtualenv" +virtualenv --no-site-packages . | sed -u 's/^/ /' +[ "${PIPESTATUS[*]}" == "0 0" ] + +echo "-----> Byte-compiling code" +find . -name "*.py" | xargs bin/python -m py_compile +[ "${PIPESTATUS[*]}" == "0 0" ] + +# if Django, inject psycopg and append settings +if [ "$NAME" = "Django" ]; then + grep -q ^psycopg2 requirements.txt || ( + echo "-----> Injecting psycopg2 into requirements for PostgreSQL support" + echo "psycopg2==2.3.1" >> requirements.txt + ) + + SETTINGS_FILE=$(ls **/settings.py | head -1) + echo "-----> Appending code to $SETTINGS_FILE to read from DATABASE_URL" + + cat >>$SETTINGS_FILE < Installing dependencies with pip" +PIP_DOWNLOAD_CACHE=$PIP_DOWNLOAD_CACHE bin/pip install -r requirements.txt | sed -u 's/^/ /' +[ "${PIPESTATUS[*]}" == "0 0" ] + +# store new artifacts in cache +for dir in $VIRTUALENV_DIRS; do + rm -rf $CACHE_DIR/$dir + cp -R $dir $CACHE_DIR/ +done \ No newline at end of file diff --git a/bin/detect b/bin/detect new file mode 100755 index 0000000..e3a553c --- /dev/null +++ b/bin/detect @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# bin/name + +BUILD_DIR=$1 +[ -f $BUILD_DIR/requirements.txt ] || exit 1 # fail fast if no requirements.txt + +# 'Django' if there is a [mysite]/settings.py file present; otherwise 'Python' +ls $BUILD_DIR/**/settings.py &> /dev/null && echo Django || echo Python \ No newline at end of file diff --git a/bin/release b/bin/release new file mode 100755 index 0000000..95b43af --- /dev/null +++ b/bin/release @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# bin/release + +BIN_DIR=$(dirname $0) +BUILD_DIR=$1 +NAME=$($BIN_DIR/detect $BUILD_DIR) || exit 1 + +cd $BUILD_DIR + +cat <