forked from daos-stack/packaging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpm_chrootbuild
executable file
·146 lines (129 loc) · 4.7 KB
/
rpm_chrootbuild
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
set -uex
cp /etc/mock/"$CHROOT_NAME".cfg mock.cfg
# Enable mock ccache plugin
cat <<EOF >> mock.cfg
config_opts['plugin_conf']['ccache_enable'] = True
config_opts['plugin_conf']['ccache_opts']['dir'] = "%(cache_topdir)s/%(root)s/ccache/"
EOF
if [[ $CHROOT_NAME == *epel-8-x86_64 ]]; then
cat <<EOF >> mock.cfg
config_opts['module_setup_commands'] = [
('enable', 'javapackages-tools:201801'),
('disable', 'go-toolset')
]
EOF
fi
# Use dnf on CentOS 7
if [[ $CHROOT_NAME == *epel-7-x86_64 ]]; then
MOCK_OPTIONS="--dnf --no-bootstrap-chroot${MOCK_OPTIONS:+ }$MOCK_OPTIONS"
fi
# Allow BR: foo-devel < 1.2 to work when foo-devel-1.3 is actually available
cat <<EOF >> mock.cfg
config_opts['dnf.conf'] += """
[main]
best=0
"""
EOF
# shellcheck disable=SC2153
repo_adds=()
repo_dels=()
echo -e "config_opts['yum.conf'] += \"\"\"\n" >> mock.cfg
if [ -n "${ARTIFACTORY_URL:-}" ] && "$LOCAL_REPOS"; then
repo_dels+=("--disablerepo=\*")
if [ -n "${REPO_FILE_URL:-}" ]; then
if [ -n "$REPO_FILES_PR" ]; then
if [[ $REPO_FILES_PR = PR-* ]]; then
build_number="lastSuccessfulBuild"
branch="$REPO_FILES_PR"
if [[ $branch = *:* ]]; then
build_number="${branch#*:}"
branch="${branch%:*}"
fi
REPO_FILE_URL="${JENKINS_URL:-https://build.hpdd.intel.com/}job/daos-do/job/repo-files/job/$branch/$build_number/artifact/"
else
if [ ! -d "$REPO_FILES_PR" ]; then
echo "Could not find your specified directory \"$REPO_FILES_PR\" to read repo-files from"
exit 1
fi
REPO_FILE_URL="file://$(readlink -e "$REPO_FILES_PR")/"
fi
fi
curl -sSf "$REPO_FILE_URL"daos_ci-"${CHROOT_NAME%-*}".repo >> mock.cfg
repo_adds+=("--enablerepo *-artifactory")
fi
fi
repos_added=()
for repo in $DISTRO_BASE_PR_REPOS $PR_REPOS; do
branch="master"
build_number="lastSuccessfulBuild"
if [[ $repo = *@* ]]; then
branch="${repo#*@}"
repo="${repo%@*}"
if [[ $branch = *:* ]]; then
build_number="${branch#*:}"
branch="${branch%:*}"
fi
fi
if [[ " ${repos_added[*]} " = *\ ${repo}\ * ]]; then
# don't add duplicates, first found wins
continue
fi
repos_added+=("$repo")
repo_adds+=("--enablerepo $repo:${branch//[@\/]/_}:$build_number")
echo -e "[$repo:${branch//[@\/]/_}:$build_number]\n\
name=$repo:${branch//[@\/]/_}:$build_number\n\
baseurl=${ARTIFACTS_URL:-${JENKINS_URL:-https://build.hpdd.intel.com/}job/}daos-stack/job/$repo/job/${branch//\//%2F}/$build_number/artifact/artifacts/$DISTRO/\n\
enabled=1\n\
gpgcheck=False\n" >> mock.cfg
done
for repo in $JOB_REPOS; do
repo_name=${repo##*://}
repo_name=${repo_name//\//_}
if [[ " ${repos_added[*]} " = *\ ${repo_name}\ * ]]; then
# don't add duplicates, first found wins
continue
fi
repos_added+=("$repo_name")
repo_adds+=("--enablerepo $repo_name")
echo -e "[${repo_name//[@\/]/_}]\n\
name=${repo_name}\n\
baseurl=${repo//\//%2F}\n\
enabled=1\n" >> mock.cfg
done
echo "\"\"\"" >> mock.cfg
if [ -n "$DISTRO_VERSION" ]; then
releasever_opt=("--config-opts=releasever=$DISTRO_VERSION")
fi
bs_dir=/scratch/mock/cache/"${CHROOT_NAME}"-bootstrap-$(id -u)
if ls -l "$bs_dir"/root_cache/cache.tar.gz; then
mkdir -p "/var/cache/mock/${CHROOT_NAME}-bootstrap/"
flock "$bs_dir" -c "cp -a $bs_dir/root_cache /var/cache/mock/${CHROOT_NAME}-bootstrap"
fi
if ls -l "$bs_dir/ccache-$CHROOT_NAME-$PACKAGE".tar.gz; then
flock "$bs_dir" -c "tar -C / -xzf $bs_dir/ccache-$CHROOT_NAME-$PACKAGE.tar.gz"
fi
rc=0
# shellcheck disable=SC2086,SC2048
if ! eval time mock -r mock.cfg ${repo_dels[*]} ${repo_adds[*]} --no-clean \
--disablerepo=\*-debug* ${releasever_opt[*]} $MOCK_OPTIONS \
$RPM_BUILD_OPTIONS "$TARGET"; then
rc=${PIPESTATUS[0]}
fi
# Save the ccache
if [ -d /scratch/ ]; then
mkdir -p "$bs_dir"/
if ! flock "$bs_dir" -c "tar -czf $bs_dir/ccache-$CHROOT_NAME-$PACKAGE.tar.gz /var/cache/mock/${CHROOT_NAME}/ccache"; then
echo "Failed to save ccache. Plowing onward."
echo "I am $(id)"
fi
if ls -l /var/cache/mock/"${CHROOT_NAME}"-bootstrap/root_cache/cache.tar.gz; then
if ! cmp /var/cache/mock/"${CHROOT_NAME}"-bootstrap/root_cache/cache.tar.gz "$bs_dir"/root_cache/cache.tar.gz; then
if ! flock "$bs_dir" -c "cp -a /var/cache/mock/${CHROOT_NAME}-bootstrap/root_cache $bs_dir/"; then
echo "Failed to save root_cache. Plowing onward."
echo "I am $(id)"
fi
fi
fi
fi
exit "$rc"