forked from paketo-buildpacks/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.sh
More file actions
executable file
·148 lines (111 loc) · 2.83 KB
/
package.sh
File metadata and controls
executable file
·148 lines (111 loc) · 2.83 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
set -e
set -u
set -o pipefail
readonly ROOT_DIR="$(cd "$(dirname "${0}")/.." && pwd)"
readonly BIN_DIR="${ROOT_DIR}/.bin"
readonly BUILD_DIR="${ROOT_DIR}/build"
# shellcheck source=SCRIPTDIR/.util/tools.sh
source "${ROOT_DIR}/scripts/.util/tools.sh"
# shellcheck source=SCRIPTDIR/.util/print.sh
source "${ROOT_DIR}/scripts/.util/print.sh"
function main {
local version output token flags
token=""
while [[ "${#}" != 0 ]]; do
case "${1}" in
--version|-v)
version="${2}"
shift 2
;;
--output|-o)
output="${2}"
shift 2
;;
--token|-t)
token="${2}"
shift 2
;;
--label)
flags+=("--label" "${2}")
shift 2
;;
--help|-h)
shift 1
usage
exit 0
;;
"")
# skip if the argument is empty
shift 1
;;
*)
util::print::error "unknown argument \"${1}\""
esac
done
if [[ -z "${version:-}" ]]; then
usage
echo
util::print::error "--version is required"
fi
if [[ -z "${output:-}" ]]; then
output="${BUILD_DIR}/buildpackage.cnb"
fi
repo::prepare
tools::install "${token}"
buildpack::archive "${version}"
buildpackage::create "${output}" "${flags[@]}"
}
function usage() {
cat <<-USAGE
package.sh --version <version> [OPTIONS]
Packages the buildpack into a buildpackage .cnb file.
OPTIONS
--help -h prints the command usage
--version <version> -v <version> specifies the version number to use when packaging the buildpack
--output <output> -o <output> location to output the packaged buildpackage artifact (default: ${ROOT_DIR}/build/buildpackage.cnb)
--token <token> Token used to download assets from GitHub (e.g. jam, pack, etc) (optional)
USAGE
}
function repo::prepare() {
util::print::title "Preparing repo..."
rm -rf "${BUILD_DIR}"
mkdir -p "${BIN_DIR}"
mkdir -p "${BUILD_DIR}"
export PATH="${BIN_DIR}:${PATH}"
}
function tools::install() {
local token
token="${1}"
util::tools::jam::install \
--directory "${BIN_DIR}" \
--token "${token}"
util::tools::pack::install \
--directory "${BIN_DIR}" \
--token "${token}"
}
function buildpack::archive() {
local version
version="${1}"
util::print::title "Packaging buildpack into ${BUILD_DIR}/buildpack.tgz..."
jam pack \
--buildpack "${ROOT_DIR}/buildpack.toml" \
--version "${version}" \
--offline \
--output "${BUILD_DIR}/buildpack.tgz"
}
function buildpackage::create() {
local output flags
output="${1}"
flags=("${@:2}")
util::print::title "Packaging buildpack..."
args=(
--config "${ROOT_DIR}/package.toml"
--format file
)
args+=("${flags[@]}")
pack \
buildpack package "${output}" \
"${args[@]}"
}
main "${@:-}"