Skip to content

Commit 20adea3

Browse files
committed
refactor: add flexible RPM installation source configuration
Add INSTALLATION_SOURCE environment variable and helpers to support installing go-fdo packages from multiple sources: - distro-repos: native distribution repositories - fedora-iot-copr: @fedora-iot/fedora-iot COPR repository - compose: Fedora/CentOS/RHEL compose trees - source: build from local git repository (default) Allow per-component override via CLIENT_INSTALLATION_SOURCE and SERVER_INSTALLATION_SOURCE to enable mixed installation scenarios (e.g., server from compose, client from source). Refactor installation functions to use common install_rpms_from() dispatcher that routes to specialized helpers. Improve COPR handling to properly disable/remove repos after use. Add compose installation with automatic repo configuration for Fedora, CentOS Stream, and RHEL. Also fixes: - Inconsistent logging (use log/log_info consistently) - Missing repo cleanup in COPR installation - Hard-coded package lists now in variables for reuse Signed-off-by: Miguel Martín <mmartinv@redhat.com>
1 parent f6eebe6 commit 20adea3

1 file changed

Lines changed: 188 additions & 31 deletions

File tree

utils/rpm.sh

Lines changed: 188 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)/native.s
3636
# the variable `systemd_${service}_drop_in_dir`. Remember to run
3737
# `sudo systemctl daemon-reload` after writing the drop-in file.
3838

39+
installation_source="${INSTALLATION_SOURCE:-source}"
40+
client_installation_source="${CLIENT_INSTALLATION_SOURCE:-${installation_source}}"
41+
server_installation_source="${SERVER_INSTALLATION_SOURCE:-${installation_source}}"
42+
3943
configs_dir="${base_dir}/configs"
4044
directories+=("${configs_dir}")
4145

@@ -71,6 +75,9 @@ owner_config_file="${configs_dir}/owner.yaml"
7175
owner_reuse_creds="false"
7276
owner_to0_insecure_tls="false"
7377

78+
go_fdo_server_rpms="go-fdo-server go-fdo-server-manufacturer go-fdo-server-owner go-fdo-server-rendezvous"
79+
go_fdo_client_rpms="go-fdo-client"
80+
7481
# systemd drop-in file configuration
7582
#
7683
systemd_drop_in_base_dir="/run/systemd/system"
@@ -202,30 +209,179 @@ configure_service_owner() {
202209
sudo chown -R ${rpm_owner_user}:${rpm_server_group} ${rpm_owner_home_dir}
203210
}
204211

