-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add build environment validation checks
- Adds a warning if the Python buildpack has been run multiple times in the same build. - Adds a warning if an existing `.heroku/python/` directory is found in the app source. - Improves the error message shown if the buildpack is used on an unsupported stack. Previously the build would fail with a curl download error depending on the availability of assets on S3. This scenario can only happen outside of Heroku, or in an old buildpack is used with a brand new stack (eg for Heroku-26). The two warnings are the first step towards #1704 and #1710, and will be turned into errors in January 2025. Towards #1704 and #1710. GUS-W-17386432. GUS-W-17309709.
- Loading branch information
Showing
6 changed files
with
197 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#!/usr/bin/env bash | ||
|
||
function checks::ensure_supported_stack() { | ||
local stack="${1}" | ||
|
||
case "${stack}" in | ||
heroku-20 | heroku-22 | heroku-24) | ||
return 0 | ||
;; | ||
cedar* | heroku-16 | heroku-18) | ||
# This error will only ever be seen on non-Heroku environments, since the | ||
# Heroku build system rejects builds using EOL stacks. | ||
output::error <<-EOF | ||
Error: The '${stack}' stack is no longer supported. | ||
This buildpack no longer supports the '${stack}' stack since it has | ||
reached its end-of-life: | ||
https://devcenter.heroku.com/articles/stack#stack-support-details-for-apps-using-classic-buildpacks | ||
Upgrade to a newer stack to continue using this buildpack. | ||
EOF | ||
meta_set "failure_reason" "stack::eol" | ||
exit 1 | ||
;; | ||
*) | ||
output::error <<-EOF | ||
Error: The '${stack}' stack is not recognised. | ||
This buildpack does not recognise or support the '${stack}' stack. | ||
If '${stack}' is a valid stack, make sure that you are using the latest | ||
version of this buildpack and have not pinned to an older release: | ||
https://devcenter.heroku.com/articles/managing-buildpacks#view-your-buildpacks | ||
https://devcenter.heroku.com/articles/managing-buildpacks#classic-buildpacks-references | ||
EOF | ||
meta_set "failure_reason" "stack::unknown" | ||
exit 1 | ||
;; | ||
esac | ||
} | ||
|
||
# TODO: Turn this into an error in January 2025. | ||
function checks::warn_if_duplicate_python_buildpack() { | ||
local build_dir="${1}" | ||
|
||
# The check for the `PYTHONHOME` env var prevents this warning triggering in the case | ||
# where the Python install was committed to the Git repo (which will be handled later). | ||
# (The env var can only have come from the `export` file of an earlier buildpack, | ||
# since app provided config vars haven't been exported to the environment here.) | ||
if [[ -f "${build_dir}/.heroku/python/bin/python" && -v PYTHONHOME ]]; then | ||
output::warning <<-EOF | ||
Warning: The Python buildpack has already been run this build. | ||
An existing Python installation was found in the build directory | ||
from a buildpack run earlier in the build. | ||
This normally means there are duplicate Python buildpacks set | ||
on your app, which is not supported, can cause errors and | ||
slow down builds. | ||
Check the buildpacks set on your app and remove any duplicate | ||
Python buildpack entries: | ||
https://devcenter.heroku.com/articles/managing-buildpacks#view-your-buildpacks | ||
https://devcenter.heroku.com/articles/managing-buildpacks#remove-classic-buildpacks | ||
If you have a use-case that requires duplicate buildpacks, | ||
please comment on: | ||
https://github.com/heroku/heroku-buildpack-python/issues/1704 | ||
In January 2025 this warning will be made an error. | ||
EOF | ||
meta_set "duplicate_python_buildpack" "true" | ||
# shellcheck disable=SC2034 # This is used below until we make this check an error. | ||
DUPLICATE_PYTHON_BUILDPACK=1 | ||
fi | ||
} | ||
|
||
# TODO: Turn this into an error in January 2025. | ||
function checks::warn_if_existing_python_dir_present() { | ||
local build_dir="${1}" | ||
|
||
# Avoid warning twice in the case of duplicate buildpacks. | ||
# TODO: Remove this once `warn_if_duplicate_python_buildpack` becomes an error. | ||
if [[ -v DUPLICATE_PYTHON_BUILDPACK ]]; then | ||
return 0 | ||
fi | ||
|
||
# We use `-e` here to catch the case where `python` is a file rather than a directory. | ||
if [[ -e "${build_dir}/.heroku/python" ]]; then | ||
output::warning <<-EOF | ||
Warning: Existing '.heroku/python/' directory found. | ||
Your app's source code contains an existing directory named | ||
'.heroku/python/', which is where the Python buildpack needs | ||
to install its files. This existing directory contains: | ||
$(find .heroku/python/ -maxdepth 2 || true) | ||
Writing to internal locations used by the Python buildpack | ||
is not supported and can cause unexpected errors. | ||
If you have committed a '.heroku/python/' directory to your | ||
Git repo, you must delete it or use a different location. | ||
Otherwise, check that an earlier buildpack or 'bin/pre_compile' | ||
hook has not created this directory. | ||
If you have a use-case that requires writing to this location, | ||
please comment on: | ||
https://github.com/heroku/heroku-buildpack-python/issues/1704 | ||
In January 2025 this warning will be made an error. | ||
EOF | ||
meta_set "existing_python_dir" "true" | ||
fi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters