Skip to content

Commit afb7b2f

Browse files
author
OpenShift Bot
authored
Merge pull request #13610 from stevekuznetsov/skuznets/backport-rpm-fixes
Merged by openshift-bot
2 parents 3e12f6a + 9a14bfa commit afb7b2f

File tree

2 files changed

+97
-21
lines changed

2 files changed

+97
-21
lines changed

hack/build-rpm-release.sh

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,9 @@ else
1717
fi
1818

1919
os::log::info 'Building Origin release RPMs with tito...'
20-
os::build::get_version_vars
21-
if [[ "${OS_GIT_TREE_STATE}" == "dirty" ]]; then
22-
os::log::fatal "Cannot build RPMs with a dirty git tree. Commit your changes and try again."
23-
fi
24-
if [[ "${OS_GIT_VERSION}" =~ ^v([0-9](\.[0-9]+)*)(.*) ]]; then
25-
# we need to translate from the semantic version
26-
# provided by the Origin build scripts to the
27-
# version that RPM will expect.
28-
rpm_version="${BASH_REMATCH[1]}"
29-
rpm_release="999${BASH_REMATCH[3]//-/.}"
30-
fi
31-
tito tag --use-version="${rpm_version}" \
32-
--use-release="${rpm_release}" \
20+
os::build::rpm::get_nvra_vars
21+
tito tag --use-version="${OS_RPM_VERSION}" \
22+
--use-release="${OS_RPM_RELEASE}" \
3323
--no-auto-changelog --offline
3424
tito_tmp_dir="${BASETMPDIR}/tito"
3525
mkdir -p "${tito_tmp_dir}"
@@ -38,7 +28,7 @@ tito build --output="${tito_tmp_dir}" --rpm --no-cleanup --quiet --offline \
3828
tito tag --undo --offline
3929

4030
os::log::info 'Unpacking tito artifacts for reuse...'
41-
output_directories=( $( find "${tito_tmp_dir}" -type d -name 'rpmbuild-origin*' ) )
31+
output_directories=( $( find "${tito_tmp_dir}" -type d -name "rpmbuild-${OS_RPM_NAME}*" ) )
4232
if [[ "${#output_directories[@]}" -eq 0 ]]; then
4333
os::log::error 'After the tito build, no rpmbuild directory was found!'
4434
exit 1
@@ -56,9 +46,9 @@ else
5646
output_directory="${output_directories[0]}"
5747
fi
5848

59-
tito_output_directory="$( find "${output_directory}" -type d -path "*/BUILD/origin-${rpm_version}/_output/local" )"
49+
tito_output_directory="$( find "${output_directory}" -type d -path "*/BUILD/${OS_RPM_NAME}-${OS_RPM_VERSION}/_output/local" )"
6050
if [[ -z "${tito_output_directory}" ]]; then
61-
os::log::fatal 'No _output artifact directory found in tito rpmbuild artifacts!'
51+
os::log::fatal 'No _output artifact directory found in tito rpmbuild artifacts!'
6252
fi
6353

6454
# clean up our local state so we can unpack the tito artifacts cleanly
@@ -74,14 +64,15 @@ if command -v createrepo >/dev/null 2>&1; then
7464
repo_path="$( os::util::absolute_path "${OS_LOCAL_RELEASEPATH}/rpms" )"
7565
createrepo "${repo_path}"
7666

77-
echo "[origin-local-release]
67+
echo "[${OS_RPM_NAME}-local-release]
7868
baseurl = file://${repo_path}
7969
gpgcheck = 0
80-
name = OpenShift Origin Release from Local Source
81-
" > "${repo_path}/origin-local-release.repo"
70+
name = OpenShift Release from Local Source
71+
enabled = 1
72+
" > "${repo_path}/${OS_RPM_NAME}-local-release.repo"
8273

83-
os::log::info "Repository file for \`yum\` or \`dnf\` placed at ${repo_path}/origin-local-release.repo"
84-
os::log::info "Install it with: "$'\n\t'"$ mv '${repo_path}/origin-local-release.repo' '/etc/yum.repos.d"
74+
os::log::info "Repository file for \`yum\` or \`dnf\` placed at ${repo_path}/${OS_RPM_NAME}-local-release.repo"
75+
os::log::info "Install it with: "$'\n\t'"$ mv '${repo_path}/${OS_RPM_NAME}-local-release.repo' '/etc/yum.repos.d"
8576
else
8677
os::log::warn "Repository file for \`yum\` or \`dnf\` could not be generated, install \`createrepo\`."
8778
fi

