Skip to content

Commit

Permalink
Refactor S3 asset URL handling
Browse files Browse the repository at this point in the history
Previously the buildpack's S3 bucket was defined in two places - once
in `VENDOR_URL` and again during the pip installation step. This
duplication was necessary since `VENDOR_URL` also contained the stack's
name, whereas the pip use-case used a non-stack-specific S3 key prefix.

In order to:
* reduce this duplication
* allow overriding of the URL for the pip use-case
* simplify this buildpack's S3 bucket migration (where we'll soon be
  needing the vary the bucket name and wouldn't want to have to
  duplicate that logic in multiple places)

...the `VENDOR_URL` variable has been replaced with `S3_BASE_URL` which
no longer contains the stack name.

The user-configurable override has similarly been renamed from
`BUILDPACK_VENDOR_URL` to `BUILDPACK_S3_BASE_URL`. Note: As before,
this override cannot be set via standard app variables (see #989).

Closes @W-8142401@.
  • Loading branch information
edmorley committed Sep 30, 2020
1 parent c550143 commit a24e289
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Replace `BUILDPACK_VENDOR_URL` and `USE_STAGING_BINARIES` with `BUILDPACK_S3_BASE_URL` (#1085).

## v181 (2020-09-29)

Expand Down
16 changes: 7 additions & 9 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,15 @@ ENV_DIR=$3
# Export Path variables, for use in sub-scripts.
export BUILD_DIR CACHE_DIR ENV_DIR

# Set the Buildpack's internet target for downloading Python distributions.
# The user can provide BUILDPACK_VENDOR_URL to specify a custom target.
# Set the base URL for downloading buildpack assets like Python runtimes.
# The user can provide BUILDPACK_S3_BASE_URL to specify a custom target.
# Note: this is designed for non-Heroku use, as it does not use the user-provided
# environment variable mechanism (the ENV_DIR).
VENDOR_URL="https://lang-python.s3.amazonaws.com/$STACK"
if [[ -n ${BUILDPACK_VENDOR_URL:-} ]]; then
VENDOR_URL="$BUILDPACK_VENDOR_URL"
elif [[ -n ${USE_STAGING_BINARIES} ]]; then
VENDOR_URL="$USE_STAGING_BINARIES/$STACK"
fi
export VENDOR_URL
DEFAULT_S3_BASE_URL='https://lang-python.s3.amazonaws.com'
S3_BASE_URL="${BUILDPACK_S3_BASE_URL:-${DEFAULT_S3_BASE_URL}}"
# This has to be exported since it's used by the geo-libs step which is run in a subshell.
# TODO: Stop exporting once the geo-libs step is removed or no longer uses `sub_env`.
export S3_BASE_URL

# Default Python Versions
# shellcheck source=bin/default_pythons
Expand Down
2 changes: 1 addition & 1 deletion bin/steps/gdal
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# This script is invoked by [`bin/compile`](/).

# The location of the pre-compiled cryptography binary.
VENDORED_GDAL="${VENDOR_URL}/libraries/vendor/gdal.tar.gz"
VENDORED_GDAL="${S3_BASE_URL}/${STACK}/libraries/vendor/gdal.tar.gz"

PKG_CONFIG_PATH="/app/.heroku/vendor/lib/pkgconfig:$PKG_CONFIG_PATH"

Expand Down
6 changes: 3 additions & 3 deletions bin/steps/geo-libs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
# This script is invoked by [`bin/compile`](/).

# The location of the pre-compiled cryptography binary.
VENDORED_GDAL="${VENDOR_URL}/libraries/vendor/gdal.tar.gz"
VENDORED_GEOS="${VENDOR_URL}/libraries/vendor/geos.tar.gz"
VENDORED_PROJ="${VENDOR_URL}/libraries/vendor/proj.tar.gz"
VENDORED_GDAL="${S3_BASE_URL}/${STACK}/libraries/vendor/gdal.tar.gz"
VENDORED_GEOS="${S3_BASE_URL}/${STACK}/libraries/vendor/geos.tar.gz"
VENDORED_PROJ="${S3_BASE_URL}/${STACK}/libraries/vendor/proj.tar.gz"

PKG_CONFIG_PATH="/app/.heroku/vendor/lib/pkgconfig:$PKG_CONFIG_PATH"

Expand Down
2 changes: 1 addition & 1 deletion bin/steps/pylibmc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if [[ "$STACK" != "cedar-14" ]]; then
fi

# The location of the pre-compiled libmemcached binary.
VENDORED_MEMCACHED="${VENDOR_URL}/libraries/vendor/libmemcache.tar.gz"
VENDORED_MEMCACHED="${S3_BASE_URL}/${STACK}/libraries/vendor/libmemcache.tar.gz"

# Syntax sugar.
# shellcheck source=bin/utils
Expand Down
4 changes: 2 additions & 2 deletions bin/steps/python
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runtime-fixer runtime.txt
PYTHON_VERSION=$(cat runtime.txt)

# The location of the pre-compiled python binary.
VENDORED_PYTHON="${VENDOR_URL}/runtimes/$PYTHON_VERSION.tar.gz"
VENDORED_PYTHON="${S3_BASE_URL}/${STACK}/runtimes/${PYTHON_VERSION}.tar.gz"

SECURITY_UPDATE="Python has released a security update! Please consider upgrading to"
SECURITY_UPDATE_PYPY="The PyPy project has released a security update! Please consider upgrading to"
Expand Down Expand Up @@ -160,7 +160,7 @@ fi
# Instead, we use the pip wheel to install itself, using the method described here:
# https://github.com/pypa/pip/issues/2351#issuecomment-69994524
PIP_WHEEL_FILENAME="pip-${PIP_VERSION}-py2.py3-none-any.whl"
PIP_WHEEL_URL="https://lang-python.s3.amazonaws.com/common/${PIP_WHEEL_FILENAME}"
PIP_WHEEL_URL="${S3_BASE_URL}/common/${PIP_WHEEL_FILENAME}"
PIP_WHEEL="${TMPDIR:-/tmp}/${PIP_WHEEL_FILENAME}"

if ! curl -sSf "${PIP_WHEEL_URL}" -o "$PIP_WHEEL"; then
Expand Down
2 changes: 1 addition & 1 deletion test/run-features
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ testHooks() {
PROFILE_PATH
PWD
PYTHONUNBUFFERED
S3_BASE_URL
SHLVL
SOME_APP_CONFIG_VAR
STACK
VENDOR_URL
)
if [[ "${STACK}" == "cedar-14" || "${STACK}" == "heroku-16" ]]; then
# Remove "OLDPWD" from expected_env_vars since for bash <4.4 it's not exported to subshells:
Expand Down

0 comments on commit a24e289

Please sign in to comment.