|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# This is technically redundant, since all consumers of this lib will have enabled these, |
| 4 | +# however, it helps Shellcheck realise the options under which these functions will run. |
| 5 | +set -euo pipefail |
| 6 | + |
| 7 | +openjdk::install_openjdk_via_jvm_common_buildpack() { |
| 8 | + local build_dir="${1}" |
| 9 | + # The install_openjdk function from the JVM common buildpack requires the path to the host buildpack to write to the |
| 10 | + # export script so that OpenJDK can be found by subsequent buildpacks. |
| 11 | + local host_buildpack_dir="${2}" |
| 12 | + |
| 13 | + # Legacy behaviour for customers and testing code can override the download location of the heroku/jvm buildpack |
| 14 | + # with JVM_COMMON_BUILDPACK for testing and debugging purposes. |
| 15 | + local jvm_common_buildpack_tarball_url="${JVM_COMMON_BUILDPACK:-https://buildpack-registry.s3.us-east-1.amazonaws.com/buildpacks/heroku/jvm.tgz}" |
| 16 | + |
| 17 | + local jvm_common_buildpack_tarball_path |
| 18 | + jvm_common_buildpack_tarball_path=$(mktemp) |
| 19 | + |
| 20 | + local jvm_common_buildpack_dir |
| 21 | + jvm_common_buildpack_dir=$(mktemp -d) |
| 22 | + |
| 23 | + curl --silent --fail --retry 3 --retry-connrefused --connect-timeout 5 --location "${jvm_common_buildpack_tarball_url}" -o "${jvm_common_buildpack_tarball_path}" |
| 24 | + tar -xzm --directory "${jvm_common_buildpack_dir}" --strip-components=1 "${jvm_common_buildpack_tarball_path}" |
| 25 | + |
| 26 | + # This script translates non-JDBC compliant DATABASE_URL (and similar) environment variables into their |
| 27 | + # JDBC compatible counterparts and writes them to "JDBC_" prefixed environment variables. We source this script |
| 28 | + # here to allow customers to connect to their databases via JDBC during the build. If no database environment |
| 29 | + # variables are present, this script does nothing. |
| 30 | + # shellcheck source=/dev/null |
| 31 | + source "${jvm_common_buildpack_dir}/opt/jdbc.sh" |
| 32 | + |
| 33 | + # shellcheck source=/dev/null |
| 34 | + source "${jvm_common_buildpack_dir}/bin/java" |
| 35 | + |
| 36 | + # See: https://github.com/heroku/heroku-buildpack-jvm-common/blob/main/bin/java |
| 37 | + install_openjdk "${build_dir}" "${host_buildpack_dir}" |
| 38 | +} |
0 commit comments