Skip to content

Commit 81b6980

Browse files
authored
Merge pull request kubernetes#87285 from joakimr-axis/joakimr-axis_release.sh
Fix shellcheck warnings/errors in /build/lib/release.sh
2 parents 7fe64cc + e05f8e6 commit 81b6980

File tree

2 files changed

+80
-69
lines changed

2 files changed

+80
-69
lines changed

build/lib/release.sh

Lines changed: 80 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,23 @@ function kube::release::parse_and_validate_ci_version() {
5656
kube::log::error "Invalid ci version: '${version}', must match regex ${version_regex}"
5757
return 1
5858
}
59+
60+
# The VERSION variables are used when this file is sourced, hence
61+
# the shellcheck SC2034 'appears unused' warning is to be ignored.
62+
63+
# shellcheck disable=SC2034
5964
VERSION_MAJOR="${BASH_REMATCH[1]}"
65+
# shellcheck disable=SC2034
6066
VERSION_MINOR="${BASH_REMATCH[2]}"
67+
# shellcheck disable=SC2034
6168
VERSION_PATCH="${BASH_REMATCH[3]}"
69+
# shellcheck disable=SC2034
6270
VERSION_PRERELEASE="${BASH_REMATCH[4]}"
71+
# shellcheck disable=SC2034
6372
VERSION_PRERELEASE_REV="${BASH_REMATCH[5]}"
73+
# shellcheck disable=SC2034
6474
VERSION_BUILD_INFO="${BASH_REMATCH[6]}"
75+
# shellcheck disable=SC2034
6576
VERSION_COMMITS="${BASH_REMATCH[7]}"
6677
}
6778

