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
1,416 changes: 1,172 additions & 244 deletions stack/.github/workflows/create-release.yml

Large diffs are not rendered by default.

268 changes: 200 additions & 68 deletions stack/.github/workflows/push-image.yml

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion stack/.github/workflows/test-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Create stack
id: create-stack
run: |
scripts/create.sh
./scripts/create.sh

- name: Run Acceptance Tests
run: ./scripts/test.sh
Expand Down
2 changes: 1 addition & 1 deletion stack/.github/workflows/update-github-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Update shared github-config

on:
schedule:
- cron: '44 3 * * *' # daily at 3:44 AM UTC
- cron: '44 3 * * *' # daily at 3:44 AM UTC
workflow_dispatch: {}

concurrency: github_config_update
Expand Down
6 changes: 4 additions & 2 deletions stack/scripts/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -o pipefail
readonly PROG_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly ROOT_DIR="$(cd "${PROG_DIR}/.." && pwd)"
readonly BIN_DIR="${ROOT_DIR}/.bin"
readonly IMAGES_JSON="${ROOT_DIR}/stacks/images.json"
readonly IMAGES_JSON="${ROOT_DIR}/images.json"

# shellcheck source=SCRIPTDIR/.util/tools.sh
source "${PROG_DIR}/.util/tools.sh"
Expand Down Expand Up @@ -67,7 +67,9 @@ function main() {
if [ -f "${IMAGES_JSON}" ]; then
# we need to copy images.json for inclusion in the build image
defaultStackPath=$(jq -r '.images[] | select(.name == "default") | .config_dir' "${IMAGES_JSON}")
cp $IMAGES_JSON $ROOT_DIR/$defaultStackPath/images.json
if [ -n "$defaultStackPath" ]; then
cp $IMAGES_JSON "${ROOT_DIR}/${defaultStackPath}/images.json"
fi
fi

# if stack or build argument is provided but not both, then throw an error
Expand Down
194 changes: 194 additions & 0 deletions stack/scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
#!/usr/bin/env bash

set -eu
set -o pipefail

readonly PROG_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly ROOT_DIR="$(cd "${PROG_DIR}/.." && pwd)"
readonly BIN_DIR="${ROOT_DIR}/.bin"

# shellcheck source=SCRIPTDIR/.util/tools.sh
source "${PROG_DIR}/.util/tools.sh"

# shellcheck source=SCRIPTDIR/.util/print.sh
source "${PROG_DIR}/.util/print.sh"

if [[ $BASH_VERSINFO -lt 4 ]]; then
util::print::error "Before running this script please update Bash to v4 or higher (e.g. on OSX: \$ brew install bash)"
fi

function main() {
local build_ref=()
local run_ref=()
local image_ref=()
local build_archive=""
local run_archive=""
local image_archive=""

while [[ "${#}" != 0 ]]; do
case "${1}" in
--help|-h)
shift 1
usage
exit 0
;;

--build-ref)
build_ref+=("${2}")
shift 2
;;

--run-ref)
run_ref+=("${2}")
shift 2
;;

--build-archive)
build_archive=${2}
shift 2
;;

--run-archive)
run_archive=${2}
shift 2
;;

--image-ref)
image_ref+=("${2}")
shift 2
;;

--image-archive)
image_archive=${2}
shift 2
;;

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

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

