Skip to content

Instantly share code, notes, and snippets.

@ojacobson
Created July 22, 2020 17:08
Show Gist options
  • Save ojacobson/6d518b0911bddd2d4ba4c3542ef54967 to your computer and use it in GitHub Desktop.
Save ojacobson/6d518b0911bddd2d4ba4c3542ef54967 to your computer and use it in GitHub Desktop.
#!/bin/bash -e
set -o pipefail
BUILDPACK_HOME=$(cd "$(dirname "$0")" && cd .. && pwd)
STEPS="$BUILDPACK_HOME/steps"
BUILD_DIR=$1
CACHE_DIR=$2
ENV_DIR=$3
arrow() {
sed -u 's/^/-----> /'
}
indent() {
sed -u 's/^/ /'
}
section() {
echo "$@" | arrow
indent
echo
}
for env_file in $(find "$ENV_DIR" -type f -print); do
name=$(basename "$env_file")
export "$name=$(< "$env_file")"
done
SAVED_APP=$(mktemp -d)
"$STEPS/prepare-app-dir" "$BUILD_DIR" "$SAVED_APP" |& section "Preparing /app"
(
cd /app
"$STEPS/restore-cache" "$CACHE_DIR" \
< "$BUILDPACK_HOME/config/cache-entries" \
|& section "Restoring cache"
"$STEPS/install-pyenv" |& section "Installing pyenv"
export PYENV_ROOT="$PWD/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
"$STEPS/install-python" |& section "Installing Python"
"$STEPS/make-virtualenv" |& section "Creating virtualenv"
(
source .virtualenv/bin/activate
"$STEPS/install-app-dependencies" |& section "Installing app dependencies"
"$STEPS/create-profile" |& section "Creating profile script"
)
)
"$STEPS/save-app-dir" "$BUILD_DIR" "$SAVED_APP" |& section "Saving /app"
(
cd "$BUILD_DIR"
"$STEPS/save-cache" "$CACHE_DIR" \
< "$BUILDPACK_HOME/config/cache-entries" \
|& section "Saving cache"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment