|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# This script is an integral part of the release workflow: .github/workflows/release.yml |
| 5 | +# It requires the following environment variables to function correctly: |
| 6 | +# |
| 7 | +# REQUESTED_BUILDPACK_ID - The ID of the buildpack to package and push to the container registry. |
| 8 | + |
| 9 | +while IFS="" read -r -d "" buildpack_toml_path; do |
| 10 | + buildpack_id="$(yj -t <"${buildpack_toml_path}" | jq -r .buildpack.id)" |
| 11 | + buildpack_version="$(yj -t <"${buildpack_toml_path}" | jq -r .buildpack.version)" |
| 12 | + buildpack_docker_repository="$(yj -t <"${buildpack_toml_path}" | jq -r .metadata.release.docker.repository)" |
| 13 | + buildpack_path=$(dirname "${buildpack_toml_path}") |
| 14 | + |
| 15 | + if [[ $buildpack_id == "${REQUESTED_BUILDPACK_ID}" ]]; then |
| 16 | + cnb_shim_tarball_url="https://github.com/heroku/cnb-shim/releases/download/v0.3/cnb-shim-v0.3.tgz" |
| 17 | + cnb_shim_tarball_sha256="109cfc01953cb04e69c82eec1c45c7c800bd57d2fd0eef030c37d8fc37a1cb4d" |
| 18 | + local_cnb_shim_tarball=$(mktemp) |
| 19 | + |
| 20 | + v2_buildpack_tarball_url="$(yj -t <"${buildpack_toml_path}" | jq -r ".metadata.shim.tarball // empty")" |
| 21 | + v2_buildpack_tarball_sha256="$(yj -t <"${buildpack_toml_path}" | jq -r ".metadata.shim.sha256 // empty")" |
| 22 | + local_v2_buildpack_tarball=$(mktemp) |
| 23 | + |
| 24 | + # If the buildpack has a V2 buildpack tarball in its metadata it's supposed to be a shimmed buildpack. |
| 25 | + # We download the shim and the V2 buildpack to the buildpack directory, turning it into a CNB. This |
| 26 | + # transformation is transparent for the code that follows after it. |
| 27 | + if [[ -n "${v2_buildpack_tarball_url:-}" ]]; then |
| 28 | + curl --retry 3 --location "${cnb_shim_tarball_url}" --output "${local_cnb_shim_tarball}" |
| 29 | + curl --retry 3 --location "${v2_buildpack_tarball_url}" --output "${local_v2_buildpack_tarball}" |
| 30 | + |
| 31 | + if ! echo "${cnb_shim_tarball_sha256} ${local_cnb_shim_tarball}" | sha256sum --check --status; then |
| 32 | + echo "Checksum verification of cnb_shim failed!" |
| 33 | + exit 1 |
| 34 | + fi |
| 35 | + |
| 36 | + if ! echo "${v2_buildpack_tarball_sha256} ${local_v2_buildpack_tarball}" | sha256sum --check --status; then |
| 37 | + echo "Checksum verification of V2 buildpack tarball failed!" |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | + |
| 41 | + mkdir -p "${buildpack_path}/target" |
| 42 | + tar -xzmf "${local_cnb_shim_tarball}" -C "${buildpack_path}" |
| 43 | + tar -xzmf "${local_v2_buildpack_tarball}" -C "${buildpack_path}/target" |
| 44 | + fi |
| 45 | + |
| 46 | + image_name="${buildpack_docker_repository}:${buildpack_version}" |
| 47 | + pack package-buildpack --config "${buildpack_path}/package.toml" --publish "${image_name}" |
| 48 | + |
| 49 | + echo "::set-output name=id::${buildpack_id}" |
| 50 | + echo "::set-output name=version::${buildpack_version}" |
| 51 | + echo "::set-output name=path::${buildpack_path}" |
| 52 | + echo "::set-output name=address::${buildpack_docker_repository}@$(crane digest "${image_name}")" |
| 53 | + exit 0 |
| 54 | + fi |
| 55 | +done < <(find . -name buildpack.toml -print0) |
| 56 | + |
| 57 | +echo "Could not find requested buildpack with id ${REQUESTED_BUILDPACK_ID}!" |
| 58 | +exit 1 |
0 commit comments