if [[ ${#image_ref[@]} != 0 || -n "$image_archive" ]]; then
if ((${#image_ref[@]} == 0)); then
util::print::error "--image-ref is required [Example: docker.io/paketobuildpacks/foo:latest]"
fi

if [ -z "$image_archive" ]; then
util::print::error "--image-archive is required [Example: ./path/to/image.oci]"
fi
else
if ((${#build_ref[@]} == 0)); then
util::print::error "--build-ref is required [Example: docker.io/paketobuildpacks/foo:latest]"
fi

if ((${#run_ref[@]} == 0)); then
util::print::error "--run-ref is required [Example: docker.io/paketobuildpacks/foo:1.0.0]"
fi

if ((${#run_ref[@]} != ${#build_ref[@]})); then
util::print::error "must have the same number of --build-ref and --run-ref arguments"
fi

if [ -z "$build_archive" ]; then
util::print::error "--build-archive is required [Example: ./path/to/build.oci]"
fi

if [ -z "$run_archive" ]; then
util::print::error "--run-archive is required [Example: ./path/to/run.oci]"
fi
fi

tools::install

if [[ ${#image_ref[@]} != 0 || -n "$image_archive" ]]; then
stack::publish::image \
"$image_archive" \
"${#image_ref[@]}" \
"${image_ref[@]}"
else
stack::publish \
"$build_archive" \
"$run_archive" \
"${#build_ref[@]}" \
"${build_ref[@]}" \
"${#run_ref[@]}" \
"${run_ref[@]}"
fi
}

function usage() {
cat <<-USAGE
publish.sh [OPTIONS]

Publishes the stack using the existing OCI image archives.

OPTIONS
--build-ref list of build references to publish to [Required if --image-ref is not provided]
--run-ref list of run references to publish to [Required if --image-ref is not provided]
--build-archive path to the build OCI archive file [Required if --image-ref is not provided]
--run-archive path to the run OCI archive file [Required if --image-ref is not provided]
--image-ref list of image references to publish to [Required if --build-ref and --run-ref are not provided]
--image-archive path to the image OCI archive file [Required if --build-ref and --run-ref are not provided]
--help -h prints the command usage
USAGE
}

function tools::install() {
util::tools::jam::install \
--directory "${BIN_DIR}"
}

function stack::publish() {
local build_archive="$1"
local run_archive="$2"

# bash can't easily pass arrays, they all get merged into one list of arguments
# so we pass the lengths & extract the arrays from the single argument list
local build_ref_len="$3" # length of build ref array
local build_ref=("${@:4:$build_ref_len}") # pull out build_ref array
local run_len_slot=$(( 4 + build_ref_len)) # location of run_ref length
local run_ref_len="${*:$run_len_slot:1}" # length of run ref array
local run_ref_slot=$(( 1 + run_len_slot)) # location of run_ref array
local run_ref=("${@:$run_ref_slot:$run_ref_len}") # pull out run_ref array

# iterate over build_ref & run_ref, they will be the same length
local len=${#build_ref[@]}
for (( i=0; i<len; i++ )); do
local br="${build_ref[$i]}"
local rr="${run_ref[$i]}"
args=(
"--build-ref" "$br"
"--run-ref" "$rr"
"--build-archive" "$build_archive"
"--run-archive" "$run_archive"
)
jam publish-stack "${args[@]}"
done
}

function stack::publish::image() {
local image_archive="$1"

# bash can't easily pass arrays, they all get merged into one list of arguments
# so we pass the lengths & extract the arrays from the single argument list
local image_ref_len="$2" # length of image ref array
local image_ref=("${@:3:$image_ref_len}") # pull out image_ref array

# iterate over image_ref
local len=${#image_ref[@]}
for (( i=0; i<len; i++ )); do
local ir="${image_ref[$i]}"
args=(
"--image-ref" "$ir"
"--image-archive" "$image_archive"
)
jam publish-image "${args[@]}"
done
}

main "${@:-}"
6 changes: 1 addition & 5 deletions stack/scripts/receipts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,7 @@ function receipts::generate::multi::arch() {
fileName=$(basename ${runOutput})
fi

if [ $imageArch = "amd64" ]; then
imageReceipt="${dir}/${fileName}"
else
imageReceipt="${dir}/${imageArch}-${fileName}"
fi
imageReceipt="${dir}/${imageArch}-${fileName}"

util::print::info "Generating CycloneDX package SBOM using syft for $archiveName on platform linux/$imageArch saved as $imageReceipt"

Expand Down
Loading
Loading