Skip to content

Commit

Permalink
Add Dockerfile and update rpm spec for openshift e2e-aws tests
Browse files Browse the repository at this point in the history
Add build-rpms.sh scrip to build the cri-o rpm
that will be injected into the machine os content using the
Dockerfile to run the openshift e2e-aws test suite.

Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
  • Loading branch information
umohnani8 committed Jul 3, 2019
1 parent 0cd7f82 commit e0c1b7e
Show file tree
Hide file tree
Showing 17 changed files with 1,244 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contrib/test/ci/cri-o.spec
Expand Up @@ -32,7 +32,7 @@
%global service_name crio

Name: %{repo}
Version: 1.15
Version: 1.15.0
Release: 1.ci%{?dist}
Summary: Kubernetes Container Runtime Interface for OCI-based containers
License: ASL 2.0
Expand Down
66 changes: 66 additions & 0 deletions hack/build-rpms.sh
@@ -0,0 +1,66 @@
#!/usr/bin/env bash

# This script generates release zips and RPMs into _output/releases.
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"

os::util::ensure::system_binary_exists rpmbuild
os::util::ensure::system_binary_exists createrepo
os::build::rpm::get_nvra_vars

OS_RPM_SPECFILE="$( find "${OS_ROOT}" -name cri-o.spec )"
OS_RPM_NAME="$( rpmspec -q --qf '%{name}\n' "${OS_RPM_SPECFILE}" | head -1 )"

os::log::info "Building release RPMs for ${OS_RPM_SPECFILE} ..."

rpm_tmp_dir="${BASETMPDIR}/rpm"

ci_data="${OS_ROOT}/contrib/test/ci"
# RPM requires the spec file be owned by the invoking user
chown "$(id -u):$(id -g)" "${OS_RPM_SPECFILE}" || true

mkdir -p "${rpm_tmp_dir}/SOURCES"
tar czf "${rpm_tmp_dir}/SOURCES/${OS_RPM_NAME}-test.tar.gz" \
--owner=0 --group=0 \
--exclude=_output --exclude=.git --transform "s|^|${OS_RPM_NAME}-test/|rSH" \
.
cp -r "${ci_data}/." "${rpm_tmp_dir}/SOURCES"

yum-builddep -y "${OS_RPM_SPECFILE}"

rpmbuild -ba "${OS_RPM_SPECFILE}" \
--define "_sourcedir ${rpm_tmp_dir}/SOURCES" \
--define "_specdir ${rpm_tmp_dir}/SOURCES" \
--define "_rpmdir ${rpm_tmp_dir}/RPMS" \
--define "_srcrpmdir ${rpm_tmp_dir}/SRPMS" \
--define "_builddir ${rpm_tmp_dir}/BUILD" \
--define "version ${OS_RPM_VERSION}" \
--define "release ${OS_RPM_RELEASE}" \
--define "commit ${OS_GIT_COMMIT}" \
--define 'dist .el7' --define "_topdir ${rpm_tmp_dir}"

# migrate the rpm artifacts to the output directory, must be clean or move will fail
make clean
mkdir -p "${OS_OUTPUT}"

