This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreceipts.sh
executable file
·107 lines (83 loc) · 2.46 KB
/
receipts.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env bash
set -eu
set -o pipefail
readonly PROG_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly STACK_DIR="$(cd "${PROG_DIR}/.." && pwd)"
readonly BIN_DIR="${STACK_DIR}/.bin"
readonly BUILD_DIR="${STACK_DIR}/build"
# shellcheck source=SCRIPTDIR/.util/tools.sh
source "${PROG_DIR}/.util/tools.sh"
# shellcheck source=SCRIPTDIR/.util/print.sh
source "${PROG_DIR}/.util/print.sh"
function main() {
local build run buildReceipt runReceipt
build="${BUILD_DIR}/build.oci"
run="${BUILD_DIR}/run.oci"
buildReceipt="${BUILD_DIR}/build-receipt.cyclonedx.json"
runReceipt="${BUILD_DIR}/run-receipt.cyclonedx.json"
while [[ "${#}" != 0 ]]; do
case "${1}" in
--help|-h)
shift 1
usage
exit 0
;;
--build-archive|-b)
build="${2}"
shift 2
;;
--run-archive|-r)
run="${2}"
shift 2
;;
--build-receipt|-B)
buildReceipt="${2}"
shift 2
;;
--run-receipt|-R)
runReceipt="${2}"
shift 2
;;
"")
# skip if the argument is empty
shift 1
;;
*)
util::print::error "unknown argument \"${1}\""
esac
done
tools::install
receipts::generate "${build}" "${buildReceipt}"
receipts::generate "${run}" "${runReceipt}"
util::print::success "Success! Receipts are:\n ${buildReceipt}\n ${runReceipt}\n"
}
function usage() {
cat <<-USAGE
receipts.sh [OPTIONS]
Generates receipts listing packages installed on build and run images of the
stack.
OPTIONS
--help -h prints the command usage
--build-archive -b path to OCI archive of build image. Defaults to
${BUILD_DIR}/build.oci
--run-archive -r path to OCI archive of build image
${BUILD_DIR}/run.oci
--build-receipt -B path to output build image package receipt. Defaults to
${BUILD_DIR}/build-receipt.txt
--run-receipt -R path to output run image package receipt. Defaults to
${BUILD_DIR}/run-receipt.txt
USAGE
}
function tools::install() {
util::tools::syft::install \
--directory "${BIN_DIR}"
}
function receipts::generate() {
local archive output hasDpkg
archive="${1}"
output="${2}"
util::print::title "Generating package SBOM for ${archive}"
util::print::info "Generating CycloneDX package SBOM using syft"
syft packages "${archive}" --output cyclonedx-json --file "${output}"
}
main "${@:-}"