@@ -97,31 +108,30 @@ function kube::release::package_tarballs() {
97108
function kube::release::package_src_tarball() {
98109
local -r src_tarball="${RELEASE_TARS}/kubernetes-src.tar.gz"
99110
kube::log::status "Building tarball: src"
100-
if [[ "${KUBE_GIT_TREE_STATE-}" == "clean" ]]; then
111+
if [[ "${KUBE_GIT_TREE_STATE-}" = 'clean' ]]; then
101112
git archive -o "${src_tarball}" HEAD
102113
else
103-
local source_files=(
104-
$(cd "${KUBE_ROOT}" && find . -mindepth 1 -maxdepth 1 \
105-
-not \( \
106-
\( -path ./_\* -o \
107-
-path ./.git\* -o \
108-
-path ./.config\* -o \
109-
-path ./.gsutil\* \
110-
\) -prune \
111-
\))
112-
)
113-
"${TAR}" czf "${src_tarball}" --transform 's|^\.|kubernetes|' -C "${KUBE_ROOT}" "${source_files[@]}"
114+
find "${KUBE_ROOT}" -mindepth 1 -maxdepth 1 \
115+
! \( \
116+
\( -path "${KUBE_ROOT}"/_\* -o \
117+
-path "${KUBE_ROOT}"/.git\* -o \
118+
-path "${KUBE_ROOT}"/.config\* -o \
119+
-path "${KUBE_ROOT}"/.gsutil\* \
120+
\) -prune \
121+
\) -print0 \
122+
| "${TAR}" czf "${src_tarball}" --transform "s|${KUBE_ROOT#/*}|kubernetes|" --null -T -
114123
fi
115124
}
116125

117126
# Package up all of the cross compiled clients. Over time this should grow into
118127
# a full SDK
119128
function kube::release::package_client_tarballs() {
120129
# Find all of the built client binaries
121-
local platform platforms
122-
platforms=($(cd "${LOCAL_OUTPUT_BINPATH}" ; echo */*))
123-
for platform in "${platforms[@]}"; do
124-
local platform_tag=${platform/\//-} # Replace a "/" for a "-"
130+
for platform_long in "${LOCAL_OUTPUT_BINPATH}"/*/*; do
131+
local platform
132+
local platform_tag
133+
platform=${platform_long##${LOCAL_OUTPUT_BINPATH}/} # Strip LOCAL_OUTPUT_BINPATH
134+
platform_tag=${platform/\//-} # Replace a "/" for a "-"
125135
kube::log::status "Starting tarball: client $platform_tag"
126136

127137
(
@@ -130,7 +140,7 @@ function kube::release::package_client_tarballs() {
130140
mkdir -p "${release_stage}/client/bin"
131141

132142
local client_bins=("${KUBE_CLIENT_BINARIES[@]}")
133-
if [[ "${platform%/*}" == "windows" ]]; then
143+
if [[ "${platform%/*}" = 'windows' ]]; then
134144
client_bins=("${KUBE_CLIENT_BINARIES_WIN[@]}")
135145
fi
136146

@@ -155,16 +165,18 @@ function kube::release::package_client_tarballs() {
155165
function kube::release::package_node_tarballs() {
156166
local platform
157167
for platform in "${KUBE_NODE_PLATFORMS[@]}"; do
158-
local platform_tag=${platform/\//-} # Replace a "/" for a "-"
159-
local arch=$(basename "${platform}")
168+
local platform_tag
169+
local arch
170+
platform_tag=${platform/\//-} # Replace a "/" for a "-"
171+
arch=$(basename "${platform}")
160172
kube::log::status "Building tarball: node $platform_tag"
161173

162174
local release_stage="${RELEASE_STAGE}/node/${platform_tag}/kubernetes"
163175
rm -rf "${release_stage}"
164176
mkdir -p "${release_stage}/node/bin"
165177

166178
local node_bins=("${KUBE_NODE_BINARIES[@]}")
167-
if [[ "${platform%/*}" == "windows" ]]; then
179+
if [[ "${platform%/*}" = 'windows' ]]; then
168180
node_bins=("${KUBE_NODE_BINARIES_WIN[@]}")
169181
fi
170182
# This fancy expression will expand to prepend a path
@@ -178,7 +190,7 @@ function kube::release::package_node_tarballs() {
178190

179191
# Include the client binaries here too as they are useful debugging tools.
180192
local client_bins=("${KUBE_CLIENT_BINARIES[@]}")
181-
if [[ "${platform%/*}" == "windows" ]]; then
193+
if [[ "${platform%/*}" = 'windows' ]]; then
182194
client_bins=("${KUBE_CLIENT_BINARIES_WIN[@]}")
183195
fi
184196
# This fancy expression will expand to prepend a path
@@ -204,11 +216,14 @@ function kube::release::build_server_images() {
204216
rm -rf "${RELEASE_IMAGES}"
205217
local platform
206218
for platform in "${KUBE_SERVER_PLATFORMS[@]}"; do
207-
local platform_tag=${platform/\//-} # Replace a "/" for a "-"
208-
local arch=$(basename "${platform}")
219+
local platform_tag
220+
local arch
221+
platform_tag=${platform/\//-} # Replace a "/" for a "-"
222+
arch=$(basename "${platform}")
209223
kube::log::status "Building images: $platform_tag"
210224

211-
local release_stage="${RELEASE_STAGE}/server/${platform_tag}/kubernetes"
225+
local release_stage
226+
release_stage="${RELEASE_STAGE}/server/${platform_tag}/kubernetes"
212227
rm -rf "${release_stage}"
213228
mkdir -p "${release_stage}/server/bin"
214229

@@ -227,12 +242,15 @@ function kube::release::package_server_tarballs() {
227242
kube::release::build_server_images
228243
local platform
229244
for platform in "${KUBE_SERVER_PLATFORMS[@]}"; do
230-
local platform_tag=${platform/\//-} # Replace a "/" for a "-"
231-
local arch=$(basename "${platform}")
245+
local platform_tag
246+
local arch
247+
platform_tag=${platform/\//-} # Replace a "/" for a "-"
248+
arch=$(basename "${platform}")
232249
kube::log::status "Building tarball: server $platform_tag"
233250

234251
# NOTE: this directory was setup in kube::release::build_server_images
235-
local release_stage="${RELEASE_STAGE}/server/${platform_tag}/kubernetes"
252+
local release_stage
253+
release_stage="${RELEASE_STAGE}/server/${platform_tag}/kubernetes"
236254
mkdir -p "${release_stage}/addons"
237255

238256
# This fancy expression will expand to prepend a path
@@ -242,8 +260,9 @@ function kube::release::package_server_tarballs() {
242260
"${release_stage}/server/bin/"
243261

244262
# Include the client binaries here too as they are useful debugging tools.
245-
local client_bins=("${KUBE_CLIENT_BINARIES[@]}")
246-
if [[ "${platform%/*}" == "windows" ]]; then
263+
local client_bins
264+
client_bins=("${KUBE_CLIENT_BINARIES[@]}")
265+
if [[ "${platform%/*}" = 'windows' ]]; then
247266
client_bins=("${KUBE_CLIENT_BINARIES_WIN[@]}")
248267
fi
249268
# This fancy expression will expand to prepend a path
@@ -258,7 +277,8 @@ function kube::release::package_server_tarballs() {
258277

259278
kube::release::clean_cruft
260279

261-
local package_name="${RELEASE_TARS}/kubernetes-server-${platform_tag}.tar.gz"
280+
local package_name
281+
package_name="${RELEASE_TARS}/kubernetes-server-${platform_tag}.tar.gz"
262282
kube::release::create_tarball "${package_name}" "${release_stage}/.."
263283
done
264284
}
@@ -288,7 +308,8 @@ function kube::release::build_hyperkube_image() {
288308
ARCH="${arch}" REGISTRY="${registry}" VERSION="${version}" \
289309
make -C cluster/images/hyperkube/ build >/dev/null
290310

291-
local hyperkube_tag="${registry}/hyperkube-${arch}:${version}"
311+
local hyperkube_tag
312+
hyperkube_tag="${registry}/hyperkube-${arch}:${version}"
292313
if [[ -n "${save_dir}" ]]; then
293314
"${DOCKER[@]}" save "${hyperkube_tag}" > "${save_dir}/hyperkube-${arch}.tar"
294315
fi
@@ -305,7 +326,8 @@ function kube::release::build_conformance_image() {
305326
ARCH="${arch}" REGISTRY="${registry}" VERSION="${version}" \
306327
make -C cluster/images/conformance/ build >/dev/null
307328

308-
local conformance_tag="${registry}/conformance-${arch}:${version}"
329+
local conformance_tag
330+
conformance_tag="${registry}/conformance-${arch}:${version}"
309331
if [[ -n "${save_dir}" ]]; then
310332
"${DOCKER[@]}" save "${conformance_tag}" > "${save_dir}/conformance-${arch}.tar"
311333
fi
@@ -320,11 +342,14 @@ function kube::release::build_conformance_image() {
320342
function kube::release::create_docker_images_for_server() {
321343
# Create a sub-shell so that we don't pollute the outer environment
322344
(
323-
local binary_dir="$1"
324-
local arch="$2"
325-
local binary_name
326-
local binaries=($(kube::build::get_docker_wrapped_binaries "${arch}"))
327-
local images_dir="${RELEASE_IMAGES}/${arch}"
345+
local binary_dir
346+
local arch
347+
local binaries
348+
local images_dir
349+
binary_dir="$1"
350+
arch="$2"
351+
binaries=$(kube::build::get_docker_wrapped_binaries "${arch}")
352+
images_dir="${RELEASE_IMAGES}/${arch}"
328353
mkdir -p "${images_dir}"
329354

330355
# k8s.gcr.io is the constant tag in the docker archives, this is also the default for config scripts in GKE.
@@ -341,31 +366,26 @@ function kube::release::create_docker_images_for_server() {
341366
# provide `--pull` argument to `docker build` if `KUBE_BUILD_PULL_LATEST_IMAGES`
342367
# is set to y or Y; otherwise try to build the image without forcefully
343368
# pulling the latest base image.
344-
local DOCKER_BUILD_OPTS=()
369+
local docker_build_opts
370+
docker_build_opts=
345371
if [[ "${KUBE_BUILD_PULL_LATEST_IMAGES}" =~ [yY] ]]; then
346-
DOCKER_BUILD_OPTS+=("--pull")
372+
docker_build_opts='--pull'
347373
fi
348-
local -r docker_build_opts="${DOCKER_BUILD_OPTS[@]}"
349374

350-
for wrappable in "${binaries[@]}"; do
375+
for wrappable in $binaries; do
351376

352-
local oldifs=$IFS
353-
IFS=","
354-
set $wrappable
355-
IFS=$oldifs
356-
357-
local binary_name="$1"
358-
local base_image="$2"
359-
local docker_build_path="${binary_dir}/${binary_name}.dockerbuild"
360-
local docker_file_path="${docker_build_path}/Dockerfile"
377+
local binary_name=${wrappable%%,*}
378+
local base_image=${wrappable##*,}
361379
local binary_file_path="${binary_dir}/${binary_name}"
380+
local docker_build_path="${binary_file_path}.dockerbuild"
381+
local docker_file_path="${docker_build_path}/Dockerfile"
362382
local docker_image_tag="${docker_registry}/${binary_name}-${arch}:${docker_tag}"
363383

364384
kube::log::status "Starting docker build for image: ${binary_name}-${arch}"
365385
(
366386
rm -rf "${docker_build_path}"
367387
mkdir -p "${docker_build_path}"
368-
ln "${binary_dir}/${binary_name}" "${docker_build_path}/${binary_name}"
388+
ln "${binary_file_path}" "${docker_build_path}/${binary_name}"
369389
ln "${KUBE_ROOT}/build/nsswitch.conf" "${docker_build_path}/nsswitch.conf"
370390
chmod 0644 "${docker_build_path}/nsswitch.conf"
371391
cat <<EOF > "${docker_file_path}"
@@ -377,7 +397,7 @@ EOF
377397
echo "COPY nsswitch.conf /etc/" >> "${docker_file_path}"
378398
fi
379399

380-
"${DOCKER[@]}" build ${docker_build_opts} -q -t "${docker_image_tag}" "${docker_build_path}" >/dev/null
400+
"${DOCKER[@]}" build ${docker_build_opts:+"${docker_build_opts}"} -q -t "${docker_image_tag}" "${docker_build_path}" >/dev/null
381401
# If we are building an official/alpha/beta release we want to keep
382402
# docker images and tag them appropriately.
383403
local -r release_docker_image_tag="${KUBE_DOCKER_REGISTRY-$docker_registry}/${binary_name}-${arch}:${KUBE_DOCKER_IMAGE_TAG-$docker_tag}"
@@ -386,10 +406,10 @@ EOF
386406
"${DOCKER[@]}" rmi "${release_docker_image_tag}" 2>/dev/null || true
387407
"${DOCKER[@]}" tag "${docker_image_tag}" "${release_docker_image_tag}" 2>/dev/null
388408
fi
389-
"${DOCKER[@]}" save -o "${binary_dir}/${binary_name}.tar" "${docker_image_tag}" ${release_docker_image_tag}
390-
echo "${docker_tag}" > "${binary_dir}/${binary_name}.docker_tag"
409+
"${DOCKER[@]}" save -o "${binary_file_path}.tar" "${docker_image_tag}" "${release_docker_image_tag}"
410+
echo "${docker_tag}" > "${binary_file_path}.docker_tag"
391411
rm -rf "${docker_build_path}"
392-
ln "${binary_dir}/${binary_name}.tar" "${images_dir}/"
412+
ln "${binary_file_path}.tar" "${images_dir}/"
393413

394414
kube::log::status "Deleting docker image ${docker_image_tag}"
395415
"${DOCKER[@]}" rmi "${docker_image_tag}" &>/dev/null || true
@@ -433,25 +453,17 @@ function kube::release::package_kube_manifests_tarball() {
433453
cp "${src_dir}/kube-addon-manager.yaml" "${dst_dir}"
434454
cp "${src_dir}/glbc.manifest" "${dst_dir}"
435455
cp "${src_dir}/etcd-empty-dir-cleanup.yaml" "${dst_dir}/"
436-
local internal_manifest
437-
for internal_manifest in $(ls "${src_dir}" | grep "^internal-*"); do
438-
cp "${src_dir}/${internal_manifest}" "${dst_dir}"
439-
done
456+
find "${src_dir}" -name 'internal-*' -exec cp {} "${dst_dir}" \;
440457
cp "${KUBE_ROOT}/cluster/gce/gci/configure-helper.sh" "${dst_dir}/gci-configure-helper.sh"
441458
cp "${KUBE_ROOT}/cluster/gce/gci/configure-kubeapiserver.sh" "${dst_dir}/configure-kubeapiserver.sh"
442459
if [[ -e "${KUBE_ROOT}/cluster/gce/gci/gke-internal-configure-helper.sh" ]]; then
443460
cp "${KUBE_ROOT}/cluster/gce/gci/gke-internal-configure-helper.sh" "${dst_dir}/"
444461
fi
445462
cp "${KUBE_ROOT}/cluster/gce/gci/health-monitor.sh" "${dst_dir}/health-monitor.sh"
446-
local objects
447-
objects=$(cd "${KUBE_ROOT}/cluster/addons" && find . \( -name \*.yaml -or -name \*.yaml.in -or -name \*.json \) | grep -v demo)
448-
tar c -C "${KUBE_ROOT}/cluster/addons" ${objects} | tar x -C "${dst_dir}"
449463
# Merge GCE-specific addons with general purpose addons.
450-
local gce_objects
451-
gce_objects=$(cd "${KUBE_ROOT}/cluster/gce/addons" && find . \( -name \*.yaml -or -name \*.yaml.in -or -name \*.json \) \( -not -name \*demo\* \))
452-
if [[ -n "${gce_objects}" ]]; then
453-
tar c -C "${KUBE_ROOT}/cluster/gce/addons" ${gce_objects} | tar x -C "${dst_dir}"
454-
fi
464+
for d in cluster/addons cluster/gce/addons; do
465+
find "${KUBE_ROOT}/${d}" \( \( -name \*.yaml -o -name \*.yaml.in -o -name \*.json \) -a ! \( -name \*demo\* \) \) -print0 | tar c --transform "s|${KUBE_ROOT#/*}/${d}||" --null -T - | "${TAR}" x -C "${dst_dir}"
466+
done
455467

456468
kube::release::clean_cruft
457469

@@ -483,7 +495,7 @@ function kube::release::package_test_platform_tarballs() {
483495
mkdir -p "${release_stage}/test/bin"
484496

485497
local test_bins=("${KUBE_TEST_BINARIES[@]}")
486-
if [[ "${platform%/*}" == "windows" ]]; then
498+
if [[ "${platform%/*}" = 'windows' ]]; then
487499
test_bins=("${KUBE_TEST_BINARIES_WIN[@]}")
488500
fi
489501
# This fancy expression will expand to prepend a path

hack/.shellcheck_failures

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
./build/lib/release.sh
21
./cluster/gce/config-default.sh
32
./cluster/gce/config-test.sh
43
./cluster/gce/gci/configure-helper.sh

0 commit comments

Comments
 (0)