mkdir -p "${OS_OUTPUT_RPMPATH}"
mv -f "${rpm_tmp_dir}"/RPMS/*/*.rpm "${OS_OUTPUT_RPMPATH}"

mkdir -p "${OS_OUTPUT_RELEASEPATH}"
echo "${OS_GIT_COMMIT}" > "${OS_OUTPUT_RELEASEPATH}/.commit"

repo_path="$( os::util::absolute_path "${OS_OUTPUT_RPMPATH}" )"
createrepo "${repo_path}"

echo "[${OS_RPM_NAME}-local-release]
baseurl = file://${repo_path}
gpgcheck = 0
name = Release from Local Source for ${OS_RPM_NAME}
enabled = 1
" > "${repo_path}/local-release.repo"

# DEPRECATED: preserve until jobs migrate to using local-release.repo
cp "${repo_path}/local-release.repo" "${repo_path}/cri-o-local-release.repo"

os::log::info "Repository file for \`yum\` or \`dnf\` placed at ${repo_path}/local-release.repo
Install it with:
$ mv '${repo_path}/local-release.repo' '/etc/yum.repos.d"
66 changes: 66 additions & 0 deletions hack/lib/build/binaries.sh
@@ -0,0 +1,66 @@
#!/usr/bin/env bash

# This library holds utility functions for building
# and placing Golang binaries for multiple arches.

# Asks golang what it thinks the host platform is. The go tool chain does some
# slightly different things when the target platform matches the host platform.
function os::build::host_platform() {
echo "$(go env GOHOSTOS)/$(go env GOHOSTARCH)"
}
readonly -f os::build::host_platform

# os::build::setup_env will check that the `go` commands is available in
# ${PATH}. If not running on Travis, it will also check that the Go version is
# good enough for the Kubernetes build.
#
# Output Vars:
# export GOPATH - A modified GOPATH to our created tree along with extra
# stuff.
# export GOBIN - This is actively unset if already set as we want binaries
# placed in a predictable place.
function os::build::setup_env() {
os::util::ensure::system_binary_exists 'go'

if [[ -z "$(which sha256sum)" ]]; then
sha256sum() {
return 0
}
fi

# Travis continuous build uses a head go release that doesn't report
# a version number, so we skip this check on Travis. It's unnecessary
# there anyway.
if [[ "${TRAVIS:-}" != "true" ]]; then
os::golang::verify_go_version
fi
# For any tools that expect this to be set (it is default in golang 1.6),
# force vendor experiment.
export GO15VENDOREXPERIMENT=1

unset GOBIN

# create a local GOPATH in _output
GOPATH="${OS_OUTPUT}/go"
OS_TARGET_BIN="${OS_OUTPUT}/go/bin"
local go_pkg_dir="${GOPATH}/src/${OS_GO_PACKAGE}"
local go_pkg_basedir=$(dirname "${go_pkg_dir}")

mkdir -p "${go_pkg_basedir}"
rm -f "${go_pkg_dir}"

# TODO: This symlink should be relative.
ln -s "${OS_ROOT}" "${go_pkg_dir}"

# lots of tools "just don't work" unless we're in the GOPATH
cd "${go_pkg_dir}"

# Append OS_EXTRA_GOPATH to the GOPATH if it is defined.
if [[ -n ${OS_EXTRA_GOPATH:-} ]]; then
GOPATH="${GOPATH}:${OS_EXTRA_GOPATH}"
fi

export GOPATH
export OS_TARGET_BIN
}
readonly -f os::build::setup_env
70 changes: 70 additions & 0 deletions hack/lib/build/rpm.sh
@@ -0,0 +1,70 @@
#!/usr/bin/env bash

# This library holds utilities for building RPMs from Origin.

# os::build::rpm::generate_nevra_vars determines the NEVRA of the RPMs
# that would be built from the current git state.
#
# Globals:
# - OS_GIT_VERSION
# Arguments:
# - None
# Exports:
# - OS_RPM_VERSION
# - OS_RPM_RELEASE
# - OS_RPM_ARCHITECTURE
function os::build::rpm::get_nvra_vars() {
# the package name can be overwritten but is normally 'origin'
OS_RPM_ARCHITECTURE="$(uname -i)"

# we can extract the pacakge version from the build version
os::build::version::get_vars
if [[ "${OS_GIT_VERSION}" =~ ^v([0-9](\.[0-9]+)*)(.*) ]]; then
OS_RPM_VERSION="${BASH_REMATCH[1]}"
metadata="${BASH_REMATCH[3]}"
else
os::log::fatal "Malformed \$OS_GIT_VERSION: ${OS_GIT_VERSION}"
fi

# we can generate the package release from the git version metadata
# OS_GIT_VERSION will always have metadata, but either contain
# pre-release information _and_ build metadata, or only the latter.
# Build metadata may or may not contain the number of commits past
# the last tag. If no commit number exists, we are on a tag and use 0.
# ex.
# -alpha.0+shasums-123-dirty
# -alpha.0+shasums-123
# -alpha.0+shasums-dirty
# -alpha.0+shasums
# +shasums-123-dirty
# +shasums-123
# +shasums-dirty
# +shasums
if [[ "${metadata:0:1}" == "+" ]]; then
# we only have build metadata, but need to massage it so
# we can generate a valid RPM release from it
if [[ "${metadata}" =~ ^\+([a-z0-9]{7,40})(-([0-9]+))?(-dirty)?$ ]]; then
build_sha="${BASH_REMATCH[1]}"
build_num="${BASH_REMATCH[3]:-0}"
else
os::log::fatal "Malformed git version metadata: ${metadata}"
fi
OS_RPM_RELEASE="1.${build_num}.${build_sha}"
elif [[ "${metadata:0:1}" == "-" ]]; then
# we have both build metadata and pre-release info
if [[ "${metadata}" =~ ^-([^\+]+)\+([a-z0-9]{7,40})(-([0-9]+))?(-dirty)?$ ]]; then
pre_release="${BASH_REMATCH[1]}"
build_sha="${BASH_REMATCH[2]}"
build_num="${BASH_REMATCH[4]:-0}"
else
os::log::fatal "Malformed git version metadata: ${metadata}"
fi
OS_RPM_RELEASE="0.${pre_release}.${build_num}.${build_sha}"
else
os::log::fatal "Malformed git version metadata: ${metadata}"
fi

OS_RPM_GIT_VARS=$( os::build::version::save_vars | tr '\n' ' ' )

export OS_RPM_VERSION OS_RPM_RELEASE OS_RPM_ARCHITECTURE OS_RPM_GIT_VARS
}
88 changes: 88 additions & 0 deletions hack/lib/build/version.sh
@@ -0,0 +1,88 @@
#!/usr/bin/env bash

# This library holds utility functions for determining
# product versions from Git repository state.

# os::build::version::get_vars loads the standard version variables as
# ENV vars
function os::build::version::get_vars() {
if [[ -n "${OS_VERSION_FILE-}" ]]; then
if [[ -f "${OS_VERSION_FILE}" ]]; then
source "${OS_VERSION_FILE}"
return
fi
if [[ ! -d "${OS_ROOT}/.git" ]]; then
os::log::fatal "No version file at ${OS_VERSION_FILE}"
fi
os::log::warning "No version file at ${OS_VERSION_FILE}, falling back to git versions"
fi
os::build::version::git_vars
}
readonly -f os::build::version::get_vars

# os::build::version::git_vars looks up the current Git vars if they have not been calculated.
function os::build::version::git_vars() {
if [[ -n "${OS_GIT_VERSION-}" ]]; then
return 0
fi

local git=(git --work-tree "${OS_ROOT}")

if [[ -n ${OS_GIT_COMMIT-} ]] || OS_GIT_COMMIT=$("${git[@]}" rev-parse --short "HEAD^{commit}" 2>/dev/null); then
if [[ -z ${OS_GIT_TREE_STATE-} ]]; then
# Check if the tree is dirty. default to dirty
if git_status=$("${git[@]}" status --porcelain 2>/dev/null) && [[ -z ${git_status} ]]; then
OS_GIT_TREE_STATE="clean"
else
OS_GIT_TREE_STATE="dirty"
fi
fi
# Use git describe to find the version based on annotated tags.
if [[ -n ${OS_GIT_VERSION-} ]] || OS_GIT_VERSION=$("${git[@]}" describe --long --tags --abbrev=7 --match 'v[0-9]*' "${OS_GIT_COMMIT}^{commit}" 2>/dev/null); then
# Try to match the "git describe" output to a regex to try to extract
# the "major" and "minor" versions and whether this is the exact tagged
# version or whether the tree is between two tagged versions.
if [[ "${OS_GIT_VERSION}" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)(\.[0-9]+)*([-].*)?$ ]]; then
OS_GIT_MAJOR=${BASH_REMATCH[1]}
OS_GIT_MINOR=${BASH_REMATCH[2]}
OS_GIT_PATCH=${BASH_REMATCH[3]}
if [[ -n "${BASH_REMATCH[5]}" ]]; then
OS_GIT_MINOR+="+"
fi
fi

# This translates the "git describe" to an actual semver.org
# compatible semantic version that looks something like this:
# v1.1.0-alpha.0.6+84c76d1-345
OS_GIT_VERSION=$(echo "${OS_GIT_VERSION}" | sed "s/-\([0-9]\{1,\}\)-g\([0-9a-f]\{7,40\}\)$/\+\2-\1/")
# If this is an exact tag, remove the last segment.
OS_GIT_VERSION=$(echo "${OS_GIT_VERSION}" | sed "s/-0$//")
if [[ "${OS_GIT_TREE_STATE}" == "dirty" ]]; then
# git describe --dirty only considers changes to existing files, but
# that is problematic since new untracked .go files affect the build,
# so use our idea of "dirty" from git status instead.
OS_GIT_VERSION+="-dirty"
fi
fi
fi
}
readonly -f os::build::version::git_vars

# Saves the environment flags to $1
function os::build::version::save_vars() {
cat <<EOF
OS_GIT_COMMIT='${OS_GIT_COMMIT-}'
OS_GIT_TREE_STATE='${OS_GIT_TREE_STATE-}'
OS_GIT_VERSION='${OS_GIT_VERSION-}'
OS_GIT_MAJOR='${OS_GIT_MAJOR-}'
OS_GIT_MINOR='${OS_GIT_MINOR-}'
OS_GIT_PATCH='${OS_GIT_PATCH-}'
KUBE_GIT_MAJOR='${KUBE_GIT_MAJOR-}'
KUBE_GIT_MINOR='${KUBE_GIT_MINOR-}'
KUBE_GIT_COMMIT='${KUBE_GIT_COMMIT-}'
KUBE_GIT_VERSION='${KUBE_GIT_VERSION-}'
ETCD_GIT_VERSION='${ETCD_GIT_VERSION-}'
ETCD_GIT_COMMIT='${ETCD_GIT_COMMIT-}'
EOF
}
readonly -f os::build::version::save_vars
14 changes: 14 additions & 0 deletions hack/lib/constants.sh
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# This script provides constants for the Golang binary build process

readonly OS_OUTPUT_BASEPATH="${OS_OUTPUT_BASEPATH:-_output}"
readonly OS_BASE_OUTPUT="${OS_ROOT}/${OS_OUTPUT_BASEPATH}"
readonly OS_OUTPUT_SCRIPTPATH="${OS_OUTPUT_SCRIPTPATH:-"${OS_BASE_OUTPUT}/scripts"}"

readonly OS_OUTPUT_SUBPATH="${OS_OUTPUT_SUBPATH:-${OS_OUTPUT_BASEPATH}/local}"
readonly OS_OUTPUT="${OS_ROOT}/${OS_OUTPUT_SUBPATH}"
readonly OS_OUTPUT_RELEASEPATH="${OS_OUTPUT}/releases"
readonly OS_OUTPUT_RPMPATH="${OS_OUTPUT_RELEASEPATH}/rpms"
readonly OS_OUTPUT_BINPATH="${OS_OUTPUT}/bin"
readonly OS_OUTPUT_PKGDIR="${OS_OUTPUT}/pkgdir"
65 changes: 65 additions & 0 deletions hack/lib/init.sh
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

# This script is meant to be the entrypoint for OpenShift Bash scripts to import all of the support
# libraries at once in order to make Bash script preambles as minimal as possible. This script recur-
# sively `source`s *.sh files in this directory tree. As such, no files should be `source`ed outside
# of this script to ensure that we do not attempt to overwrite read-only variables.

set -o errexit
set -o nounset
set -o pipefail

OS_SCRIPT_START_TIME="$( date +%s )"; export OS_SCRIPT_START_TIME

# os::util::absolute_path returns the absolute path to the directory provided
function os::util::absolute_path() {
local relative_path="$1"
local absolute_path

pushd "${relative_path}" >/dev/null
relative_path="$( pwd )"
if [[ -h "${relative_path}" ]]; then
absolute_path="$( readlink "${relative_path}" )"
else
absolute_path="${relative_path}"
fi
popd >/dev/null

echo "${absolute_path}"
}
readonly -f os::util::absolute_path

# find the absolute path to the root of the Origin source tree
init_source="$( dirname "${BASH_SOURCE[0]}" )/../.."
OS_ROOT="$( os::util::absolute_path "${init_source}" )"
export OS_ROOT
cd "${OS_ROOT}"

for library_file in $( find "${OS_ROOT}/hack/lib" -type f -name '*.sh' -not -path '*/hack/lib/init.sh' ); do
source "${library_file}"
done

unset library_files library_file init_source

# all of our Bash scripts need to have the stacktrace
# handler installed to deal with errors
os::log::stacktrace::install

# All of our Bash scripts need to have access to the
# binaries that we build so we don't have to find
# them before every invocation.
os::util::environment::update_path_var

if [[ -z "${OS_TMP_ENV_SET-}" ]]; then
# if this file is run via 'source', then $0 will be "-bash" and won't work with basename
if [[ "${0}" =~ .*\.sh ]]; then
os::util::environment::setup_tmpdir_vars "$( basename "${0}" ".sh" )"
else
os::util::environment::setup_tmpdir_vars "shell"
fi
fi

# Allow setting $JUNIT_REPORT to toggle output behavior
if [[ -n "${JUNIT_REPORT:-}" ]]; then
export JUNIT_REPORT_OUTPUT="${LOG_DIR}/raw_test_output.log"
fi

0 comments on commit e0c1b7e

Please sign in to comment.