Skip to content

Commit 8c3a102

Browse files
authored
Unify agent and server RPM builds (#2187)
* Unify agent and server container makefiles * Code review feedback * More code review feedback
1 parent 03e4a14 commit 8c3a102

File tree

5 files changed

+102
-233
lines changed

5 files changed

+102
-233
lines changed

agent/rpm/Makefile

Lines changed: 5 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,7 @@
1-
# Making a pbench-agent RPM requires a few steps:
2-
# 1. Get version number.
3-
# 2. Update the RPM spec file with that version number etc.
4-
# 3. Update the stockpile submodule.
5-
# 4. Do a "make install" of the agent to a temp directory.
6-
# 5. Generate a tar ball from the directory.
7-
# 6. Generate a local SRPM that will be uploaded to COPR for building.
8-
# 7. Optionally generate a local RPM.
9-
# 8. Clean up the temp directory
1+
# Makefile for generating a source RPM and optional local RPM
2+
# for the Pbench agent.
103

11-
CWD = $(shell pwd)
4+
component = agent
5+
subcomps = agent
126

13-
# adjust as necessary
14-
AGENT = $(dir ${CWD})
15-
16-
VERSION = $(file < ${AGENT}/VERSION)
17-
18-
# temp directory for packing up the tarball
19-
TMPDIR = /tmp/opt
20-
21-
RPMSRC = ${HOME}/rpmbuild/SOURCES
22-
RPMSRPM = ${HOME}/rpmbuild/SRPMS
23-
RPMSPEC = ${HOME}/rpmbuild/SPECS
24-
25-
prog = pbench-agent
26-
arch = noarch
27-
28-
USE_GIT_SHA1 = yes
29-
sha1 := $(shell git rev-parse --short HEAD)
30-
seqno := $(shell if [ -e ./seqno ] ;then cat ./seqno ;else echo "1" ;fi)
31-
32-
# By default we only build a source RPM
33-
all: srpm
34-
35-
rpm: srpm
36-
rpmbuild -bb ${RPMSPEC}/${prog}.spec
37-
38-
srpm: spec patches tarball
39-
rm -f ${RPMSRPM}/$(prog)-*.src.rpm
40-
rpmbuild -bs ${RPMSPEC}/${prog}.spec
41-
42-
.PHONY: spec
43-
spec: ${prog}.spec.j2
44-
mkdir -p ${RPMSPEC}
45-
if [ -e ./seqno ] ;then expr ${seqno} + 1 > ./seqno ;fi
46-
jinja2 ${prog}.spec.j2 -D version=${VERSION} -D gdist=g${sha1} -D seqno=${seqno} > ${RPMSPEC}/${prog}.spec
47-
rpmlint ${RPMSPEC}/${prog}.spec
48-
49-
.PHONY: patches
50-
patches:
51-
if [ -d ${CWD}/patches ] ;then cp ${CWD}/patches/* ${RPMSRC} ;fi
52-
53-
.PHONY: tarball
54-
tarball:
55-
mkdir -p ${RPMSRC}
56-
(cd ${AGENT}/../; git submodule init; git submodule update)
57-
make -C .. DESTDIR=${TMPDIR}/${prog}-${VERSION}/agent
58-
echo "${sha1}" > ${TMPDIR}/${prog}-${VERSION}/agent/SHA1
59-
echo "${seqno}" > ${TMPDIR}/${prog}-${VERSION}/agent/SEQNO
60-
tar zcf ${RPMSRC}/pbench-agent-${VERSION}.tar.gz -C ${TMPDIR} ${prog}-${VERSION}
61-
rm -rf ${TMPDIR}
62-
63-
include rpm.mk
64-
65-
clean:: rpm-clean
7+
include ../../utils/rpm.mk

agent/rpm/rpm.mk

Lines changed: 0 additions & 46 deletions
This file was deleted.

server/rpm/Makefile

Lines changed: 5 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,7 @@
1-
# Making a pbench-server RPM requires a few steps
2-
# 1. Generate a version number
3-
# 2. Update the RPM spec file with that version number
4-
# 3. Generate a tar ball of the sources to be used by the RPM building process
5-
# 4. Generate an SRPM that will be uploaded to COPR for building.
1+
# Makefile for generating a source RPM and optional local RPM
2+
# for the Pbench server.
63

7-
CWD = $(shell pwd -L)
8-
9-
SERVER = $(dir ${CWD})
10-
PBENCHTOP = $(shell dirname ${SERVER})
11-
TMPDIR = /tmp/opt
12-
13-
VERSION = $(shell cat ${SERVER}/VERSION)
14-
15-
DISTRO = $(shell uname -r | python -c 'import sys; print(sys.stdin.read().split(".")[-2])')
16-
17-
PYTHON = python3
18-
19-
RPMSRC = ${HOME}/rpmbuild/SOURCES
20-
RPMSRPM = ${HOME}/rpmbuild/SRPMS
21-
RPMSPEC = ${HOME}/rpmbuild/SPECS
22-
23-
prog = pbench-server
24-
arch = noarch
25-
26-
TBDIR = ${TMPDIR}/${prog}-${VERSION}
27-
28-
USE_GIT_SHA1 = yes
29-
sha1 = $(shell git rev-parse --short HEAD)
30-
seqno := $(shell if [ -e ./seqno ] ;then cat ./seqno ;else echo "1" ;fi)
31-
32-
rpm: srpm
33-
rpmbuild -bb ${HOME}/rpmbuild/SPECS/${prog}.spec
34-
35-
srpm: patches tarball
36-
rm -f ${HOME}/rpmbuild/SRPMS/$(prog)-*.src.rpm
37-
rpmbuild -bs ${HOME}/rpmbuild/SPECS/$(prog).spec
38-
39-
.PHONY: spec
40-
spec: ${prog}.spec.j2
41-
mkdir -p ${RPMSPEC}
42-
if [ -e ./seqno ] ;then expr ${seqno} + 1 > ./seqno ;fi
43-
jinja2 ${prog}.spec.j2 -D version=${VERSION} -D gdist=g${sha1} -D seqno=${seqno} > ${RPMSPEC}/${prog}.spec
44-
rpmlint ${RPMSPEC}/${prog}.spec
45-
46-
.PHONY: patches
47-
patches:
48-
if [ -d ${CWD}/patches ] ;then cp ${CWD}/patches/* ${RPMSRC} ;fi
49-
50-
.PHONY: tarball
51-
tarball: spec
52-
mkdir -p ${RPMSRC}
53-
make -C ${PBENCHTOP}/server DESTDIR=${TBDIR}/server install
54-
make -C ${PBENCHTOP}/web-server DESTDIR=${TBDIR}/web-server install
55-
sed -i '1s;.*python$$;#!/usr/bin/env python3;' ${TBDIR}/server/bin/pbench-config ${TBDIR}/server/bin/pbench-server
56-
echo "${sha1}" > ${TBDIR}/server/SHA1
57-
echo "${seqno}" > ${TBDIR}/server/SEQNO
58-
tar zcf ${RPMSRC}/pbench-server-${VERSION}.tar.gz -C ${TMPDIR} ${prog}-${VERSION}
59-
rm -rf ${TMPDIR}
60-
61-
###########################################################################
62-
# build RPMs in COPR
63-
seqno := $(shell if [ -f seqno ] ;then cat seqno ;else echo 1; fi)
64-
65-
include rpm.mk
66-
67-
clean-sha1:
68-
rm -f ${upstmtree}/${prog}.SHA1
69-
70-
clean:: localclean
4+
component = server
5+
subcomps = server web-server
716

7+
include ../../utils/rpm.mk

server/rpm/rpm.mk

Lines changed: 0 additions & 55 deletions
This file was deleted.

utils/rpm.mk

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Common definitions for making an RPM, used by both the Agent and the Server.
2+
#
3+
# Making a pbench component RPM requires a few steps:
4+
# 1. Get version number.
5+
# 2. Update the RPM spec file with that version number etc.
6+
# 3. Update any GIT submodules.
7+
# 4. Do a "make install" to a temp directory.
8+
# 5. Generate a tar ball from the directory.
9+
# 6. Generate a local SRPM that will be uploaded to COPR for building.
10+
# 7. Optionally generate a local RPM.
11+
# 8. Clean up the temp directory
12+
13+
PBENCHTOP := $(shell git rev-parse --show-toplevel)
14+
TMPDIR = /tmp/opt
15+
16+
prog = pbench-${component}
17+
VERSION := $(file < ${PBENCHTOP}/${component}/VERSION)
18+
TBDIR = ${TMPDIR}/${prog}-${VERSION}
19+
20+
RPMDIRS = BUILD BUILDROOT SPECS SOURCES SRPMS RPMS
21+
22+
RPMSRC = ${HOME}/rpmbuild/SOURCES
23+
RPMSRPM = ${HOME}/rpmbuild/SRPMS
24+
RPMSPEC = ${HOME}/rpmbuild/SPECS
25+
26+
sha1 := $(shell git rev-parse --short HEAD)
27+
seqno := $(shell if [ -e ./seqno ] ;then cat ./seqno ;else echo "1" ;fi)
28+
29+
# By default we only build a source RPM
30+
all: srpm
31+
32+
.PHONY: rpm
33+
rpm: spec srpm
34+
rpmbuild -bb ${RPMSPEC}/${prog}.spec
35+
36+
.PHONY: srpm
37+
srpm: spec patches tarball
38+
rm -f ${RPMSRPM}/$(prog)-*.src.rpm
39+
rpmbuild -bs ${RPMSPEC}/${prog}.spec
40+
41+
.PHONY: spec
42+
spec: rpm-dirs ${prog}.spec.j2
43+
if [ -e ./seqno ] ;then expr ${seqno} + 1 > ./seqno ;fi
44+
jinja2 ${prog}.spec.j2 -D version=${VERSION} -D gdist=g${sha1} -D seqno=${seqno} > ${RPMSPEC}/${prog}.spec
45+
rpmlint ${RPMSPEC}/${prog}.spec
46+
47+
.PHONY: patches
48+
patches: rpm-dirs
49+
if [ -d ./patches ] ;then cp ./patches/* ${RPMSRC}/ ;fi
50+
51+
.PHONY: tarball
52+
tarball: rpm-dirs submodules ${subcomps}
53+
echo "${sha1}" > ${TBDIR}/${component}/SHA1
54+
echo "${seqno}" > ${TBDIR}/${component}/SEQNO
55+
tar zcf ${RPMSRC}/${prog}-${VERSION}.tar.gz -C ${TMPDIR} ${prog}-${VERSION}
56+
rm -rf ${TMPDIR}
57+
58+
.PHONY: rpm-dirs
59+
rpm-dirs:
60+
mkdir -p $(addprefix ${HOME}/rpmbuild/,${RPMDIRS})
61+
62+
.PHONY: submodules
63+
submodules:
64+
git submodule update --init --recursive
65+
66+
.PHONY: ${subcomps}
67+
${subcomps}:
68+
make -C ${PBENCHTOP}/$@ DESTDIR=${TBDIR}/$@ install
69+
70+
$(RPMSRPM)/$(prog)-$(version)-$(seqno)$(sha1).src.rpm: srpm
71+
72+
ifdef COPR_USER
73+
_copr_user = ${COPR_USER}
74+
else
75+
_copr_user = ${USER}
76+
endif
77+
78+
COPR_TARGETS = copr copr-test
79+
.PHONY: ${COPR_TARGETS}
80+
${COPR_TARGETS}: $(RPMSRPM)/$(prog)-$(version)-$(seqno)$(sha1).src.rpm
81+
copr-cli build $(_copr_user)/$(subst copr,pbench,$@) $(RPMSRPM)/$(prog)-$(VERSION)-$(seqno)g$(sha1).src.rpm
82+
83+
.PHONY: distclean
84+
distclean:
85+
rm -rf $(addprefix ${HOME}/rpmbuild/,${RPMDIRS})
86+
87+
.PHONY: clean
88+
clean:: rpm-clean
89+
90+
.PHONY: rpm-clean
91+
rpm-clean:
92+
rm -rf $(foreach dir,${RPMDIRS},${HOME}/rpmbuild/${dir}/*)

0 commit comments

Comments
 (0)