Skip to content

Commit

Permalink
Adds support for bionic and tiny stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
ForestEckhardt committed May 28, 2020
1 parent 2216570 commit e339091
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 124 deletions.
5 changes: 5 additions & 0 deletions buildpack.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ api = "0.2"
include_files = ["bin/run","bin/build","bin/detect","buildpack.toml"]
pre_package = "./scripts/build.sh"

[[stacks]]
id = "io.buildpacks.stacks.bionic"

[[stacks]]
id = "io.paketo.stacks.tiny"

[[stacks]]
id = "org.cloudfoundry.stacks.cflinuxfs3"
199 changes: 92 additions & 107 deletions scripts/.util/tools.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash

set -eu
set -o pipefail

Expand All @@ -18,118 +19,102 @@ function util::tools::path::export() {
fi
}

function util::tools::pack::install() {
local dir version os

util::print::title "Installing pack"

while [[ "${#}" != 0 ]]; do
case "${1}" in
--directory)
dir="${2}"
shift 2
;;

--version)
version="${2}"
shift 2
;;

*)
util::print::error "unknown argument \"${1}\""
esac
done

mkdir -p "${dir}"
util::tools::path::export "${dir}"

os="$(uname -s)"

if [[ "${os}" == "Darwin" ]]; then
os="macos"
elif [[ "${os}" == "Linux" ]]; then
os="linux"
else
util::print::error "Unsupported operating system"
fi

if [[ ! -f "${dir}/pack" ]]; then
util::print::info "--> installing..."
elif [[ "$("${dir}/pack" version | cut -d ' ' -f 1)" != *${version}* ]]; then
rm "${dir}/pack"
util::print::info "--> updating..."
else
util::print::info "--> skipping..."
return 0
fi

GIT_TOKEN="$(util::git::token::fetch)"

if [[ "${version}" == "latest" ]]; then
local url
if [[ "${os}" == "macos" ]]; then
url="$(
curl -s \
-H "Authorization: token ${GIT_TOKEN}" \
https://api.github.com/repos/buildpacks/pack/releases/latest \
| jq --raw-output '.assets[1] | .browser_download_url'
)"
else
url="$(
curl -s \
-H "Authorization: token ${GIT_TOKEN}" \
https://api.github.com/repos/buildpacks/pack/releases/latest \
| jq --raw-output '.assets[0] | .browser_download_url'
)"
fi
util::tools::pack::expand "${dir}" "${url}"
else
local tarball
tarball="pack-${version}-${os}.tar.gz"
url="https://github.com/buildpacks/pack/releases/download/v${version}/${tarball}"
util::tools::pack::expand "${dir}" "${url}"
fi
}

function util::tools::pack::expand() {
local dir url version
dir="${1}"
url="${2}"
tarball="$(echo "${url}" | sed "s/.*\///")"
version="v$(echo "${url}" | sed 's/pack-//' | sed 's/-.*//')"

curl --location --silent --output "${tarball}" "${url}"
tar xzf "${tarball}" -C "${dir}"
rm "${tarball}"
}

function util::tools::jam::install () {
local dir

while [[ "${#}" != 0 ]]; do
case "${1}" in
--directory)
dir="${2}"
shift 2
;;

*)
util::print::error "unknown argument \"${1}\""
esac
done

mkdir -p "${dir}"
util::tools::path::export "${dir}"
echo "-> Installing v0.0.10 jam..."

local dir
while [[ "${#}" != 0 ]]; do
case "${1}" in
--directory)
dir="${2}"
shift 2
;;

*)
util::print::error "unknown argument \"${1}\""
esac
done

local os
case "$(uname)" in
"Darwin")
os="darwin"
;;

"Linux")
os="linux"
;;

*)
echo "Unknown OS \"$(uname)\""
exit 1
esac

mkdir -p "${dir}"
util::tools::path::export "${dir}"

if [[ ! -f "${dir}/jam" ]]; then
local version
version="v0.0.10"

