Fix the comments around the quote for compatibility, expansion etc.

This commit is contained in:
Dave Chen 2021-02-18 11:04:40 +08:00
parent 721da10205
commit be971ab549

View File

@ -136,32 +136,32 @@ build() {
base_image="" base_image=""
if [[ -f BASEIMAGE ]]; then if [[ -f BASEIMAGE ]]; then
base_image=$(getBaseImage "${os_arch}" | ${SED} "s|REGISTRY|${REGISTRY}|g") base_image=$(getBaseImage "${os_arch}" | "${SED}" "s|REGISTRY|${REGISTRY}|g")
${SED} -i "s|BASEARCH|${arch}|g" $dockerfile_name "${SED}" -i "s|BASEARCH|${arch}|g" $dockerfile_name
fi fi
# Only the cross-build on x86 is guaranteed by far, other arches like aarch64 doesn't support cross-build # Only the cross-build on x86 is guaranteed by far, other arches like aarch64 doesn't support cross-build
# thus, there is no need to tackle a disability feature on those platforms, and also help to prevent from # thus, there is no need to tackle a disability feature on those platforms, and also help to prevent from
# ending up a wrong image tag on non-amd64 platforms. # ending up a wrong image tag on non-amd64 platforms.
build_arch=$(uname -m) build_arch=$(uname -m)
if [[ ${build_arch} = "x86_64" ]]; then if [[ ${build_arch} = 'x86_64' ]]; then
# copy the qemu-*-static binary to docker image to build the multi architecture image on x86 platform # copy the qemu-*-static binary to docker image to build the multi architecture image on x86 platform
if grep -q "CROSS_BUILD_" Dockerfile; then if grep -q 'CROSS_BUILD_' Dockerfile; then
if [[ "${arch}" == "amd64" ]]; then if [[ "${arch}" = 'amd64' ]]; then
${SED} -i "/CROSS_BUILD_/d" Dockerfile "${SED}" -i '/CROSS_BUILD_/d' Dockerfile
else else
${SED} -i "s|QEMUARCH|${QEMUARCHS[$arch]}|g" Dockerfile "${SED}" -i "s|QEMUARCH|${QEMUARCHS[$arch]}|g" Dockerfile
# Register qemu-*-static for all supported processors except the current one # Register qemu-*-static for all supported processors except the current one
echo "Registering qemu-*-static binaries in the kernel" echo 'Registering qemu-*-static binaries in the kernel'
local sudo="" local sudo
if [[ $(id -u) != 0 ]]; then if [[ $(id -u) -ne 0 ]]; then
sudo=sudo sudo=sudo
fi fi
${sudo} "${KUBE_ROOT}/third_party/multiarch/qemu-user-static/register/register.sh" --reset -p yes ${sudo} "${KUBE_ROOT}/third_party/multiarch/qemu-user-static/register/register.sh" --reset -p yes
curl -sSL https://github.com/multiarch/qemu-user-static/releases/download/"${QEMUVERSION}"/x86_64_qemu-"${QEMUARCHS[$arch]}"-static.tar.gz | tar -xz -C "${temp_dir}" curl -sSL https://github.com/multiarch/qemu-user-static/releases/download/"${QEMUVERSION}"/x86_64_qemu-"${QEMUARCHS[$arch]}"-static.tar.gz | tar -xz -C "${temp_dir}"
# Ensure we don't get surprised by umask settings # Ensure we don't get surprised by umask settings
chmod 0755 "${temp_dir}/qemu-${QEMUARCHS[$arch]}-static" chmod 0755 "${temp_dir}/qemu-${QEMUARCHS[$arch]}-static"
${SED} -i "s/CROSS_BUILD_//g" Dockerfile "${SED}" -i 's/CROSS_BUILD_//g' Dockerfile
fi fi
fi fi
elif [[ "${QEMUARCHS[$arch]}" != "${build_arch}" ]]; then elif [[ "${QEMUARCHS[$arch]}" != "${build_arch}" ]]; then
@ -169,7 +169,7 @@ build() {
popd popd
continue continue
else else
${SED} -i "/CROSS_BUILD_/d" Dockerfile "${SED}" -i '/CROSS_BUILD_/d' Dockerfile
fi fi
docker buildx build --progress=plain --no-cache --pull --output=type="${output_type}" --platform "${os_name}/${arch}" \ docker buildx build --progress=plain --no-cache --pull --output=type="${output_type}" --platform "${os_name}/${arch}" \
@ -207,7 +207,7 @@ push() {
# reset manifest list; needed in case multiple images are being built / pushed. # reset manifest list; needed in case multiple images are being built / pushed.
manifest=() manifest=()
# Make os_archs list into image manifest. Eg: 'linux/amd64 linux/ppc64le' to '${REGISTRY}/${image}:${TAG}-linux-amd64 ${REGISTRY}/${image}:${TAG}-linux-ppc64le' # Make os_archs list into image manifest. Eg: 'linux/amd64 linux/ppc64le' to '${REGISTRY}/${image}:${TAG}-linux-amd64 ${REGISTRY}/${image}:${TAG}-linux-ppc64le'
while IFS='' read -r line; do manifest+=("$line"); done < <(echo "$os_archs" | ${SED} "s~\/~-~g" | ${SED} -e "s~[^ ]*~$REGISTRY\/$image:$TAG\-&~g") while IFS='' read -r line; do manifest+=("$line"); done < <(echo "$os_archs" | "${SED}" "s~\/~-~g" | "${SED}" -e "s~[^ ]*~$REGISTRY\/$image:$TAG\-&~g")
docker manifest create --amend "${REGISTRY}/${image}:${TAG}" "${manifest[@]}" docker manifest create --amend "${REGISTRY}/${image}:${TAG}" "${manifest[@]}"
# We will need the full registry name in order to set the "os.version" for Windows images. # We will need the full registry name in order to set the "os.version" for Windows images.