Skip to content

Commit

Permalink
Update github-config to 2fe8f56
Browse files Browse the repository at this point in the history
  • Loading branch information
paketo-bot authored and paketo-bot committed Aug 19, 2020
1 parent 721e41e commit d0f63b3
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 125 deletions.
18 changes: 9 additions & 9 deletions scripts/.util/git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ set -o pipefail
source "$(dirname "${BASH_SOURCE[0]}")/print.sh"

function util::git::token::fetch() {
if [[ -z "${GIT_TOKEN:-""}" ]]; then
util::print::title "Fetching GIT_TOKEN"
if [[ -z "${GIT_TOKEN:-""}" ]]; then
util::print::title "Fetching GIT_TOKEN"

GIT_TOKEN="$(
lpass show Shared-CF\ Buildpacks/concourse-private.yml \
| grep buildpacks-github-token \
| cut -d ' ' -f 2
)"
fi
GIT_TOKEN="$(
lpass show Shared-CF\ Buildpacks/concourse-private.yml \
| grep buildpacks-github-token \
| cut -d ' ' -f 2
)"
fi

printf "%s" "${GIT_TOKEN}"
printf "%s" "${GIT_TOKEN}"
}
18 changes: 10 additions & 8 deletions scripts/.util/tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ set -o pipefail
source "$(dirname "${BASH_SOURCE[0]}")/print.sh"

function util::tools::path::export() {
local dir
dir="${1}"
local dir
dir="${1}"

if ! echo "${PATH}" | grep -q "${dir}"; then
PATH="${dir}:$PATH"
export PATH
fi
if ! echo "${PATH}" | grep -q "${dir}"; then
PATH="${dir}:$PATH"
export PATH
fi
}

function util::tools::jam::install () {
Expand Down Expand Up @@ -119,14 +119,16 @@ function util::tools::packager::install () {

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

esac
done

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

if [[ ! -f "${dir}/packager" ]]; then
util::print::title "Installing packager"
GOBIN="${dir}" go get -u github.com/cloudfoundry/libcfbuildpack/packager
util::print::title "Installing packager"
GOBIN="${dir}" go get -u github.com/cloudfoundry/libcfbuildpack/packager
fi
}
99 changes: 67 additions & 32 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,53 +1,88 @@
#!/usr/bin/env bash

set -e
set -u
set -eu
set -o pipefail

readonly PROGDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly BUILDPACKDIR="$(cd "${PROGDIR}/.." && pwd)"

function main() {
mkdir -p "${BUILDPACKDIR}/bin"
while [[ "${#}" != 0 ]]; do
case "${1}" in
--help|-h)
shift 1
usage
exit 0
;;

if [[ -f "${BUILDPACKDIR}/run/main.go" ]]; then
pushd "${BUILDPACKDIR}/bin" > /dev/null || return
printf "%s" "Building run..."
"")
# skip if the argument is empty
shift 1
;;

GOOS=linux \
go build \
-ldflags="-s -w" \
-o "run" \
"${BUILDPACKDIR}/run"
*)
util::print::error "unknown argument \"${1}\""
esac
done

echo "Success!"
mkdir -p "${BUILDPACKDIR}/bin"

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

function usage() {
cat <<-USAGE
build.sh [OPTIONS]
Builds the buildpack executables.
OPTIONS
--help -h prints the command usage
USAGE
}

ln -sf "run" "${name}"
function run::build() {
if [[ -f "${BUILDPACKDIR}/run/main.go" ]]; then
pushd "${BUILDPACKDIR}/bin" > /dev/null || return
printf "%s" "Building run... "

echo "Success!"
done
popd > /dev/null || return
fi
GOOS=linux \
go build \
-ldflags="-s -w" \
-o "run" \
"${BUILDPACKDIR}/run"

echo "Success!"

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

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

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

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

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

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

echo "Success!"
done
fi
echo "Success!"
done
fi
}

main "${@:-}"
150 changes: 90 additions & 60 deletions scripts/integration.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 @@ -15,81 +16,110 @@ source "${PROGDIR}/.util/print.sh"
source "${PROGDIR}/.util/git.sh"

function main() {
if [[ ! -d "${BUILDPACKDIR}/integration" ]]; then
util::print::warn "** WARNING No Integration tests **"
fi

tools::install
images::pull
token::fetch
tests::run
while [[ "${#}" != 0 ]]; do
case "${1}" in
--help|-h)
shift 1
usage
exit 0
;;