205-
install_from_copr() {
212+
install_rpms_from_source() {
213+
local rpms="$*"
214+
case "${rpms}" in
215+
*go-fdo-client*)
216+
fetch_client_repo
217+
pushd "${client_src_dir}" >/dev/null
218+
commit="$(git rev-parse --short HEAD)"
219+
rpm -q go-fdo-client 2>/dev/null | grep -q "go-fdo-client.*git${commit}.*" || {
220+
make rpm
221+
sudo dnf install -y rpmbuild/rpms/"$(uname -m)"/*git"${commit}"*.rpm
222+
}
223+
popd >/dev/null
224+
;;
225+
*go-fdo-server*)
226+
fetch_server_repo
227+
pushd "${server_src_dir}" >/dev/null
228+
commit="$(git rev-parse --short HEAD)"
229+
rpm -q go-fdo-server 2>/dev/null | grep -q "go-fdo-server.*git${commit}.*" || {
230+
make rpm
231+
sudo dnf install -y rpmbuild/rpms/"$(uname -m)"/go-fdo-server-[1-9.]*.git"${commit}"*.rpm \
232+
rpmbuild/rpms/noarch/go-fdo-server-{manufacturer,owner,rendezvous}-[1-9.]*.git"${commit}"*.rpm
233+
}
234+
popd >/dev/null
235+
;;
236+
*)
237+
log_error "Unsupported rpms to install from source: '${rpms}'"
238+
;;
239+
esac
240+
}
241+
242+
rpm_repo_from_copr_project_spec() {
243+
local copr_project_spec="${1}"
244+
local slashes="${copr_project_spec//[^\/]}"
245+
local slash_count="${#slashes}"
246+
local hub
247+
local owner_project
248+
local owner
249+
local project
250+
case ${slash_count} in
251+
1)
252+
hub="copr.fedorainfracloud.org"
253+
owner="${copr_project_spec/\/*}"
254+
project="${copr_project_spec/*\/}"
255+
;;
256+
2)
257+
hub="${copr_project_spec/\/*}"
258+
owner_project="${copr_project_spec/*\/}"
259+
owner="${owner_project/\/*}"
260+
project="${owner_project/*\/}"
261+
;;
262+
*)
263+
log_error "Invalid copr project specification"
264+
;;
265+
esac
266+
echo "copr:${hub}:${owner/@/group_}:${project}"
267+
}
268+
269+
install_rpms_from_copr() {
270+
local copr="${1}"
271+
shift
272+
local rpms="$*"
273+
local repo
274+
repo=$(rpm_repo_from_copr_project_spec "${copr}")
206275
rpm -q --whatprovides 'dnf-command(copr)' &>/dev/null || sudo dnf install -y 'dnf-command(copr)'
207-
dnf copr list | grep 'fedora-iot/fedora-iot' || sudo dnf copr enable -y @fedora-iot/fedora-iot
276+
dnf copr list | grep -q "${copr}" || sudo dnf copr enable -y "${copr}"
208277
# testing-farm-tag-repository is causing problems with builds see:
209278
# https://docs.testing-farm.io/Testing%20Farm/0.1/test-environment.html#disabling-tag-repository
210-
sudo dnf install --disablerepo=* --enablerepo=copr:copr.fedorainfracloud.org:group_fedora-iot:fedora-iot -y "$@"
211-
sudo dnf copr disable -y @fedora-iot/fedora-iot
279+
sudo dnf install --disablerepo=* --enablerepo="${repo}" -y ${rpms}
280+
sudo dnf copr disable -y "${copr}"
281+
sudo dnf copr remove -y "${copr}"
282+
}
283+
284+
install_rpms_from_compose() {
285+
local rpms="$*"
286+
source /etc/os-release
287+
case "${ID}-${VERSION_ID}" in
288+
fedora-*)
289+
compose_host="http://kojipkgs.fedoraproject.org"
290+
compose_id="latest-Fedora-${VERSION_ID^}"
291+
compose_streams="${COMPOSE_STREAMS:-Everything}"
292+
compose_base_url="${COMPOSE_BASE_URL:-${compose_host}/compose/${VERSION_ID}/${compose_id}/compose}"
293+
;;
294+
centos-*)
295+
compose_host="https://composes.stream.centos.org"
296+
compose_id="latest-CentOS-Stream"
297+
compose_streams="${COMPOSE_STREAMS:-BaseOS AppStream}"
298+
compose_base_url="${COMPOSE_BASE_URL:-${compose_host}/stream-${VERSION_ID}/production/${compose_id}/compose}"
299+
;;
300+
rhel-*)
301+
compose_base_url="${COMPOSE_BASE_URL:-}"
302+
[ -n "${compose_base_url}" ] || log_error "Compose base URL must be set for RHEL (eg='http://download.host/.../latest-RHEL-Compose/compose/')"
303+
compose_streams="${COMPOSE_STREAMS:-BaseOS AppStream}"
304+
[ -n "${compose_streams}" ] || log_error "Streams must be set for RHEL (default='BaseOS AppStream')"
305+
;;
306+
*)
307+
log_error "OS not supported"
308+
;;
309+
esac
310+
repo_base_name="go-fdo-ci-compose-${ID}-${VERSION_ID}"
311+
repo_dir="/etc/yum.repos.d"
312+
for stream in ${compose_streams}; do
313+
repo_name="${repo_base_name}-${stream}"
314+
repo_file="${repo_dir}/${repo_name}.repo"
315+
sudo tee "${repo_file}" <<EOF
316+
[${repo_name}]
317+
name=${repo_name}
318+
baseurl=${compose_base_url}/${stream}/$(uname -m)/os/
319+
enabled=1
320+
gpgcheck=0
321+
322+
EOF
323+
if [ "${ID}" = "fedora" ] && [ ! -v "COMPOSE_BASE_URL" ] && [ ! -v "COMPOSE_STREAMS" ] ; then
324+
sudo tee -a "${repo_file}" <<EOF
325+
[${repo_name}-updates]
326+
name=${repo_name}-updates
327+
baseurl=${compose_host}/compose/updates/f${VERSION_ID}-updates/compose/${stream}/$(uname -m)/os/
328+
enabled=1
329+
gpgcheck=0
330+
331+
EOF
332+
fi
333+
done
334+
sudo dnf install --disablerepo=* --enablerepo="${repo_base_name}*" -y ${rpms}
335+
sudo rm -f "${repo_dir?}/${repo_base_name:?}"*.repo
336+
}
337+
338+
install_rpms_from() {
339+
local install_source="${1}"
340+
[ -n "$install_source" ] || log_error "Installation source must be provided as first argument"
341+
shift
342+
local rpms="${*}"
343+
case "${install_source}" in
344+
"distro-repos")
345+
sudo dnf install -y ${rpms}
346+
;;
347+
"fedora-iot-copr")
348+
install_rpms_from_copr "@fedora-iot/fedora-iot" "${rpms}"
349+
;;
350+
"compose")
351+
install_rpms_from_compose "${rpms}"
352+
;;
353+
"source")
354+
install_rpms_from_source "${rpms}"
355+
;;
356+
*)
357+
log_error "Unsupported installation source: '${install_source}'"
358+
;;
359+
esac
212360
}
213361

214362
install_client() {
215-
# If PACKIT_COPR_RPMS is not defined it means we are running the test
216-
# locally so we will install the client from the copr repo
217-
[ -v "PACKIT_COPR_RPMS" ] || rpm -q go-fdo-client &>/dev/null || install_from_copr go-fdo-client
218-
log_info "Installed Client RPM:"
219-
echo "$(rpm -q go-fdo-client)"
363+
if [ -v "PACKIT_COPR_RPMS" ]; then
364+
# if PACKIT_COPR_RPMS is defined and contains the 'go-fdo-client'
365+
# package it means we are running the tests in the client repo
366+
if [[ "${PACKIT_COPR_RPMS}" =~ go-fdo-client ]]; then
367+
log_info "Expected Go FDO Client RPM:"
368+
for i in ${PACKIT_COPR_RPMS}; do
369+
log "$i\n"
370+
done | sort
371+
else
372+
install_rpms_from "fedora-iot-copr" ${go_fdo_client_rpms}
373+
fi
374+
else
375+
# If PACKIT_COPR_RPMS is not defined it means we are running the test
376+
# locally
377+
install_rpms_from "${client_installation_source}" "${go_fdo_client_rpms}"
378+
fi
379+
log_info "Installed Go FDO Client RPM:"
380+
log "$(rpm -q ${go_fdo_client_rpms})\n"
220381
}
221382

222383
uninstall_client() {
223-
# When running a test locally we remove the client package
224-
# after a successful execution.
225-
[ -v "PACKIT_COPR_RPMS" ] || {
226-
sudo dnf remove -y go-fdo-client
227-
sudo dnf copr remove -y @fedora-iot/fedora-iot
228-
}
384+
[ -v "PACKIT_COPR_RPMS" ] || sudo dnf remove -y ${go_fdo_client_rpms}
229385
}
230386

231387
run_go_fdo_client() {
@@ -240,30 +396,31 @@ run_go_fdo_client() {
240396
}
241397

242398
install_server() {
243-
# If PACKIT_COPR_RPMS is not defined it means we are running the test
244-
# locally so we will build and install the RPMs from the *committed* code
245-
if [ ! -v "PACKIT_COPR_RPMS" ]; then
246-
commit="$(git rev-parse --short HEAD)"
247-
rpm -q go-fdo-server | grep -q "go-fdo-server.*git${commit}.*" || {
248-
make rpm
249-
sudo dnf install -y rpmbuild/rpms/{noarch,"$(uname -m)"}/*git"${commit}"*.rpm
250-
}
399+
# If PACKIT_COPR_RPMS is defined it means that all the rpms were built and installed already by packit
400+
if [ -v "PACKIT_COPR_RPMS" ]; then
401+
if [[ "${PACKIT_COPR_RPMS}" =~ go-fdo-server ]]; then
402+
log_info "Expected Go FDO Server RPMs:"
403+
for i in ${PACKIT_COPR_RPMS}; do
404+
log "$i\n"
405+
done | sort
406+
else
407+
install_rpms_from "fedora-iot-copr" ${go_fdo_server_rpms}
408+
fi
251409
else
252-
log_info "Expected Server RPMs:"
253-
for i in ${PACKIT_COPR_RPMS}; do
254-
echo "$i"
255-
done | sort
410+
# If PACKIT_COPR_RPMS is not defined it means we are running the test
411+
# locally
412+
install_rpms_from "${server_installation_source}" "${go_fdo_server_rpms}"
256413
fi
257414
# Make sure the RPMS are installed
258-
installed_rpms=$(rpm -q --qf "%{nvr}.%{arch} " go-fdo-server{,-{manufacturer,owner,rendezvous}})
259-
log_info "Installed Server RPMs:"
415+
installed_rpms=$(rpm -q --qf "%{nvr}.%{arch} " ${go_fdo_server_rpms})
416+
log_info "Installed Go FDO Server RPMs:"
260417
for i in ${installed_rpms}; do
261-
echo " $i"
418+
log "$i\n"
262419
done | sort
263420
}
264421

265422
uninstall_server() {
266-
[ -v "PACKIT_COPR_RPMS" ] || sudo dnf remove -y go-fdo-server{,-manufacturer,-owner,-rendezvous}
423+
[ -v "PACKIT_COPR_RPMS" ] || sudo dnf remove -y ${go_fdo_server_rpms}
267424
}
268425

269426
start_service_manufacturer() {

0 commit comments

Comments
 (0)