Building RPM from Git with Koji
If you have followed my other articles about Koji, you should have a fully working setup now. However its not very handy to only build local SRPM.
Fortunately Koji can build RPMs by spec-files and Makefiles which it gets from a Git repo or other SCM. Read on to learn how you get that going.
;using any other command instead of "make sources". Example showing "fedpkg sources"
This allows all Github repos owned by the Github account “github-username”.
When building out of an SCM, Koji expects there will be a Makefile in the project root that has a ‘sources’ target. Koji will call ‘make sources’ on the checked out files.
This target simply needs to download all the sources for the SRPM that are not already included in the SCM repository.
If the repo is private, you also need to add a SSH public key to the Github user and the private key to /root/.ssh/id_rsa on the Koji server.
Check with ssl_add -l if its loaded correctly.
My prefered folder structure for this repo has all RPM specs in a subfolder by their name and in there version-folders. Then in there the spec and Makefile.
The Makefile is easy. Pay attention to the indentation as Makefiles NEED tabs and not spaces !!
version = $(notdir $(dir))
package = jetty
spectool -g $(package)-$(version).spec
spec files are found on the internet for nearly every application. However you have to modify some of them to fit your needs.
So finally we can build from Git now like this
koji build dist-centos6 --scratch 'git+ssh://firstname.lastname@example.org/github-username/reponame.git?jetty/8.1.9/#HEAD
There are also other types of SCM you can use like SVN and CVS
git://, git+http://, git+https://, git+rsync://, git+ssh://
svn://, svn+http://, svn+https://, svn+ssh://
Some thoughts where this can lead to:
Using Githubs webhooks feature combined with a really simple httpd script, you can have Koji build automatically from Git after every commit. Or if a special commit message is used.
As long as I dont write an article about that, I just point you here https://github.com/philicious/koji-scripts-and-plugins/blob/master/koji-github-webhook/koji-github-tornado.py