util::print::title "Installing jam ${version}"
curl "https://github.com/paketo-buildpacks/packit/releases/download/${version}/jam-${os}" \
--silent \
--location \
--output "${dir}/jam"
chmod +x "${dir}/jam"
fi
}

if [[ ! -f "${dir}/jam" ]]; then
util::print::title "Installing jam"
GOBIN="${dir}" go get github.com/paketo-buildpacks/packit/cargo/jam
fi
function util::tools::pack::install() {
local dir
while [[ "${#}" != 0 ]]; do
case "${1}" in
--directory)
dir="${2}"
shift 2
;;

*)
util::print::error "unknown argument \"${1}\""
esac
done

mkdir -p "${dir}"
util::tools::path::export "${dir}"

local os
case "$(uname)" in
"Darwin")
os="macos"
;;

"Linux")
os="linux"
;;

*)
echo "Unknown OS \"$(uname)\""
exit 1
esac

if [[ ! -f "${dir}/pack" ]]; then
local version
version="v0.10.0"

util::print::title "Installing pack ${version}"
curl "https://github.com/buildpacks/pack/releases/download/${version}/pack-v0.10.0-${os}.tgz" \
--silent \
--location \
--output /tmp/pack.tgz
tar xzf /tmp/pack.tgz -C "${dir}"
chmod +x "${dir}/pack"
rm /tmp/pack.tgz
fi
}

function util::tools::packager::install () {
local dir

while [[ "${#}" != 0 ]]; do
case "${1}" in
--directory)
Expand All @@ -147,6 +132,6 @@ function util::tools::packager::install () {

if [[ ! -f "${dir}/packager" ]]; then
util::print::title "Installing packager"
GOBIN="${dir}" go get github.com/cloudfoundry/libcfbuildpack/packager
GOBIN="${dir}" go install github.com/cloudfoundry/libcfbuildpack/packager
fi
}
49 changes: 34 additions & 15 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,46 @@ readonly PROGDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly BUILDPACKDIR="$(cd "${PROGDIR}/.." && pwd)"

function main() {
mkdir -p "${BUILDPACKDIR}/bin"
mkdir -p "${BUILDPACKDIR}/bin"

pushd "${BUILDPACKDIR}/bin" > /dev/null || return
printf "%s" "Building run..."
if [[ -f "${BUILDPACKDIR}/main.go" ]]; then
pushd "${BUILDPACKDIR}/bin" > /dev/null || return
printf "%s" "Building run..."

GOOS=linux \
go build \
-ldflags="-s -w" \
-o "run" \
"${BUILDPACKDIR}"
GOOS=linux \
go build \
-ldflags="-s -w" \
-o "run" \
"${BUILDPACKDIR}"

echo "Success!"
echo "Success!"

for name in detect build; do
printf "%s" "Linking ${name}..."
for name in detect build; do
printf "%s" "Linking ${name}..."

ln -sf "run" "${name}"
ln -sf "run" "${name}"

echo "Success!"
done
popd > /dev/null || return
echo "Success!"
done
popd > /dev/null || return
fi

if [[ -d "${BUILDPACKDIR}/cmd" ]]; then
local name
for src in "${BUILDPACKDIR}"/cmd/*; do
name="$(basename "${src}")"

printf "%s" "Building ${name}..."

GOOS="linux" \
go build \
-ldflags="-s -w" \
-o "${BUILDPACKDIR}/bin/${name}" \
"${src}/main.go"

echo "Success!"
done
fi
}

main "${@:-}"
3 changes: 1 addition & 2 deletions scripts/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ function main() {

function tools::install() {
util::tools::pack::install \
--directory "${BUILDPACKDIR}/.bin" \
--version "latest"
--directory "${BUILDPACKDIR}/.bin"

if [[ -f "${BUILDPACKDIR}/.packit" ]]; then
util::tools::jam::install \
Expand Down

0 comments on commit e339091

Please sign in to comment.