mirror of https://github.com/k3s-io/k3s
Merge pull request #60923 from ipuustin/shell-bugfix5
Automatic merge from submit-queue (batch tested with PRs 60759, 60531, 60923, 60851, 58717). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Fix build scripts to work in case there are spaces in directory names. **What this PR does / why we need it**: Fix kubernetes build scripts to work in case the source directory is in a directory path which contains a space. You can prepare such a directory like this: ``` $ mkdir '/tmp/test dir/' $ cd '/tmp/test dir/' $ git clone https://github.com/kubernetes/kubernetes.git $ cd kubernetes ``` Then, without the fix: ``` $ KUBE_FASTBUILD=true KUBE_RELEASE_RUN_TESTS=n build/release.sh cat: /tmp/test: No such file or directory cat: dir/kubernetes/build/build-image/cross/VERSION: No such file or directory cat: /tmp/test: No such file or directory cat: dír/kubernetes/build/build-image/VERSION: No such file or directory +++ [0307 18:10:33] Verifying Prerequisites.... cp: target '/tmp/test dir/kubernetes/_output/images/kube-build:build-7c7cd10a18--/Dockerfile' is not a directory !!! [0307 18:10:33] Call tree: !!! [0307 18:10:33] 1: build/release.sh:35 kube::build::build_image(...) !!! Error in build/../build/common.sh:454 Error in build/../build/common.sh:454. '((i<3-1))' exited with status 1 Call stack: 1: build/../build/common.sh:454 kube::build::build_image(...) 2: build/release.sh:35 main(...) Exiting with status 1 ``` With the fix the compilation succeeds. The fix is done adding double quotes to required places (and also just in case to other places where shellcheck recommended adding them). Note that this fix doesn't as such help with the official make-based build: it's tricky to make makefiles work with targets with spaces in their names. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: **Special notes for your reviewer**: This PR needs pretty thorough review since this touches the core build scripts. **Release note**: ```release-note NONE ```pull/8/head
commit
9b8323f174
|
@ -29,13 +29,13 @@ DOCKER_MACHINE_NAME=${DOCKER_MACHINE_NAME:-"kube-dev"}
|
|||
readonly DOCKER_MACHINE_DRIVER=${DOCKER_MACHINE_DRIVER:-"virtualbox --virtualbox-cpu-count -1"}
|
||||
|
||||
# This will canonicalize the path
|
||||
KUBE_ROOT=$(cd $(dirname "${BASH_SOURCE}")/.. && pwd -P)
|
||||
KUBE_ROOT=$(cd "$(dirname "${BASH_SOURCE}")"/.. && pwd -P)
|
||||
|
||||
source "${KUBE_ROOT}/hack/lib/init.sh"
|
||||
|
||||
# Constants
|
||||
readonly KUBE_BUILD_IMAGE_REPO=kube-build
|
||||
readonly KUBE_BUILD_IMAGE_CROSS_TAG="$(cat ${KUBE_ROOT}/build/build-image/cross/VERSION)"
|
||||
readonly KUBE_BUILD_IMAGE_CROSS_TAG="$(cat "${KUBE_ROOT}/build/build-image/cross/VERSION")"
|
||||
|
||||
# This version number is used to cause everyone to rebuild their data containers
|
||||
# and build image. This is especially useful for automated build systems like
|
||||
|
@ -43,7 +43,7 @@ readonly KUBE_BUILD_IMAGE_CROSS_TAG="$(cat ${KUBE_ROOT}/build/build-image/cross/
|
|||
#
|
||||
# Increment/change this number if you change the build image (anything under
|
||||
# build/build-image) or change the set of volumes in the data container.
|
||||
readonly KUBE_BUILD_IMAGE_VERSION_BASE="$(cat ${KUBE_ROOT}/build/build-image/VERSION)"
|
||||
readonly KUBE_BUILD_IMAGE_VERSION_BASE="$(cat "${KUBE_ROOT}/build/build-image/VERSION")"
|
||||
readonly KUBE_BUILD_IMAGE_VERSION="${KUBE_BUILD_IMAGE_VERSION_BASE}-${KUBE_BUILD_IMAGE_CROSS_TAG}"
|
||||
|
||||
# Here we map the output directories across both the local and remote _output
|
||||
|
@ -232,7 +232,7 @@ function kube::build::prepare_docker_machine() {
|
|||
|
||||
docker-machine inspect "${DOCKER_MACHINE_NAME}" &> /dev/null || {
|
||||
kube::log::status "Creating a machine to build Kubernetes"
|
||||
docker-machine create --driver ${DOCKER_MACHINE_DRIVER} \
|
||||
docker-machine create --driver "${DOCKER_MACHINE_DRIVER}" \
|
||||
--virtualbox-memory "${virtualbox_memory_mb}" \
|
||||
--engine-env HTTP_PROXY="${KUBERNETES_HTTP_PROXY:-}" \
|
||||
--engine-env HTTPS_PROXY="${KUBERNETES_HTTPS_PROXY:-}" \
|
||||
|
@ -249,13 +249,13 @@ function kube::build::prepare_docker_machine() {
|
|||
local docker_machine_out
|
||||
while ! docker_machine_out=$(docker-machine env "${DOCKER_MACHINE_NAME}" 2>&1); do
|
||||
if [[ ${docker_machine_out} =~ "Error checking TLS connection" ]]; then
|
||||
echo ${docker_machine_out}
|
||||
echo "${docker_machine_out}"
|
||||
docker-machine regenerate-certs ${DOCKER_MACHINE_NAME}
|
||||
else
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
eval $(docker-machine env "${DOCKER_MACHINE_NAME}")
|
||||
eval "$(docker-machine env "${DOCKER_MACHINE_NAME}")"
|
||||
kube::log::status "A Docker host using docker-machine named '${DOCKER_MACHINE_NAME}' is ready to go!"
|
||||
return 0
|
||||
}
|
||||
|
@ -354,7 +354,7 @@ function kube::build::docker_image_exists() {
|
|||
function kube::build::docker_delete_old_images() {
|
||||
# In Docker 1.12, we can replace this with
|
||||
# docker images "$1" --format "{{.Tag}}"
|
||||
for tag in $("${DOCKER[@]}" images ${1} | tail -n +2 | awk '{print $2}') ; do
|
||||
for tag in $("${DOCKER[@]}" images "${1}" | tail -n +2 | awk '{print $2}') ; do
|
||||
if [[ "${tag}" != "${2}"* ]] ; then
|
||||
V=3 kube::log::status "Keeping image ${1}:${tag}"
|
||||
continue
|
||||
|
@ -434,7 +434,7 @@ function kube::build::clean() {
|
|||
kube::build::docker_delete_old_images "${KUBE_BUILD_IMAGE_REPO}" "${KUBE_BUILD_IMAGE_TAG_BASE}"
|
||||
|
||||
V=2 kube::log::status "Cleaning all untagged docker images"
|
||||
"${DOCKER[@]}" rmi $("${DOCKER[@]}" images -q --filter 'dangling=true') 2> /dev/null || true
|
||||
"${DOCKER[@]}" rmi "$("${DOCKER[@]}" images -q --filter 'dangling=true')" 2> /dev/null || true
|
||||
fi
|
||||
|
||||
if [[ -d "${LOCAL_OUTPUT_ROOT}" ]]; then
|
||||
|
@ -451,8 +451,8 @@ function kube::build::build_image() {
|
|||
|
||||
cp /etc/localtime "${LOCAL_OUTPUT_BUILD_CONTEXT}/"
|
||||
|
||||
cp ${KUBE_ROOT}/build/build-image/Dockerfile "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile"
|
||||
cp ${KUBE_ROOT}/build/build-image/rsyncd.sh "${LOCAL_OUTPUT_BUILD_CONTEXT}/"
|
||||
cp "${KUBE_ROOT}/build/build-image/Dockerfile" "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile"
|
||||
cp "${KUBE_ROOT}/build/build-image/rsyncd.sh" "${LOCAL_OUTPUT_BUILD_CONTEXT}/"
|
||||
dd if=/dev/urandom bs=512 count=1 2>/dev/null | LC_ALL=C tr -dc 'A-Za-z0-9' | dd bs=32 count=1 2>/dev/null > "${LOCAL_OUTPUT_BUILD_CONTEXT}/rsyncd.password"
|
||||
chmod go= "${LOCAL_OUTPUT_BUILD_CONTEXT}/rsyncd.password"
|
||||
|
||||
|
|
|
@ -67,9 +67,9 @@ function kube::release::parse_and_validate_ci_version() {
|
|||
# Build final release artifacts
|
||||
function kube::release::clean_cruft() {
|
||||
# Clean out cruft
|
||||
find ${RELEASE_STAGE} -name '*~' -exec rm {} \;
|
||||
find ${RELEASE_STAGE} -name '#*#' -exec rm {} \;
|
||||
find ${RELEASE_STAGE} -name '.DS*' -exec rm {} \;
|
||||
find "${RELEASE_STAGE}" -name '*~' -exec rm {} \;
|
||||
find "${RELEASE_STAGE}" -name '#*#' -exec rm {} \;
|
||||
find "${RELEASE_STAGE}" -name '.DS*' -exec rm {} \;
|
||||
}
|
||||
|
||||
function kube::release::package_tarballs() {
|
||||
|
@ -154,7 +154,7 @@ function kube::release::package_node_tarballs() {
|
|||
local platform
|
||||
for platform in "${KUBE_NODE_PLATFORMS[@]}"; do
|
||||
local platform_tag=${platform/\//-} # Replace a "/" for a "-"
|
||||
local arch=$(basename ${platform})
|
||||
local arch=$(basename "${platform}")
|
||||
kube::log::status "Building tarball: node $platform_tag"
|
||||
|
||||
local release_stage="${RELEASE_STAGE}/node/${platform_tag}/kubernetes"
|
||||
|
@ -198,7 +198,7 @@ function kube::release::package_server_tarballs() {
|
|||
local platform
|
||||
for platform in "${KUBE_SERVER_PLATFORMS[@]}"; do
|
||||
local platform_tag=${platform/\//-} # Replace a "/" for a "-"
|
||||
local arch=$(basename ${platform})
|
||||
local arch=$(basename "${platform}")
|
||||
kube::log::status "Building tarball: server $platform_tag"
|
||||
|
||||
local release_stage="${RELEASE_STAGE}/server/${platform_tag}/kubernetes"
|
||||
|
@ -280,7 +280,7 @@ function kube::release::create_docker_images_for_server() {
|
|||
local binary_dir="$1"
|
||||
local arch="$2"
|
||||
local binary_name
|
||||
local binaries=($(kube::build::get_docker_wrapped_binaries ${arch}))
|
||||
local binaries=($(kube::build::get_docker_wrapped_binaries "${arch}"))
|
||||
local images_dir="${RELEASE_IMAGES}/${arch}"
|
||||
mkdir -p "${images_dir}"
|
||||
|
||||
|
@ -325,16 +325,16 @@ function kube::release::create_docker_images_for_server() {
|
|||
|
||||
kube::log::status "Starting docker build for image: ${binary_name}-${arch}"
|
||||
(
|
||||
rm -rf ${docker_build_path}
|
||||
mkdir -p ${docker_build_path}
|
||||
ln ${binary_dir}/${binary_name} ${docker_build_path}/${binary_name}
|
||||
printf " FROM ${base_image} \n ADD ${binary_name} /usr/local/bin/${binary_name}\n" > ${docker_file_path}
|
||||
rm -rf "${docker_build_path}"
|
||||
mkdir -p "${docker_build_path}"
|
||||
ln "${binary_dir}/${binary_name}" "${docker_build_path}/${binary_name}"
|
||||
printf " FROM ${base_image} \n ADD ${binary_name} /usr/local/bin/${binary_name}\n" > "${docker_file_path}"
|
||||
|
||||
"${DOCKER[@]}" build --pull -q -t "${docker_image_tag}" ${docker_build_path} >/dev/null
|
||||
"${DOCKER[@]}" tag "${docker_image_tag}" ${deprecated_image_tag} >/dev/null
|
||||
"${DOCKER[@]}" save "${docker_image_tag}" ${deprecated_image_tag} > "${binary_dir}/${binary_name}.tar"
|
||||
echo "${docker_tag}" > ${binary_dir}/${binary_name}.docker_tag
|
||||
rm -rf ${docker_build_path}
|
||||
"${DOCKER[@]}" build --pull -q -t "${docker_image_tag}" "${docker_build_path}" >/dev/null
|
||||
"${DOCKER[@]}" tag "${docker_image_tag}" "${deprecated_image_tag}" >/dev/null
|
||||
"${DOCKER[@]}" save "${docker_image_tag}" "${deprecated_image_tag}" > "${binary_dir}/${binary_name}.tar"
|
||||
echo "${docker_tag}" > "${binary_dir}/${binary_name}.docker_tag"
|
||||
rm -rf "${docker_build_path}"
|
||||
ln "${binary_dir}/${binary_name}.tar" "${images_dir}/"
|
||||
|
||||
# If we are building an official/alpha/beta release we want to keep
|
||||
|
@ -350,8 +350,8 @@ function kube::release::create_docker_images_for_server() {
|
|||
else
|
||||
# not a release
|
||||
kube::log::status "Deleting docker image ${docker_image_tag}"
|
||||
"${DOCKER[@]}" rmi ${docker_image_tag} &>/dev/null || true
|
||||
"${DOCKER[@]}" rmi ${deprecated_image_tag} &>/dev/null || true
|
||||
"${DOCKER[@]}" rmi "${docker_image_tag}" &>/dev/null || true
|
||||
"${DOCKER[@]}" rmi "${deprecated_image_tag}" &>/dev/null || true
|
||||
fi
|
||||
) &
|
||||
done
|
||||
|
@ -434,7 +434,7 @@ function kube::release::package_test_tarball() {
|
|||
# Add the test image files
|
||||
mkdir -p "${release_stage}/test/images"
|
||||
cp -fR "${KUBE_ROOT}/test/images" "${release_stage}/test/"
|
||||
tar c ${KUBE_TEST_PORTABLE[@]} | tar x -C ${release_stage}
|
||||
tar c "${KUBE_TEST_PORTABLE[@]}" | tar x -C "${release_stage}"
|
||||
|
||||
kube::release::clean_cruft
|
||||
|
||||
|
|
Loading…
Reference in New Issue