"")
# skip if the argument is empty
shift 1
;;

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

if [[ ! -d "${BUILDPACKDIR}/integration" ]]; then
util::print::warn "** WARNING No Integration tests **"
fi

tools::install
images::pull
token::fetch
tests::run
}

function tools::install() {
util::tools::pack::install \
--directory "${BUILDPACKDIR}/.bin"
function usage() {
cat <<-USAGE
integration.sh [OPTIONS]
if [[ -f "${BUILDPACKDIR}/.packit" ]]; then
util::tools::jam::install \
--directory "${BUILDPACKDIR}/.bin"
Runs the integration test suite.
else
util::tools::packager::install \
--directory "${BUILDPACKDIR}/.bin"
fi
OPTIONS
--help -h prints the command usage
USAGE
}

function images::pull() {
local builder
builder=""
function tools::install() {
util::tools::pack::install \
--directory "${BUILDPACKDIR}/.bin"

if [[ -f "${BUILDPACKDIR}/integration.json" ]]; then
builder="$(jq -r .builder "${BUILDPACKDIR}/integration.json")"
fi
if [[ -f "${BUILDPACKDIR}/.packit" ]]; then
util::tools::jam::install \
--directory "${BUILDPACKDIR}/.bin"

if [[ "${builder}" == "null" || -z "${builder}" ]]; then
builder="index.docker.io/paketobuildpacks/builder:base"
fi
else
util::tools::packager::install \
--directory "${BUILDPACKDIR}/.bin"
fi
}

util::print::title "Pulling builder image..."
docker pull "${builder}"

util::print::title "Setting default pack builder image..."
pack set-default-builder "${builder}"

local run_image lifecycle_image
run_image="$(
docker inspect "${builder}" \
| jq -r '.[0].Config.Labels."io.buildpacks.builder.metadata"' \
| jq -r '.stack.runImage.image'
)"
lifecycle_image="index.docker.io/buildpacksio/lifecycle:$(
docker inspect "${builder}" \
| jq -r '.[0].Config.Labels."io.buildpacks.builder.metadata"' \
| jq -r '.lifecycle.version'
)"

util::print::title "Pulling run image..."
docker pull "${run_image}"

util::print::title "Pulling lifecycle image..."
docker pull "${lifecycle_image}"
function images::pull() {
local builder
builder=""

if [[ -f "${BUILDPACKDIR}/integration.json" ]]; then
builder="$(jq -r .builder "${BUILDPACKDIR}/integration.json")"
fi

if [[ "${builder}" == "null" || -z "${builder}" ]]; then
builder="index.docker.io/paketobuildpacks/builder:base"
fi

util::print::title "Pulling builder image..."
docker pull "${builder}"

util::print::title "Setting default pack builder image..."
pack set-default-builder "${builder}"

local run_image lifecycle_image
run_image="$(
docker inspect "${builder}" \
| jq -r '.[0].Config.Labels."io.buildpacks.builder.metadata"' \
| jq -r '.stack.runImage.image'
)"
lifecycle_image="index.docker.io/buildpacksio/lifecycle:$(
docker inspect "${builder}" \
| jq -r '.[0].Config.Labels."io.buildpacks.builder.metadata"' \
| jq -r '.lifecycle.version'
)"

util::print::title "Pulling run image..."
docker pull "${run_image}"

util::print::title "Pulling lifecycle image..."
docker pull "${lifecycle_image}"
}

function token::fetch() {
GIT_TOKEN="$(util::git::token::fetch)"
export GIT_TOKEN
GIT_TOKEN="$(util::git::token::fetch)"
export GIT_TOKEN
}

function tests::run() {
util::print::title "Run Buildpack Runtime Integration Tests"
pushd "${BUILDPACKDIR}" > /dev/null
if GOMAXPROCS="${GOMAXPROCS:-4}" go test -count=1 -timeout 0 ./integration/... -v -run Integration; then
util::print::success "** GO Test Succeeded **"
else
util::print::error "** GO Test Failed **"
fi
popd > /dev/null
util::print::title "Run Buildpack Runtime Integration Tests"
pushd "${BUILDPACKDIR}" > /dev/null
if GOMAXPROCS="${GOMAXPROCS:-4}" go test -count=1 -timeout 0 ./integration/... -v -run Integration; then
util::print::success "** GO Test Succeeded **"
else
util::print::error "** GO Test Failed **"
fi
popd > /dev/null
}

main "${@:-}"
Loading

0 comments on commit d0f63b3

Please sign in to comment.