forked from paketo-buildpacks/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish.sh
More file actions
executable file
·143 lines (109 loc) · 3.23 KB
/
publish.sh
File metadata and controls
executable file
·143 lines (109 loc) · 3.23 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
#!/usr/bin/env bash
set -eu
set -o pipefail
readonly ROOT_DIR="$(cd "$(dirname "${0}")/.." && pwd)"
readonly BIN_DIR="${ROOT_DIR}/.bin"
# 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 archive_path image_ref token
token=""
while [[ "${#}" != 0 ]]; do
case "${1}" in
--archive-path | -a)
archive_path="${2}"
shift 2
;;
--image-ref | -i)
image_ref="${2}"
shift 2
;;
--token | -t)
token="${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 "${image_ref:-}" ]]; then
usage
util::print::error "--image-ref is required"
fi
if [[ -z "${archive_path:-}" ]]; then
util::print::info "Using default archive path: ${ROOT_DIR}/build/buildpack-release-artifact.tgz"
archive_path="${ROOT_DIR}/build/buildpack-release-artifact.tgz"
else
archive_path="${archive_path}"
fi
repo::prepare
tools::install "${token}"
buildpack::publish "${image_ref}" "${archive_path}"
}
function usage() {
cat <<-USAGE
Publishes a composite buildpack to a registry.
OPTIONS
-a, --archive-path <filepath> Path to the buildpack release artifact (default: ${ROOT_DIR}/build/buildpack-release-artifact.tgz) (optional)
-h, --help Prints the command usage
-i, --image-ref <ref> List of image reference to publish to (required)
-t, --token <token> Token used to download assets from GitHub (e.g. jam, pack, etc) (optional)
USAGE
}
function repo::prepare() {
util::print::title "Preparing repo..."
mkdir -p "${BIN_DIR}"
export PATH="${BIN_DIR}:${PATH}"
}
function tools::install() {
local token
token="${1}"
util::tools::pack::install \
--directory "${BIN_DIR}" \
--token "${token}"
util::tools::yj::install \
--directory "${BIN_DIR}" \
--token "${token}"
}
function buildpack::publish() {
local image_ref archive_path tmp_dir
image_ref="${1}"
archive_path="${2}"
util::print::title "Publishing composite buildpack..."
util::print::info "Extracting archive..."
tmp_dir=$(mktemp -d -p $ROOT_DIR)
tar -xvf $archive_path -C $tmp_dir
util::print::info "Publishing buildpack to ${image_ref}"
current_dir=$(pwd)
cd $tmp_dir
# If package.toml has no targets we must specify one on the command line, otherwise pack will complain.
# This is here for backward compatibility but eventually all package.toml files should have targets defined.
targets=""
if cat package.toml | yj -tj | jq -r .targets | grep -q null; then
# Use the local architecture to support running locally and in CI, which will be linux/amd64 by default.
arch=$(util::tools::arch)
targets="--target linux/${arch}"
echo "package.toml has no targets so ${targets} will be used"
fi
pack \
buildpack package "${image_ref}" \
--config package.toml \
--format image \
--publish \
${targets}
cd $current_dir
rm -rf $tmp_dir
}
main "${@:-}"