Skip to content

Commit 1721fa3

Browse files
authored
Merge pull request #868 from heroku/app-dir-fix
Refactor: $BUILD_DIR
2 parents 89145ef + 970b6c1 commit 1721fa3

File tree

15 files changed

+43
-43
lines changed

15 files changed

+43
-43
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# Master
44

5+
- Refactor: use variable rather than hardcoded /app
56
- Bug fix: pipenv no longer installs twice on CI
67

78
--------------------------------------------------------------------------------

bin/compile

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export PATH=$PATH:$ROOT_DIR/vendor/:$ROOT_DIR/vendor/pip-pop
9090
unset GIT_DIR PYTHONHOME PYTHONPATH
9191
unset RECEIVE_DATA RUN_KEY BUILD_INFO DEPLOY LOG_TOKEN
9292
unset CYTOKINE_LOG_FILE GEM_PATH
93+
export PYTHONPATH="$BUILD_DIR"
9394

9495
# Import the utils script, which contains helper functions used throughout the buildpack.
9596
# shellcheck source=bin/utils
@@ -104,7 +105,7 @@ source "$BIN_DIR/warnings"
104105
# to `/app`.
105106
# Symlinks are required, since Python is not a portable installation.
106107
# More on this topic later.
107-
mkdir -p /app/.heroku
108+
mkdir -p "BUILD_DIR/.heroku"
108109

109110
# This buildpack programatically generates (or simply copies) a number of files for
110111
# buildpack machinery: an export script, and a number of `.profile.d` scripts. This
@@ -122,19 +123,19 @@ export BUILD_DIR CACHE_DIR BIN_DIR PROFILE_PATH EXPORT_PATH
122123
# Notes on each variable included.
123124

124125
# PATH is relatively obvious, we need to be able to execute 'python'.
125-
export PATH=/app/.heroku/python/bin:/app/.heroku/vendor/bin:$PATH
126+
export PATH="$BUILD_DIR/.heroku/python/bin:$BUILD_DIR/.heroku/vendor/bin:$PATH"
126127
# Tell Python to not buffer it's stdin/stdout.
127128
export PYTHONUNBUFFERED=1
128129
# Set the locale to a well-known and expected standard.
129130
export LANG=en_US.UTF-8
130131
# `~/.heroku/vendor` is an place where the buildpack may stick pre-build binaries for known
131132
# C dependencies (e.g. libmemcached on cedar-14). This section configures Python (GCC, more specifically)
132133
# and pip to automatically include these paths when building binaries.
133-
export C_INCLUDE_PATH=/app/.heroku/vendor/include:/app/.heroku/python/include:$C_INCLUDE_PATH
134-
export CPLUS_INCLUDE_PATH=/app/.heroku/vendor/include:/app/.heroku/python/include:$CPLUS_INCLUDE_PATH
135-
export LIBRARY_PATH=/app/.heroku/vendor/lib:/app/.heroku/python/lib:$LIBRARY_PATH
136-
export LD_LIBRARY_PATH=/app/.heroku/vendor/lib:/app/.heroku/python/lib:$LD_LIBRARY_PATH
137-
export PKG_CONFIG_PATH=/app/.heroku/vendor/lib/pkg-config:/app/.heroku/python/lib/pkg-config:$PKG_CONFIG_PATH
134+
export C_INCLUDE_PATH="$BUILD_DIR/.heroku/vendor/include:$BUILD_DIR/.heroku/python/include:$C_INCLUDE_PATH"
135+
export CPLUS_INCLUDE_PATH="$BUILD_DIR/.heroku/vendor/include:$BUILD_DIR/.heroku/python/include:$CPLUS_INCLUDE_PATH"
136+
export LIBRARY_PATH="$BUILD_DIR/.heroku/vendor/lib:$BUILD_DIR/.heroku/python/lib:$LIBRARY_PATH"
137+
export LD_LIBRARY_PATH="$BUILD_DIR/.heroku/vendor/lib:$BUILD_DIR/.heroku/python/lib:$LD_LIBRARY_PATH"
138+
export PKG_CONFIG_PATH="$BUILD_DIR/.heroku/vendor/lib/pkg-config:$BUILD_DIR/.heroku/python/lib/pkg-config:$PKG_CONFIG_PATH"
138139

