Skip to content

Commit 52661e3

Browse files
author
OpenShift Bot
authored
Merge pull request #14435 from stevekuznetsov/skuznets/bash-cleanup
Merged by openshift-bot
2 parents 279c084 + 56c46b0 commit 52661e3

23 files changed

+440
-427
lines changed

.tito/lib/origin/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_os_git_vars():
3434
for var in ["COMMIT", "VERSION", "MAJOR", "MINOR"]:
3535
var_name = "OS_GIT_{}".format(var)
3636
git_vars[var_name] = run_command(
37-
"bash -c 'source ./hack/lib/init.sh; os::build::os_version_vars; echo ${}'".format(var_name)
37+
"bash -c 'source ./hack/lib/init.sh; os::build::version::openshift_vars; echo ${}'".format(var_name)
3838
)
3939

4040
# we hard-code this to a clean state as tito will have dirtied up the tree

contrib/vagrant/provision-util.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,3 +435,12 @@ os::provision::enable-overlay-storage() {
435435

436436
echo "${msg}"
437437
}
438+
439+
os::build::get-bin-output-path() {
440+
local os_root="${1:-}"
441+
442+
if [[ -n "${os_root}" ]]; then
443+
os_root="${os_root}/"
444+
fi
445+
echo ${os_root}_output/local/bin/$(os::build::host_platform)
446+
}

hack/build-go.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ readonly OS_GOFLAGS_TAGS="include_gcs include_oss containers_image_openpgp"
1313
# only works on Linux for now, all other platforms must build binaries themselves
1414
if [[ -z "$@" ]]; then
1515
if [[ "${OS_RELEASE:-}" != "n" ]] && \
16-
os::build::detect_local_release_tars $(os::build::host_platform_friendly) >/dev/null; then
16+
os::build::archive::detect_local_release_tars $(os::build::host_platform_friendly) >/dev/null; then
1717
echo "++ Using release artifacts from ${OS_RELEASE_COMMIT} for ${platform} instead of building"
1818
mkdir -p "${OS_OUTPUT_BINPATH}/${platform}"
19-
os::build::extract_tar "${OS_PRIMARY_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/${platform}"
20-
os::build::extract_tar "${OS_CLIENT_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/${platform}"
21-
os::build::extract_tar "${OS_IMAGE_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/${platform}"
19+
os::build::archive::extract_tar "${OS_PRIMARY_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/${platform}"
20+
os::build::archive::extract_tar "${OS_CLIENT_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/${platform}"
21+
os::build::archive::extract_tar "${OS_IMAGE_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/${platform}"
2222

2323
os::build::make_openshift_binary_symlinks
2424

hack/build-images.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ os::util::ensure::gopath_binary_exists imagebuilder
1313
# image builds require RPMs to have been built
1414
os::build::release::check_for_rpms
1515
# OS_RELEASE_COMMIT is required by image-build
16-
os::build::detect_local_release_tars $(os::build::host_platform_friendly)
16+
os::build::archive::detect_local_release_tars $(os::build::host_platform_friendly)
1717

