Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions bin/compile

This file was deleted.

1 change: 1 addition & 0 deletions bin/compile
35 changes: 0 additions & 35 deletions bin/detect

This file was deleted.

1 change: 1 addition & 0 deletions bin/detect
29 changes: 0 additions & 29 deletions bin/finalize

This file was deleted.

1 change: 1 addition & 0 deletions bin/finalize
29 changes: 0 additions & 29 deletions bin/release

This file was deleted.

1 change: 1 addition & 0 deletions bin/release
50 changes: 50 additions & 0 deletions bin/ruby-run
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# Cloud Foundry Java Buildpack
# Copyright 2013-2020 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

$stdout.sync = true
$stderr.sync = true
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
require 'java_buildpack/buildpack'

case ARGV[0]
when "compile"
app_dir = ARGV[1]
JavaBuildpack::Buildpack.with_buildpack(app_dir, nil, nil, 'Compile failed with exception %s', &:compile)

when "detect"
app_dir = ARGV[1]
components = JavaBuildpack::Buildpack.with_buildpack(app_dir, nil, nil, 'Detect failed with exception %s',
&:detect).compact
if components.empty?
abort
else
str = components.join(' ')
puts str.length > 255 ? str.slice(0..251) + '...' : str
end

when "finalize"
app_dir = ARGV[1]
deps_dir = ARGV[3]
index = ARGV[4]
JavaBuildpack::Buildpack.with_buildpack(app_dir, deps_dir, index, 'Finalize failed with exception %s', &:compile)

when "release"
app_dir = ARGV[1]
output = JavaBuildpack::Buildpack.with_buildpack(app_dir, nil, nil, 'Release failed with exception %s', &:release)
puts output
end
109 changes: 109 additions & 0 deletions bin/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/usr/bin/env bash

set -e
set -u
set -o pipefail

BUILDPACK_DIR="$(cd "$(dirname "${0}")/.." && pwd)"
readonly BUILDPACK_DIR

RUBY_DIR="/tmp/ruby"
readonly RUBY_DIR

function util::config::lookup() {
sed '/^#/d' < "${BUILDPACK_DIR}/config/ruby.yml"
}

function util::cache::present() {
if [[ -e "${BUILDPACK_DIR}/resources/cache" ]]; then
return 0
else
return 1
fi
}

function util::index::lookup() {
local repository_root
repository_root="$(grep "repository_root" <<< "$(util::config::lookup)" | cut -d' ' -f2)"

local uri
uri="${repository_root}/index.yml"

if util::cache::present; then
local sha
sha="$(printf "%s" "${uri}" | shasum -a 256 | cut -d' ' -f1)"
cat "${BUILDPACK_DIR}/resources/cache/${sha}.cached"
else
curl -ssL "${uri}"
fi
}

function util::semver::parse() {
local version major minor patch
version="$(grep "version" <<< "$(util::config::lookup)" | cut -d' ' -f2)"
major="$(cut -d'.' -f1 <<< "${version}")"
minor="$(cut -d'.' -f2 <<< "${version}")"
patch="$(cut -d'.' -f3 <<< "${version}")"

printf "%s" "${major/+/*}\\.${minor/+/*}\\.${patch/+/*}"
}

function util::ruby::stream() {
local uri
uri="${1}"

if util::cache::present; then
local sha
sha="$(printf "%s" "${uri}" | shasum -a 256 | cut -d' ' -f1)"
cat "${BUILDPACK_DIR}/resources/cache/${sha}.cached"
else
curl -ssL "${uri}"
fi
}

function util::install() {
local index semver
index="$(util::index::lookup)"
semver="$(util::semver::parse)"

local uri
uri="$(grep "${semver}" <<< "${index}" | head -n 1 | awk '{print $2}')"

util::ruby::stream "${uri}" | tar xz -C "${RUBY_DIR}"
}

function util::print::error() {
local message red reset
message="${1}"
red="\033[0;31m"
reset="\033[0;39m"

echo -e "${red}${message}${reset}" >&2
exit 1
}

function util::environment::setup() {
export PATH="${RUBY_DIR}/bin:${PATH:-}"
export LIBRARY_PATH="${RUBY_DIR}/lib:${LIBRARY_PATH:-}"
export LD_LIBRARY_PATH="${RUBY_DIR}/lib:${LIBRARY_PATH:-}"
export CPATH="${RUBY_DIR}/include:${CPATH:-}"
}

function main() {
local phase
phase="$(basename "${0}")"

if [[ "${CF_STACK}" == "cflinuxfs4" ]]; then
if [[ ! -e "${RUBY_DIR}" ]]; then
mkdir -p "${RUBY_DIR}"

util::install
fi

util::environment::setup
fi

exec "${BUILDPACK_DIR}/bin/ruby-run" "${phase}" "${@-}"
}

main "${@:-}"
19 changes: 19 additions & 0 deletions config/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Cloud Foundry Java Buildpack
# Copyright 2013-2020 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Configuration for Ruby
---
version: 3.1.+
repository_root: https://raw.githubusercontent.com/cloudfoundry/ruby-buildpack/develop/java-index
2 changes: 1 addition & 1 deletion rakelib/dependency_cache_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def component_ids
offline_cache = offline_cache.split(',')
(conf << offline_cache).flatten!.uniq!
end
conf
conf << "ruby"
end

def component_configuration(component_id)
Expand Down