Skip to content

Commit

Permalink
Migrate functions from and remove hack/common.sh
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
  • Loading branch information
stevekuznetsov committed Jun 9, 2017
1 parent 34bd18b commit 56c46b0
Show file tree
Hide file tree
Showing 16 changed files with 404 additions and 392 deletions.
2 changes: 1 addition & 1 deletion .tito/lib/origin/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_os_git_vars():
for var in ["COMMIT", "VERSION", "MAJOR", "MINOR"]:
var_name = "OS_GIT_{}".format(var)
git_vars[var_name] = run_command(
"bash -c 'source ./hack/lib/init.sh; os::build::os_version_vars; echo ${}'".format(var_name)
"bash -c 'source ./hack/lib/init.sh; os::build::version::openshift_vars; echo ${}'".format(var_name)
)

# we hard-code this to a clean state as tito will have dirtied up the tree
Expand Down
9 changes: 9 additions & 0 deletions contrib/vagrant/provision-util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -435,3 +435,12 @@ os::provision::enable-overlay-storage() {

echo "${msg}"
}

os::build::get-bin-output-path() {
local os_root="${1:-}"

if [[ -n "${os_root}" ]]; then
os_root="${os_root}/"
fi
echo ${os_root}_output/local/bin/$(os::build::host_platform)
}
8 changes: 4 additions & 4 deletions hack/build-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ readonly OS_GOFLAGS_TAGS="include_gcs include_oss containers_image_openpgp"
# only works on Linux for now, all other platforms must build binaries themselves
if [[ -z "$@" ]]; then
if [[ "${OS_RELEASE:-}" != "n" ]] && \
os::build::detect_local_release_tars $(os::build::host_platform_friendly) >/dev/null; then
os::build::archive::detect_local_release_tars $(os::build::host_platform_friendly) >/dev/null; then
echo "++ Using release artifacts from ${OS_RELEASE_COMMIT} for ${platform} instead of building"
mkdir -p "${OS_OUTPUT_BINPATH}/${platform}"
os::build::extract_tar "${OS_PRIMARY_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/${platform}"
os::build::extract_tar "${OS_CLIENT_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/${platform}"
os::build::extract_tar "${OS_IMAGE_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/${platform}"
os::build::archive::extract_tar "${OS_PRIMARY_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/${platform}"
os::build::archive::extract_tar "${OS_CLIENT_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/${platform}"
os::build::archive::extract_tar "${OS_IMAGE_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/${platform}"

os::build::make_openshift_binary_symlinks

Expand Down
4 changes: 2 additions & 2 deletions hack/build-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ os::util::ensure::gopath_binary_exists imagebuilder
# image builds require RPMs to have been built
os::build::release::check_for_rpms
# OS_RELEASE_COMMIT is required by image-build
os::build::detect_local_release_tars $(os::build::host_platform_friendly)
os::build::archive::detect_local_release_tars $(os::build::host_platform_friendly)