hack/lib/build/rpm.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/bash
2+
3+
# This library holds utilities for building RPMs from Origin.
4+
5+
# os::build::rpm::generate_nevra_vars determines the NEVRA of the RPMs
6+
# that would be built from the current git state.
7+
#
8+
# Globals:
9+
# - OS_GIT_VERSION
10+
# Arguments:
11+
# - None
12+
# Exports:
13+
# - OS_RPM_NAME
14+
# - OS_RPM_VERSION
15+
# - OS_RPM_RELEASE
16+
# - OS_RPM_ARCHITECTURE
17+
function os::build::rpm::get_nvra_vars() {
18+
# the package name can be overwritten but is normally 'origin'
19+
OS_RPM_NAME="${OS_RPM_NAME:-"origin"}"
20+
OS_RPM_ARCHITECTURE="$(uname -i)"
21+
22+
# we can extract the pacakge version from the build version
23+
os::build::get_version_vars
24+
if [[ "${OS_GIT_VERSION}" =~ ^v([0-9](\.[0-9]+)*)(.*) ]]; then
25+
OS_RPM_VERSION="${BASH_REMATCH[1]}"
26+
metadata="${BASH_REMATCH[3]}"
27+
else
28+
os::log::fatal "Malformed \$OS_GIT_VERSION: ${OS_GIT_VERSION}"
29+
fi
30+
31+
# we can generate the package release from the git version metadata
32+
# OS_GIT_VERSION will always have metadata, but either contain
33+
# pre-release information _and_ build metadata, or only the latter
34+
# ex.
35+
# -alpha.0+shasums-123-dirty
36+
# -alpha.0+shasums-123
37+
# +shasums-123-dirty
38+
# +shasums-123
39+
if [[ "${metadata:0:1}" == "+" ]]; then
40+
# we only have build metadata, but need to massage it so
41+
# we can generate a valid RPM release from it
42+
if [[ "${metadata}" =~ ^\+([a-z0-9]{7})-([0-9]+)(-dirty)?$ ]]; then
43+
build_sha="${BASH_REMATCH[1]}"
44+
build_num="${BASH_REMATCH[2]}"
45+
else
46+
os::log::fatal "Malformed git version metadata: ${metadata}"
47+
fi
48+
OS_RPM_RELEASE="1.${build_num}.${build_sha}"
49+
elif [[ "${metadata:0:1}" == "-" ]]; then
50+
# we have both build metadata and pre-release info
51+
if [[ "${metadata}" =~ ^-([^\+]+)\+([a-z0-9]{7})-([0-9]+)(-dirty)?$ ]]; then
52+
pre_release="${BASH_REMATCH[1]}"
53+
build_sha="${BASH_REMATCH[2]}"
54+
build_num="${BASH_REMATCH[3]}"
55+
else
56+
os::log::fatal "Malformed git version metadata: ${metadata}"
57+
fi
58+
OS_RPM_RELEASE="0.${pre_release}.${build_num}.${build_sha}"
59+
else
60+
os::log::fatal "Malformed git version metadata: ${metadata}"
61+
fi
62+
63+
export OS_RPM_NAME OS_RPM_VERSION OS_RPM_RELEASE OS_RPM_ARCHITECTURE
64+
}
65+
66+
67+
# os::build::rpm::format_nvra formats the rpm NVRA vars generated by
68+
# os::build::rpm::get_nvra_vars and will generate them if necessary
69+
#
70+
# Globals:
71+
# - OS_RPM_NAME
72+
# - OS_RPM_VERSION
73+
# - OS_RPM_RELEASE
74+
# - OS_RPM_ARCHITECTURE
75+
# Arguments:
76+
# None
77+
# Returns:
78+
# None
79+
function os::build::rpm::format_nvra() {
80+
if [[ -z "${OS_RPM_NAME:-}" || -z "${OS_RPM_VERSION:-}" || -z "${OS_RPM_RELEASE:-}" ]]; then
81+
os::build::rpm::get_nvra_vars
82+
fi
83+
84+
echo "${OS_RPM_NAME}-${OS_RPM_VERSION}-${OS_RPM_RELEASE}.${OS_RPM_ARCHITECTURE}"
85+
}

0 commit comments

Comments
 (0)