139140
# The Application Code
140141
# --------------------
@@ -211,15 +212,16 @@ fi
211212
# Create the directory for .profile.d, if it doesn't exist.
212213
mkdir -p "$(dirname "$PROFILE_PATH")"
213214
# Create the directory for editable source code installation, if it doesn't exist.
214-
mkdir -p /app/.heroku/src
215+
mkdir -p "$BUILD_DIR/.heroku/src"
215216

216217
# On Heroku CI, builds happen in `/app`. Otherwise, on the Heroku platform,
217218
# they occur in a temp directory. Beacuse Python is not portable, we must create
218219
# symlinks to emulate that we are operating in `/app` during the build process.
219220
# This is (hopefully obviously) because apps end up running from `/app` in production.
220-
if [[ $BUILD_DIR != '/app' ]]; then
221+
if [[ "$BUILD_DIR" != '/app' ]]; then
221222
# python expects to reside in /app, so set up symlinks
222223
# we will not remove these later so subsequent buildpacks can still invoke it
224+
mkdir -p /app/.heroku
223225
ln -nsf "$BUILD_DIR/.heroku/python" /app/.heroku/python
224226
ln -nsf "$BUILD_DIR/.heroku/vendor" /app/.heroku/vendor
225227
# Note: .heroku/src is copied in later.
@@ -310,8 +312,7 @@ mtime "nltk.download.time" "${start}"
310312
# and copying it into the proper place (the logical place to do this was early, but it must be done here).
311313
# In CI, $BUILD_DIR is /app.
312314
if [[ ! "$BUILD_DIR" == "/app" ]]; then
313-
rm -fr "$BUILD_DIR/.heroku/src"
314-
deep-cp /app/.heroku/src "$BUILD_DIR/.heroku/src"
315+
ln -nsf "$BUILD_DIR/.heroku/src" /app/.heroku/src
315316
fi
316317

317318

@@ -343,13 +344,12 @@ set_default_env PYTHONHASHSEED random
343344
# Tell Python to look for Python modules in the /app dir. Don't change this.
344345
set_default_env PYTHONPATH "\$HOME"
345346

346-
# Python expects to be in /app, if at runtime, it is not, set
347+
# Python expects to be in "$BUILD_DIR," if at runtime, it is not, set
347348
# up symlinks… this can occur when the subdir buildpack is used.
348349
cat <<EOT >> "$PROFILE_PATH"
349-
if [[ \$HOME != "/app" ]]; then
350-
mkdir -p /app/.heroku
351-
ln -nsf "\$HOME/.heroku/python" /app/.heroku/python
352-
ln -nsf "\$HOME/.heroku/vendor" /app/.heroku/vendor
350+
if [[ \$HOME != "$BUILD_DIR" ]]; then
351+
ln -nsf "\$HOME/.heroku/python" "$BUILD_DIR/.heroku/python"
352+
ln -nsf "\$HOME/.heroku/vendor" "$BUILD_DIR/.heroku/vendor"
353353
fi
354354
EOT
355355