# Without this, the dockerregistry lacks gcs+oss storage drivers in non-cross builds.
readonly OS_GOFLAGS_TAGS="include_gcs include_oss"
Expand All @@ -25,7 +25,7 @@ OS_BUILD_IMAGE_ARGS="${OS_BUILD_IMAGE_ARGS:-} -mount ${OS_OUTPUT_RPMPATH}/:/srv/
function ln_or_cp {
local src_file=$1
local dst_dir=$2
if os::build::is_hardlink_supported "${dst_dir}" ; then
if os::build::archive::internal::is_hardlink_supported "${dst_dir}" ; then
ln -f "${src_file}" "${dst_dir}"
else
cp -pf "${src_file}" "${dst_dir}"
Expand Down
2 changes: 1 addition & 1 deletion hack/build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ trap "os::build::environment::cleanup ${container}" EXIT
# Perform the build and release in Docker.
(
OS_GIT_TREE_STATE=clean # set this because we will be pulling from git archive
os::build::get_version_vars
os::build::version::get_vars
echo "++ Building release ${OS_GIT_VERSION}"
)
os::build::environment::withsource "${container}" "${OS_GIT_COMMIT:-HEAD}"
Expand Down
8 changes: 8 additions & 0 deletions hack/dind-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,14 @@ function build-image() {
popd > /dev/null
}

function os::build::get-bin-output-path() {
local os_root="${1:-}"

if [[ -n "${os_root}" ]]; then
os_root="${os_root}/"
fi
echo ${os_root}_output/local/bin/$(os::build::host_platform)
}

## Start of the main program

Expand Down
8 changes: 4 additions & 4 deletions hack/extract-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ source "$(dirname "${BASH_SOURCE}")/lib/init.sh"

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

mkdir -p "${OS_OUTPUT_BINPATH}/$(os::build::host_platform)"
os::build::extract_tar "${OS_PRIMARY_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/$(os::build::host_platform)"
os::build::extract_tar "${OS_CLIENT_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/$(os::build::host_platform)"
os::build::extract_tar "${OS_IMAGE_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/$(os::build::host_platform)"
os::build::archive::extract_tar "${OS_PRIMARY_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/$(os::build::host_platform)"
os::build::archive::extract_tar "${OS_CLIENT_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/$(os::build::host_platform)"
os::build::archive::extract_tar "${OS_IMAGE_RELEASE_TAR}" "${OS_OUTPUT_BINPATH}/$(os::build::host_platform)"

os::build::make_openshift_binary_symlinks
145 changes: 145 additions & 0 deletions hack/lib/build/archive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#!/bin/bash

# This library holds utility functions for archiving
# built binaries and releases.

function os::build::archive::name() {
echo "${OS_RELEASE_ARCHIVE}-${OS_GIT_VERSION}-$1" | tr '+' '-'
}
readonly -f os::build::archive::name

function os::build::archive::zip() {
local default_name
default_name="$( os::build::archive::name "${platform}" ).zip"
local archive_name="${archive_name:-$default_name}"
echo "++ Creating ${archive_name}"
for file in "$@"; do
pushd "${release_binpath}" &> /dev/null
sha256sum "${file}"
popd &>/dev/null
zip "${OS_OUTPUT_RELEASEPATH}/${archive_name}" -qj "${release_binpath}/${file}"
done
}
readonly -f os::build::archive::zip

function os::build::archive::tar() {
local base_name
base_name="$( os::build::archive::name "${platform}" )"
local default_name="${base_name}.tar.gz"
local archive_name="${archive_name:-$default_name}"
echo "++ Creating ${archive_name}"
pushd "${release_binpath}" &> /dev/null
find . -type f -exec sha256sum {} \;
if [[ -n "$(which bsdtar)" ]]; then
bsdtar -czf "${OS_OUTPUT_RELEASEPATH}/${archive_name}" -s ",^\.,${base_name}," $@
else
tar -czf --xattrs-exclude='LIBARCHIVE.xattr.security.selinux' "${OS_OUTPUT_RELEASEPATH}/${archive_name}" --transform="s,^\.,${base_name}," $@
fi
popd &>/dev/null
}
readonly -f os::build::archive::tar

# Checks if the filesystem on a partition that the provided path points to is
# supporting hard links.
#
# Input:
# $1 - the path where the hardlinks support test will be done.
# Returns:
# 0 - if hardlinks are supported
# non-zero - if hardlinks aren't supported
function os::build::archive::internal::is_hardlink_supported() {
local path="$1"
# Determine if FS supports hard links
local temp_file=$(TMPDIR="${path}" mktemp)
ln "${temp_file}" "${temp_file}.link" &> /dev/null && unlink "${temp_file}.link" || local supported=$?
rm -f "${temp_file}"
return ${supported:-0}
}
readonly -f os::build::archive::internal::is_hardlink_supported

# Extract a tar.gz compressed archive in a given directory. If the
# archive contains hardlinks and the underlying filesystem is not
# supporting hardlinks then the a hard dereference will be done.
#
# Input:
# $1 - path to archive file
# $2 - directory where the archive will be extracted
function os::build::archive::extract_tar() {
local archive_file="$1"
local change_dir="$2"

if [[ -z "${archive_file}" ]]; then
return 0
fi

local tar_flags="--strip-components=1"

# Unpack archive
echo "++ Extracting $(basename ${archive_file})"
if [[ "${archive_file}" == *.zip ]]; then
unzip -o "${archive_file}" -d "${change_dir}"
return 0
fi
if os::build::archive::internal::is_hardlink_supported "${change_dir}" ; then
# Ensure that tar won't try to set an owner when extracting to an
# nfs mount. Setting ownership on an nfs mount is likely to fail
# even for root.
local mount_type=$(df -P -T "${change_dir}" | tail -n +2 | awk '{print $2}')
if [[ "${mount_type}" = "nfs" ]]; then
tar_flags="${tar_flags} --no-same-owner"
fi
tar mxzf "${archive_file}" ${tar_flags} -C "${change_dir}"
else
local temp_dir=$(TMPDIR=/dev/shm/ mktemp -d)
tar mxzf "${archive_file}" ${tar_flags} -C "${temp_dir}"
pushd "${temp_dir}" &> /dev/null
tar cO --hard-dereference * | tar xf - -C "${change_dir}"
popd &>/dev/null
rm -rf "${temp_dir}"
fi
}
readonly -f os::build::archive::extract_tar

# os::build::archive::detect_local_release_tars verifies there is only one primary and one
# image binaries release tar in OS_OUTPUT_RELEASEPATH for the given platform specified by
# argument 1, exiting if more than one of either is found.
#
# If the tars are discovered, their full paths are exported to the following env vars:
#
# OS_PRIMARY_RELEASE_TAR
# OS_IMAGE_RELEASE_TAR
function os::build::archive::detect_local_release_tars() {
local platform="$1"

if [[ ! -d "${OS_OUTPUT_RELEASEPATH}" ]]; then
echo "There are no release artifacts in ${OS_OUTPUT_RELEASEPATH}"
return 2
fi
if [[ ! -f "${OS_OUTPUT_RELEASEPATH}/.commit" ]]; then
echo "There is no release .commit identifier ${OS_OUTPUT_RELEASEPATH}"
return 2
fi
local primary=$(find ${OS_OUTPUT_RELEASEPATH} -maxdepth 1 -type f -name openshift-origin-server-*-${platform}* \( -name *.tar.gz -or -name *.zip \))
if [[ $(echo "${primary}" | wc -l) -ne 1 || -z "${primary}" ]]; then
echo "There should be exactly one ${platform} server tar in $OS_OUTPUT_RELEASEPATH"
[[ -z "${WARN-}" ]] && return 2
fi

local client=$(find ${OS_OUTPUT_RELEASEPATH} -maxdepth 1 -type f -name openshift-origin-client-tools-*-${platform}* \( -name *.tar.gz -or -name *.zip \))
if [[ $(echo "${client}" | wc -l) -ne 1 || -z "${client}" ]]; then
echo "There should be exactly one ${platform} client tar in $OS_OUTPUT_RELEASEPATH"
[[ -n "${WARN-}" ]] || return 2
fi

local image=$(find ${OS_OUTPUT_RELEASEPATH} -maxdepth 1 -type f -name openshift-origin-image*-${platform}* \( -name *.tar.gz -or -name *.zip \))
if [[ $(echo "${image}" | wc -l) -ne 1 || -z "${image}" ]]; then
echo "There should be exactly one ${platform} image tar in $OS_OUTPUT_RELEASEPATH"
[[ -n "${WARN-}" ]] || return 2
fi

export OS_PRIMARY_RELEASE_TAR="${primary}"
export OS_IMAGE_RELEASE_TAR="${image}"
export OS_CLIENT_RELEASE_TAR="${client}"
export OS_RELEASE_COMMIT="$(cat ${OS_OUTPUT_RELEASEPATH}/.commit)"
}
readonly -f os::build::archive::detect_local_release_tars
Loading

0 comments on commit 56c46b0

Please sign in to comment.