1818
# Without this, the dockerregistry lacks gcs+oss storage drivers in non-cross builds.
1919
readonly OS_GOFLAGS_TAGS="include_gcs include_oss"
@@ -25,7 +25,7 @@ OS_BUILD_IMAGE_ARGS="${OS_BUILD_IMAGE_ARGS:-} -mount ${OS_OUTPUT_RPMPATH}/:/srv/
2525
function ln_or_cp {
2626
local src_file=$1
2727
local dst_dir=$2
28-
if os::build::is_hardlink_supported "${dst_dir}" ; then
28+
if os::build::archive::internal::is_hardlink_supported "${dst_dir}" ; then
2929
ln -f "${src_file}" "${dst_dir}"
3030
else
3131
cp -pf "${src_file}" "${dst_dir}"

hack/build-release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ trap "os::build::environment::cleanup ${container}" EXIT
2424
# Perform the build and release in Docker.
2525
(
2626
OS_GIT_TREE_STATE=clean # set this because we will be pulling from git archive
27-
os::build::get_version_vars
27+
os::build::version::get_vars
2828
echo "++ Building release ${OS_GIT_VERSION}"
2929
)
3030
os::build::environment::withsource "${container}" "${OS_GIT_COMMIT:-HEAD}"

hack/dind-cluster.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,14 @@ function build-image() {
529529
os::build::image "${build_root}" "${image_name}"
530530
}
531531

532+
function os::build::get-bin-output-path() {
533+
local os_root="${1:-}"
534+
535+
if [[ -n "${os_root}" ]]; then
536+
os_root="${os_root}/"
537+
fi
538+
echo ${os_root}_output/local/bin/$(os::build::host_platform)
539+
}
532540

533541
## Start of the main program
534542

hack/extract-release.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ source "$(dirname "${BASH_SOURCE}")/lib/init.sh"
66

77
# Copy the release archives release back to the local _output/local/bin/... directories.
88
# NOTE: On Mac and Windows you must pass WARN=1 in order to extract the output.
9-
os::build::detect_local_release_tars $(os::build::host_platform_friendly)
9+
os::build::archive::detect_local_release_tars $(os::build::host_platform_friendly)
1010

1111
mkdir -p "${OS_OUTPUT_BINPATH}/$(os::build::host_platform)"
12-
os::build::extract_tar "${OS_PRIMARY_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/$(os::build::host_platform)"
13-
os::build::extract_tar "${OS_CLIENT_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/$(os::build::host_platform)"
14-
os::build::extract_tar "${OS_IMAGE_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/$(os::build::host_platform)"
12+
os::build::archive::extract_tar "${OS_PRIMARY_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/$(os::build::host_platform)"
13+
os::build::archive::extract_tar "${OS_CLIENT_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/$(os::build::host_platform)"
14+
os::build::archive::extract_tar "${OS_IMAGE_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/$(os::build::host_platform)"
1515

1616
os::build::make_openshift_binary_symlinks

hack/lib/build/archive.sh

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
#!/bin/bash
2+
3+
# This library holds utility functions for archiving
4+
# built binaries and releases.
5+
6+
function os::build::archive::name() {
7+
echo "${OS_RELEASE_ARCHIVE}-${OS_GIT_VERSION}-$1" | tr '+' '-'
8+
}
9+
readonly -f os::build::archive::name
10+
11+
function os::build::archive::zip() {
12+
local default_name
13+
default_name="$( os::build::archive::name "${platform}" ).zip"
14+
local archive_name="${archive_name:-$default_name}"
15+
echo "++ Creating ${archive_name}"
16+
for file in "$@"; do
17+
pushd "${release_binpath}" &> /dev/null
18+
sha256sum "${file}"
19+
popd &>/dev/null
20+
zip "${OS_OUTPUT_RELEASEPATH}/${archive_name}" -qj "${release_binpath}/${file}"
21+
done
22+
}
23+
readonly -f os::build::archive::zip
24+
25+
function os::build::archive::tar() {
26+
local base_name
27+
base_name="$( os::build::archive::name "${platform}" )"
28+
local default_name="${base_name}.tar.gz"
29+
local archive_name="${archive_name:-$default_name}"
30+
echo "++ Creating ${archive_name}"
31+
pushd "${release_binpath}" &> /dev/null
32+
find . -type f -exec sha256sum {} \;
33+
if [[ -n "$(which bsdtar)" ]]; then
34+
bsdtar -czf "${OS_OUTPUT_RELEASEPATH}/${archive_name}" -s ",^\.,${base_name}," $@
35+
else
36+
tar -czf --xattrs-exclude='LIBARCHIVE.xattr.security.selinux' "${OS_OUTPUT_RELEASEPATH}/${archive_name}" --transform="s,^\.,${base_name}," $@
37+
fi
38+
popd &>/dev/null
39+
}
40+
readonly -f os::build::archive::tar
41+
42+
# Checks if the filesystem on a partition that the provided path points to is
43+
# supporting hard links.
44+
#
45+
# Input:
46+
# $1 - the path where the hardlinks support test will be done.
47+
# Returns:
48+
# 0 - if hardlinks are supported
49+
# non-zero - if hardlinks aren't supported
50+
function os::build::archive::internal::is_hardlink_supported() {
51+
local path="$1"
52+
# Determine if FS supports hard links
53+
local temp_file=$(TMPDIR="${path}" mktemp)
54+
ln "${temp_file}" "${temp_file}.link" &> /dev/null && unlink "${temp_file}.link" || local supported=$?
55+
rm -f "${temp_file}"
56+
return ${supported:-0}
57+
}
58+
readonly -f os::build::archive::internal::is_hardlink_supported
59+
60+
# Extract a tar.gz compressed archive in a given directory. If the
61+
# archive contains hardlinks and the underlying filesystem is not
62+
# supporting hardlinks then the a hard dereference will be done.
63+
#
64+
# Input:
65+
# $1 - path to archive file
66+
# $2 - directory where the archive will be extracted
67+
function os::build::archive::extract_tar() {
68+
local archive_file="$1"
69+
local change_dir="$2"
70+
71+
if [[ -z "${archive_file}" ]]; then
72+
return 0
73+
fi
74+
75+
local tar_flags="--strip-components=1"
76+
77+
# Unpack archive
78+
echo "++ Extracting $(basename ${archive_file})"
79+
if [[ "${archive_file}" == *.zip ]]; then
80+
unzip -o "${archive_file}" -d "${change_dir}"
81+
return 0
82+
fi
83+
if os::build::archive::internal::is_hardlink_supported "${change_dir}" ; then
84+
# Ensure that tar won't try to set an owner when extracting to an
85+
# nfs mount. Setting ownership on an nfs mount is likely to fail
86+
# even for root.
87+
local mount_type=$(df -P -T "${change_dir}" | tail -n +2 | awk '{print $2}')
88+
if [[ "${mount_type}" = "nfs" ]]; then
89+
tar_flags="${tar_flags} --no-same-owner"
90+
fi
91+
tar mxzf "${archive_file}" ${tar_flags} -C "${change_dir}"
92+
else
93+
local temp_dir=$(TMPDIR=/dev/shm/ mktemp -d)
94+
tar mxzf "${archive_file}" ${tar_flags} -C "${temp_dir}"
95+
pushd "${temp_dir}" &> /dev/null
96+
tar cO --hard-dereference * | tar xf - -C "${change_dir}"
97+
popd &>/dev/null
98+
rm -rf "${temp_dir}"
99+
fi
100+
}
101+
readonly -f os::build::archive::extract_tar
102+
103+
# os::build::archive::detect_local_release_tars verifies there is only one primary and one
104+
# image binaries release tar in OS_OUTPUT_RELEASEPATH for the given platform specified by
105+
# argument 1, exiting if more than one of either is found.
106+
#
107+
# If the tars are discovered, their full paths are exported to the following env vars:
108+
#
109+
# OS_PRIMARY_RELEASE_TAR
110+
# OS_IMAGE_RELEASE_TAR
111+
function os::build::archive::detect_local_release_tars() {
112+
local platform="$1"
113+
114+
if [[ ! -d "${OS_OUTPUT_RELEASEPATH}" ]]; then
115+
echo "There are no release artifacts in ${OS_OUTPUT_RELEASEPATH}"
116+
return 2
117+
fi
118+
if [[ ! -f "${OS_OUTPUT_RELEASEPATH}/.commit" ]]; then
119+
echo "There is no release .commit identifier ${OS_OUTPUT_RELEASEPATH}"
120+
return 2
121+
fi
122+
local primary=$(find ${OS_OUTPUT_RELEASEPATH} -maxdepth 1 -type f -name openshift-origin-server-*-${platform}* \( -name *.tar.gz -or -name *.zip \))
123+
if [[ $(echo "${primary}" | wc -l) -ne 1 || -z "${primary}" ]]; then
124+
echo "There should be exactly one ${platform} server tar in $OS_OUTPUT_RELEASEPATH"
125+
[[ -z "${WARN-}" ]] && return 2
126+
fi
127+
128+
local client=$(find ${OS_OUTPUT_RELEASEPATH} -maxdepth 1 -type f -name openshift-origin-client-tools-*-${platform}* \( -name *.tar.gz -or -name *.zip \))
129+
if [[ $(echo "${client}" | wc -l) -ne 1 || -z "${client}" ]]; then
130+
echo "There should be exactly one ${platform} client tar in $OS_OUTPUT_RELEASEPATH"
131+
[[ -n "${WARN-}" ]] || return 2
132+
fi
133+
134+
local image=$(find ${OS_OUTPUT_RELEASEPATH} -maxdepth 1 -type f -name openshift-origin-image*-${platform}* \( -name *.tar.gz -or -name *.zip \))
135+
if [[ $(echo "${image}" | wc -l) -ne 1 || -z "${image}" ]]; then
136+
echo "There should be exactly one ${platform} image tar in $OS_OUTPUT_RELEASEPATH"
137+
[[ -n "${WARN-}" ]] || return 2
138+
fi
139+
140+
export OS_PRIMARY_RELEASE_TAR="${primary}"
141+
export OS_IMAGE_RELEASE_TAR="${image}"
142+
export OS_CLIENT_RELEASE_TAR="${client}"
143+
export OS_RELEASE_COMMIT="$(cat ${OS_OUTPUT_RELEASEPATH}/.commit)"
144+
}
145+
readonly -f os::build::archive::detect_local_release_tars

0 commit comments

Comments
 (0)