Skip to content

Commit 58b6024

Browse files
authored
Stacks: Multi-arch implementation (#1055)
* adding the script files * adding github workflows * fix:lint errors
1 parent d0dfe4d commit 58b6024

8 files changed

Lines changed: 1620 additions & 341 deletions

File tree

stack/.github/workflows/create-release.yml

Lines changed: 1172 additions & 244 deletions
Large diffs are not rendered by default.

stack/.github/workflows/push-image.yml

Lines changed: 200 additions & 68 deletions
Large diffs are not rendered by default.

stack/.github/workflows/test-pull-request.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ jobs:
1818
- name: Checkout
1919
uses: actions/checkout@v3
2020

21+
# https://github.com/docker/setup-qemu-action
22+
- name: Set up QEMU
23+
uses: docker/setup-qemu-action@v3
24+
2125
- name: Create stack
2226
id: create-stack
2327
run: |
24-
scripts/create.sh
28+
./scripts/create.sh
2529
2630
- name: Run Acceptance Tests
2731
run: ./scripts/test.sh

stack/.github/workflows/update-github-config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Update shared github-config
22

33
on:
44
schedule:
5-
- cron: '44 3 * * *' # daily at 3:44 AM UTC
5+
- cron: '44 3 * * *' # daily at 3:44 AM UTC
66
workflow_dispatch: {}
77

88
concurrency: github_config_update

stack/scripts/create.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set -o pipefail
66
readonly PROG_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
77
readonly ROOT_DIR="$(cd "${PROG_DIR}/.." && pwd)"
88
readonly BIN_DIR="${ROOT_DIR}/.bin"
9-
readonly IMAGES_JSON="${ROOT_DIR}/stacks/images.json"
9+
readonly IMAGES_JSON="${ROOT_DIR}/images.json"
1010

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

7375
# if stack or build argument is provided but not both, then throw an error

stack/scripts/publish.sh

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
set -o pipefail
5+
6+
readonly PROG_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
readonly ROOT_DIR="$(cd "${PROG_DIR}/.." && pwd)"
8+
readonly BIN_DIR="${ROOT_DIR}/.bin"
9+
10+
# shellcheck source=SCRIPTDIR/.util/tools.sh
11+
source "${PROG_DIR}/.util/tools.sh"
12+
13+
# shellcheck source=SCRIPTDIR/.util/print.sh
14+
source "${PROG_DIR}/.util/print.sh"
15+
16+
if [[ $BASH_VERSINFO -lt 4 ]]; then
17+
util::print::error "Before running this script please update Bash to v4 or higher (e.g. on OSX: \$ brew install bash)"
18+
fi
19+
20+
function main() {
21+
local build_ref=()
22+
local run_ref=()
23+
local image_ref=()
24+
local build_archive=""
25+
local run_archive=""
26+
local image_archive=""
27+
28+
while [[ "${#}" != 0 ]]; do
29+
case "${1}" in
30+
--help|-h)
31+
shift 1
32+
usage
33+
exit 0
34+
;;
35+
36+
--build-ref)
37+
build_ref+=("${2}")
38+
shift 2
39+
;;
40+
41+
--run-ref)
42+
run_ref+=("${2}")
43+
shift 2
44+
;;
45+
46+
--build-archive)
47+
build_archive=${2}
48+
shift 2
49+
;;
50+
51+
--run-archive)
52+
run_archive=${2}
53+
shift 2
54+
;;
55+
56+
--image-ref)
57+
image_ref+=("${2}")
58+
shift 2
59+
;;
60+
61+
--image-archive)
62+
image_archive=${2}
63+
shift 2
64+
;;
65+
66+
"")
67+
# skip if the argument is empty
68+
shift 1
69+
;;
70+
71+
*)
72+
util::print::error "unknown argument \"${1}\""
73+
esac
74+
done
75+
76+
if [[ ${#image_ref[@]} != 0 || -n "$image_archive" ]]; then
77+
if ((${#image_ref[@]} == 0)); then
78+
util::print::error "--image-ref is required [Example: docker.io/paketobuildpacks/foo:latest]"
79+
fi
80+
81+
if [ -z "$image_archive" ]; then
82+
util::print::error "--image-archive is required [Example: ./path/to/image.oci]"
83+
fi
84+
else
85+
if ((${#build_ref[@]} == 0)); then
86+
util::print::error "--build-ref is required [Example: docker.io/paketobuildpacks/foo:latest]"
87+
fi
88+
89+
if ((${#run_ref[@]} == 0)); then
90+
util::print::error "--run-ref is required [Example: docker.io/paketobuildpacks/foo:1.0.0]"
91+
fi
92+
93+
if ((${#run_ref[@]} != ${#build_ref[@]})); then
94+
util::print::error "must have the same number of --build-ref and --run-ref arguments"
95+
fi
96+
97+
if [ -z "$build_archive" ]; then
98+
util::print::error "--build-archive is required [Example: ./path/to/build.oci]"
99+
fi
100+
101+
if [ -z "$run_archive" ]; then
102+
util::print::error "--run-archive is required [Example: ./path/to/run.oci]"
103+
fi
104+
fi
105+
106+
tools::install
107+
108+
if [[ ${#image_ref[@]} != 0 || -n "$image_archive" ]]; then
109+
stack::publish::image \
110+
"$image_archive" \
111+
"${#image_ref[@]}" \
112+
"${image_ref[@]}"
113+
else
114+
stack::publish \
115+
"$build_archive" \
116+
"$run_archive" \
117+
"${#build_ref[@]}" \
118+
"${build_ref[@]}" \
119+
"${#run_ref[@]}" \
120+
"${run_ref[@]}"
121+
fi
122+
}
123+
124+
function usage() {
125+
cat <<-USAGE
126+
publish.sh [OPTIONS]
127+
128+
Publishes the stack using the existing OCI image archives.
129+
130+
OPTIONS
131+
--build-ref list of build references to publish to [Required if --image-ref is not provided]
132+
--run-ref list of run references to publish to [Required if --image-ref is not provided]
133+
--build-archive path to the build OCI archive file [Required if --image-ref is not provided]
134+
--run-archive path to the run OCI archive file [Required if --image-ref is not provided]
135+
--image-ref list of image references to publish to [Required if --build-ref and --run-ref are not provided]
136+
--image-archive path to the image OCI archive file [Required if --build-ref and --run-ref are not provided]
137+
--help -h prints the command usage
138+
USAGE
139+
}
140+
141+
function tools::install() {
142+
util::tools::jam::install \
143+
--directory "${BIN_DIR}"
144+
}
145+
146+
function stack::publish() {
147+
local build_archive="$1"
148+
local run_archive="$2"
149+
150+
# bash can't easily pass arrays, they all get merged into one list of arguments
151+
# so we pass the lengths & extract the arrays from the single argument list
152+
local build_ref_len="$3" # length of build ref array
153+
local build_ref=("${@:4:$build_ref_len}") # pull out build_ref array
154+
local run_len_slot=$(( 4 + build_ref_len)) # location of run_ref length
155+
local run_ref_len="${*:$run_len_slot:1}" # length of run ref array
156+
local run_ref_slot=$(( 1 + run_len_slot)) # location of run_ref array
157+
local run_ref=("${@:$run_ref_slot:$run_ref_len}") # pull out run_ref array
158+
159+
# iterate over build_ref & run_ref, they will be the same length
160+
local len=${#build_ref[@]}
161+
for (( i=0; i<len; i++ )); do
162+
local br="${build_ref[$i]}"
163+
local rr="${run_ref[$i]}"
164+
args=(
165+
"--build-ref" "$br"
166+
"--run-ref" "$rr"
167+
"--build-archive" "$build_archive"
168+
"--run-archive" "$run_archive"
169+
)
170+
jam publish-stack "${args[@]}"
171+
done
172+
}
173+
174+
function stack::publish::image() {
175+
local image_archive="$1"
176+
177+
# bash can't easily pass arrays, they all get merged into one list of arguments
178+
# so we pass the lengths & extract the arrays from the single argument list
179+
local image_ref_len="$2" # length of image ref array
180+
local image_ref=("${@:3:$image_ref_len}") # pull out image_ref array
181+
182+
# iterate over image_ref
183+
local len=${#image_ref[@]}
184+
for (( i=0; i<len; i++ )); do
185+
local ir="${image_ref[$i]}"
186+
args=(
187+
"--image-ref" "$ir"
188+
"--image-archive" "$image_archive"
189+
)
190+
jam publish-image "${args[@]}"
191+
done
192+
}
193+
194+
main "${@:-}"

stack/scripts/receipts.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,7 @@ function receipts::generate::multi::arch() {
152152
fileName=$(basename ${runOutput})
153153
fi
154154

155-
if [ $imageArch = "amd64" ]; then
156-
imageReceipt="${dir}/${fileName}"
157-
else
158-
imageReceipt="${dir}/${imageArch}-${fileName}"
159-
fi
155+
imageReceipt="${dir}/${imageArch}-${fileName}"
160156

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

0 commit comments

Comments
 (0)