bin/steps/collectstatic

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ] && [ "$DJANGO_INSTALL
3030
puts-step "$ python $MANAGE_FILE collectstatic --noinput"
3131

3232
# Run collectstatic, cleanup some of the noisy output.
33-
PYTHONPATH=${PYTHONPATH:-.}
33+
PYTHONPATH=${PYTHONPATH:-$BUILD_DIR}
3434
export PYTHONPATH
3535

3636
# Create a temporary file for collecting the collectstaic logs.
3737
COLLECTSTATIC_LOG=$(mktemp)
38-
3938
python "$MANAGE_FILE" collectstatic --noinput --traceback 2>&1 | tee "$COLLECTSTATIC_LOG" | sed '/^Post-processed/d;/^Copying/d;/^$/d' | indent
4039
COLLECTSTATIC_STATUS="${PIPESTATUS[0]}"
4140

bin/steps/gdal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# The location of the pre-compiled cryptography binary.
1313
VENDORED_GDAL="${VENDOR_URL}/libraries/vendor/gdal.tar.gz"
1414

15-
PKG_CONFIG_PATH="/app/.heroku/vendor/lib/pkgconfig:$PKG_CONFIG_PATH"
15+
PKG_CONFIG_PATH="$BUILD_DIR/.heroku/vendor/lib/pkgconfig:$PKG_CONFIG_PATH"
1616

1717
# Syntax sugar.
1818
# shellcheck source=bin/utils

bin/steps/geo-libs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ VENDORED_GDAL="${VENDOR_URL}/libraries/vendor/gdal.tar.gz"
1414
VENDORED_GEOS="${VENDOR_URL}/libraries/vendor/geos.tar.gz"
1515
VENDORED_PROJ="${VENDOR_URL}/libraries/vendor/proj.tar.gz"
1616

17-
PKG_CONFIG_PATH="/app/.heroku/vendor/lib/pkgconfig:$PKG_CONFIG_PATH"
17+
PKG_CONFIG_PATH="$BUILD_DIR/.heroku/vendor/lib/pkgconfig:$PKG_CONFIG_PATH"
1818

1919
# Syntax sugar.
2020
# shellcheck source=bin/utils

bin/steps/mercurial

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Install Mercurial if it appears to be required.
44
if [[ -f "requirements.txt" ]]; then
55
if (grep -Fiq "hg+" requirements.txt) then
6-
/app/.heroku/python/bin/pip install mercurial | cleanup | indent
6+
"$BUILD_DIR/.heroku/python/bin/pip" install mercurial | cleanup | indent
77
mcount "steps.mercurial"
88
fi
99
fi

bin/steps/pip-install

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ if [ ! "$SKIP_PIP_INSTALL" ]; then
4141
if [ ! -f "$BUILD_DIR/.heroku/python/bin/pip" ]; then
4242
exit 1
4343
fi
44-
/app/.heroku/python/bin/pip install -r "$BUILD_DIR/requirements.txt" --exists-action=w --src=/app/.heroku/src --disable-pip-version-check --no-cache-dir 2>&1 | tee "$WARNINGS_LOG" | cleanup | indent
44+
45+
"$BUILD_DIR/.heroku/python/bin/pip" install -r "$BUILD_DIR/requirements.txt" --exists-action=w --src="$BUILD_DIR/.heroku/src" --disable-pip-version-check --no-cache-dir 2>&1 | tee "$WARNINGS_LOG" | cleanup | indent
4546
PIP_STATUS="${PIPESTATUS[0]}"
4647
set -e
4748

@@ -54,15 +55,15 @@ if [ ! "$SKIP_PIP_INSTALL" ]; then
5455

5556
# Smart Requirements handling
5657
cp requirements.txt .heroku/python/requirements-declared.txt
57-
/app/.heroku/python/bin/pip freeze --disable-pip-version-check > .heroku/python/requirements-installed.txt
58+
"$BUILD_DIR/.heroku/python/bin/pip" freeze --disable-pip-version-check > .heroku/python/requirements-installed.txt
5859

5960
echo
6061

6162
# Install test dependencies, for CI.
6263
if [ "$INSTALL_TEST" ]; then
6364
if [[ -f "$1/requirements-test.txt" ]]; then
6465
puts-step "Installing test dependencies…"
65-
/app/.heroku/python/bin/pip install -r "$1/requirements-test.txt" --exists-action=w --src=./.heroku/src --disable-pip-version-check --no-cache-dir 2>&1 | cleanup | indent
66+
"$BUILD_DIR/.heroku/python/bin/pip" install -r "$1/requirements-test.txt" --exists-action=w --src=./.heroku/src --disable-pip-version-check --no-cache-dir 2>&1 | cleanup | indent
6667
fi
6768
fi
6869
fi

bin/steps/pip-uninstall

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if [ ! "$SKIP_PIP_INSTALL" ]; then
2020

2121
if [[ -s .heroku/python/requirements-stale.txt ]]; then
2222
puts-step "Uninstalling stale dependencies"
23-
/app/.heroku/python/bin/pip uninstall -r .heroku/python/requirements-stale.txt -y --exists-action=w --disable-pip-version-check | cleanup | indent
23+
"$BUILD_DIR/.heroku/python/bin/pip" uninstall -r .heroku/python/requirements-stale.txt -y --exists-action=w --disable-pip-version-check | cleanup | indent
2424
fi
2525
fi
2626

bin/steps/pipenv

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if [[ -f Pipfile.lock ]]; then
1212
# Measure that we're using Pipenv.
1313
mcount "tool.pipenv"
1414

15-
# Don't skip installation of there are git deps.
15+
# Don't skip installation if there are git deps.
1616
if ! grep -q 'git' Pipfile.lock; then
1717
echo "Skipping installation, as Pipfile.lock hasn't changed since last deploy." | indent
1818

@@ -58,26 +58,25 @@ if [ ! "$SKIP_PIPENV_INSTALL" ]; then
5858
# Due to weird old pip behavior and pipenv behavior, pipenv upgrades pip
5959
# to latest if only --upgrade is specified. Specify upgrade strategy to
6060
# avoid this eager behavior.
61-
/app/.heroku/python/bin/pip install pipenv==$PIPENV_VERSION --upgrade --upgrade-strategy only-if-needed &> /dev/null
61+
"$BUILD_DIR/.heroku/python/bin/pip" install pipenv==$PIPENV_VERSION --upgrade --upgrade-strategy only-if-needed &> /dev/null
6262

6363
# Install the test dependencies, for CI.
6464
if [ "$INSTALL_TEST" ]; then
6565
puts-step "Installing test dependencies…"
66-
/app/.heroku/python/bin/pipenv install --dev --system --deploy 2>&1 | cleanup | indent
66+
"$BUILD_DIR/.heroku/python/bin/pipenv" install --dev --system --deploy 2>&1 | cleanup | indent
6767

6868
# Install the dependencies.
6969
elif [[ ! -f Pipfile.lock ]]; then
7070
puts-step "Installing dependencies with Pipenv $PIPENV_VERSION"
71-
/app/.heroku/python/bin/pipenv install --system --skip-lock 2>&1 | indent
72-
71+
"$BUILD_DIR/.heroku/python/bin/pipenv" install --system --skip-lock 2>&1 | indent
7372
else
7473
pipenv-to-pip Pipfile.lock > requirements.txt
7574
"$BIN_DIR/steps/pip-uninstall"
7675
cp requirements.txt .heroku/python/requirements-declared.txt
7776
openssl dgst -sha256 Pipfile.lock > .heroku/python/Pipfile.lock.sha256
7877

7978
puts-step "Installing dependencies with Pipenv $PIPENV_VERSION"
80-
/app/.heroku/python/bin/pipenv install --system --deploy 2>&1 | indent
79+
"$BUILD_DIR/.heroku/python/bin/pipenv" install --system --deploy 2>&1 | indent
8180
fi
8281
fi
8382
else

bin/steps/pipenv-python-version

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
# Detect Python-version with Pipenv.
44

5-
if [[ -f $BUILD_DIR/Pipfile ]]; then
5+
if [[ -f "$BUILD_DIR/Pipfile" ]]; then
66

7-
if [[ ! -f $BUILD_DIR/runtime.txt ]]; then
8-
if [[ ! -f $BUILD_DIR/Pipfile.lock ]]; then
7+
if [[ ! -f "$BUILD_DIR/runtime.txt" ]]; then
8+
if [[ ! -f "$BUILD_DIR/Pipfile.lock" ]]; then
99
puts-warn "No 'Pipfile.lock' found! We recommend you commit this into your repository."
1010
fi
11-
if [[ -f $BUILD_DIR/Pipfile.lock ]]; then
11+
if [[ -f "$BUILD_DIR/Pipfile.lock" ]]; then
1212
set +e
1313
PYTHON=$(jq -r '._meta.requires.python_full_version' "$BUILD_DIR/Pipfile.lock")
1414
if [[ "$PYTHON" != "null" ]]; then

0 commit comments

Comments
 (0)