Skip to content

Commit

Permalink
Merge pull request #94 from heroku/function-detect
Browse files Browse the repository at this point in the history
update jvm-function-invoker detect for new project.toml schema changes
  • Loading branch information
Malax authored May 14, 2021
2 parents 668299f + 034c727 commit d0fa72c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions buildpacks/jvm-function-invoker/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
* `SF_FX_REMOTE_DEBUG` was renamed to `DEBUG_PORT` and also species the port on with the JDWP agent will listen on.
* Updated function runtime to `0.2.1`
* Update `bin/detect` to check for `type=function`.

## [0.2.7] 2021/05/05
### Changed
Expand Down
14 changes: 13 additions & 1 deletion buildpacks/jvm-function-invoker/bin/detect
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,21 @@ platform_dir="${1:?}"
# shellcheck disable=SC2034
build_plan="${2:?}"

# shellcheck disable=SC2164
bpDir="$(
cd "$(dirname "$0")/.."
pwd
)" # absolute path

# shellcheck source=SCRIPTDIR/../lib/toolbox.sh
source "${bpDir}/lib/toolbox.sh"

install_toolbox "/tmp/utils"
PATH="/tmp/utils/bin:$PATH"

# We check for a project.toml/function.toml to be able to distinguish between regular JVM applications and a function.
# Just from the application alone, they're indistinguishable by design.
if [[ -f "${app_dir}/function.toml" || -f "${app_dir}/project.toml" ]]; then
if [[ -f "${app_dir}/function.toml" || (-f "${app_dir}/project.toml" && $(yj -t <"${app_dir}/project.toml" | jq -r .com.salesforce.type) == "function") ]]; then
cat >"${build_plan}" <<-EOF
[[requires]]
name = "jdk"
Expand Down
37 changes: 37 additions & 0 deletions buildpacks/jvm-function-invoker/lib/toolbox.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

install_toolbox() {
local toolbox_dir=$1
local jqUrl="https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64"
local jqSha="c6b3a7d7d3e7b70c6f51b706a3b90bd01833846c54d32ca32f0027f00226ff6d"
local yjUrl="https://github.com/sclevine/yj/releases/download/v2.0/yj-linux"
local yjSha="db2b94b7fbf0941b6af9d30c1e7d43e41be62edad59d711b5c760ad5b13f7d6c"

mkdir -p "${toolbox_dir}/bin"

if [[ ! -f "${toolbox_dir}/bin/jq" ]]; then
local jqBin="${toolbox_dir}/bin/jq"
curl -o "$jqBin" -Ls "$jqUrl" && chmod +x "$jqBin"

local actualSha
actualSha="$(shasum -a 256 "${jqBin}" | awk '{ print $1 }')"

if [ "$actualSha" != "$jqSha" ]; then
echo "Invalid jq sha: $actualSha"
exit 1
fi
fi

if [[ ! -f "${toolbox_dir}/bin/yj" ]]; then
local yjBin="${toolbox_dir}/bin/yj"
curl -o "$yjBin" -Ls "$yjUrl" && chmod +x "$yjBin"

local actualSha
actualSha="$(shasum -a 256 "$yjBin" | awk '{ print $1 }')"

if [ "$actualSha" != "$yjSha" ]; then
echo "Invalid yj sha: $actualSha"
exit 1
fi
fi
}

0 comments on commit d0fa72c

Please sign in to comment.