Skip to content

Commit 4d5c303

Browse files
author
Tony Rogers
committed
adding Vagrantfile and Makefile to support building RPMs and DEBs
1 parent 5e6a273 commit 4d5c303

File tree

12 files changed

+375
-1
lines changed

12 files changed

+375
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ build
33
dist
44
*.egg-info
55
.project
6-
.pydevproject
6+
.pydevproject
7+
artifacts
8+
.vagrant

Makefile

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Base the name of the software on the spec file
2+
PACKAGE := $(shell basename *.spec .spec)
3+
# Override this arch if the software is arch specific
4+
ARCH = noarch
5+
6+
# Variables for clean build directory tree under repository
7+
BUILDDIR = ./build
8+
ARTIFACTDIR = ./artifacts
9+
SDISTDIR = ${ARTIFACTDIR}/sdist
10+
RPMBUILDDIR = ${BUILDDIR}/rpm-build
11+
RPMDIR = ${ARTIFACTDIR}/rpms
12+
DEBBUILDDIR = ${BUILDDIR}/deb-build
13+
DEBDIR = ${ARTIFACTDIR}/debs
14+
15+
# base rpmbuild command that utilizes the local buildroot
16+
# not using the above variables on purpose.
17+
# if you can make it work, PRs are welcome!
18+
RPMBUILD = rpmbuild --define "_topdir %(pwd)/build" \
19+
--define "_sourcedir %(pwd)/artifacts/sdist" \
20+
--define "_builddir %{_topdir}/rpm-build" \
21+
--define "_srcrpmdir %{_rpmdir}" \
22+
--define "_rpmdir %(pwd)/artifacts/rpms"
23+
24+
# Allow which python to be overridden at the environment level
25+
PYTHON := $(shell which python)
26+
27+
all: rpms
28+
29+
clean:
30+
rm -rf ${BUILDDIR}/ *~
31+
rm -rf *.egg-info
32+
find . -name '*.pyc' -exec rm -f {} \;
33+
34+
clean_all: clean
35+
rm -rf ${ARTIFACTDIR}/
36+
37+
build: clean
38+
${PYTHON} setup.py build -f
39+
40+
install: build
41+
${PYTHON} setup.py install -f
42+
43+
install_rpms: rpms
44+
yum install ${RPMDIR}/${ARCH}/${PACKAGE}*.${ARCH}.rpm
45+
46+
reinstall: uninstall install
47+
48+
uninstall: clean
49+
rm -f /usr/bin/${PACKAGE}
50+
rm -rf /usr/lib/python*/site-packages/${PACKAGE}
51+
52+
uninstall_rpms: clean
53+
rpm -e ${PACKAGE}
54+
55+
sdist:
56+
${PYTHON} setup.py sdist -d "${SDISTDIR}"
57+
58+
prep_rpmbuild: prep_build
59+
mkdir -p ${RPMBUILDDIR}
60+
mkdir -p ${RPMDIR}
61+
cp ${SDISTDIR}/*gz ${RPMBUILDDIR}/
62+
63+
rpms: prep_rpmbuild
64+
${RPMBUILD} -ba ${PACKAGE}.spec
65+
66+
srpm: prep_rpmbuild
67+
${RPMBUILD} -bs ${PACKAGE}.spec
68+
69+
prep_build: sdist
70+
mkdir -p ${BUILDDIR}
71+
72+
prep_debbuild: prep_build
73+
mkdir -p ${DEBBUILDDIR}
74+
mkdir -p ${DEBDIR}
75+
SDISTPACKAGE=`ls ${SDISTDIR}`; \
76+
BASE=`basename $$SDISTPACKAGE .tar.gz`; \
77+
DEBBASE=`echo $$BASE | sed 's/-/_/'`; \
78+
TARGET=${DEBBUILDDIR}/$$DEBBASE.orig.tar.gz; \
79+
ln -f -s ../../${SDISTDIR}/$$SDISTPACKAGE $$TARGET; \
80+
tar -xz -f $$TARGET -C ${DEBBUILDDIR}; \
81+
rm -rf ${DEBBUILDDIR}/$$BASE/debian; \
82+
cp -pr debian/ ${DEBBUILDDIR}/$$BASE
83+
84+
debs: prep_debbuild
85+
SDISTPACKAGE=`ls ${SDISTDIR}`; \
86+
BASE=`basename $$SDISTPACKAGE .tar.gz`; \
87+
cd ${DEBBUILDDIR}/$$BASE; \
88+
debuild -uc -us
89+
mv ${DEBBUILDDIR}/*.deb ${DEBDIR}/
90+

README.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,23 @@ Sample usage:::
66

77
>>> from zbxsend import Metric, send_to_zabbix
88
>>> send_to_zabbix([Metric('localhost', 'bucks_earned', 99999)], 'localhost', 10051)
9+
10+
=====
11+
Build
12+
=====
13+
14+
To build an RPM:::
15+
>>> make rpms
16+
>>> yum install ./artifacts/rpms/noarch/*.rpm
17+
18+
To build a deb:::
19+
>>> make debs
20+
>>> apt-get install ./artifacts/deb/*.deb
21+
22+
=======
23+
Vagrant
24+
=======
25+
26+
To test building a package (rpm/deb) and installing that package:::
27+
>>> vagrant up centos
28+
>>> vagrant up ubuntu

Vagrantfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5+
VAGRANTFILE_API_VERSION = "2"
6+
7+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8+
# Every Vagrant virtual environment requires a box to build off of.
9+
10+
if Vagrant.has_plugin?("vagrant-cachier")
11+
# Configure cached packages to be shared between instances of the same base box.
12+
# More info on http://fgrehm.viewdocs.io/vagrant-cachier/usage
13+
config.cache.scope = :box
14+
config.cache.auto_detect = false
15+
config.cache.enable :yum
16+
end
17+
18+
nodes = [{:hostname => 'centos', :box => 'centos-6.5-64-vagrant'},
19+
{:hostname => 'ubuntu', :box => 'hashicorp/precise64'}]
20+
21+
nodes.each do |node|
22+
config.vm.define node[:hostname] do |node_config|
23+
node_config.vm.box = node[:box]
24+
node_config.vm.host_name = node[:hostname]
25+
26+
memory = node[:ram] ? node[:ram] : 1024;
27+
node_config.vm.provider :virtualbox do |vb|
28+
vb.customize ["modifyvm", :id, "--memory", memory.to_s]
29+
vb.customize ["modifyvm", :id, "--name", node[:hostname]]
30+
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
31+
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
32+
end
33+
34+
node_config.vm.provision "puppet" do |puppet|
35+
puppet.manifests_path = "manifests"
36+
puppet.manifest_file = "#{node[:hostname]}.pp"
37+
puppet.options = "--verbose --debug"
38+
end
39+
end
40+
end
41+
end

debian/changelog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
zbxsend (0.1.6) unstable; urgency=low
2+
3+
* Initial release
4+
5+
-- Tony Rogers <tony.rogers@rackspace.com> Sat, 25 Apr 2015 01:14:00 +0500

debian/control

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Source: zbxsend
2+
Maintainer: Sergey Kirillov
3+
Section: misc
4+
Build-Depends: debhelper (>= 8.0.0)
5+
Priority: optional
6+
Standards-Version: 0.1.6
7+
8+
Package: zbxsend
9+
Description: Module used to send metrics to Zabbix.
10+
Architecture: all
11+
Depends: ${shlibs:Depends}, ${misc:Depends}, python (>=2.6)

debian/files

Whitespace-only changes.

debian/rules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/make -f
2+
# -*- makefile -*-
3+
# Uncomment this to turn on verbose mode.
4+
#export DH_VERBOSE=1
5+
%:
6+
dh $@

manifests/centos.pp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
include system_requirements
2+
include zbxsend
3+
4+
Class['system_requirements'] -> Class['zbxsend']
5+
6+
class system_requirements {
7+
# Sets up basic system requirements
8+
9+
package { 'python':
10+
ensure => present,
11+
provider => yum,
12+
}
13+
14+
package { 'python-devel':
15+
ensure => present,
16+
provider => yum,
17+
}
18+
19+
package { 'rpm-build':
20+
ensure => present,
21+
provider => yum,
22+
}
23+
24+
package { 'python-setuptools':
25+
ensure => present,
26+
provider => yum,
27+
}
28+
29+
exec { 'python-pip':
30+
command => 'easy_install pip==1.5.4',
31+
path => '/usr/bin/',
32+
require => Package['python-setuptools']
33+
}
34+
35+
}
36+
37+
class zbxsend {
38+
# Sets up the zbxsend project by linking things through so updates are live.
39+
# THIS SHOULD NOT BE USED AS A TEMPLATE FOR PRODUCTION
40+
exec { 'pip-install':
41+
command => 'sudo pip install --no-deps -e /vagrant',
42+
path => '/usr/bin/',
43+
require => [Exec['python-pip']]
44+
}
45+
}

manifests/ubuntu.pp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
include system_requirements
2+
include zbxsend
3+
4+
Class['system_requirements'] -> Class['zbxsend']
5+
6+
class system_requirements {
7+
# Sets up basic system requirements
8+
9+
package { 'python':
10+
ensure => present,
11+
provider => apt,
12+
}
13+
14+
package { 'python-dev':
15+
ensure => present,
16+
provider => apt,
17+
}
18+
19+
package { 'debhelper':
20+
ensure => present,
21+
provider => apt,
22+
}
23+
24+
package { 'devscripts':
25+
ensure => present,
26+
provider => apt,
27+
}
28+
29+
package { 'python-setuptools':
30+
ensure => present,
31+
provider => apt,
32+
}
33+
34+
exec { 'python-pip':
35+
command => 'easy_install pip==1.5.4',
36+
path => '/usr/bin/',
37+
require => Package['python-setuptools']
38+
}
39+
40+
}
41+
42+
class zbxsend {
43+
# Sets up the zbxsend project by linking things through so updates are live.
44+
# THIS SHOULD NOT BE USED AS A TEMPLATE FOR PRODUCTION
45+
exec { 'build deb':
46+
command => 'sudo rm -rf vagrant ; cp -r /vagrant . && cd vagrant && sudo make debs',
47+
path => '/bin/:/usr/bin',
48+
require => [Exec['python-pip']]
49+
}
50+
51+
exec { 'install deb':
52+
command => 'sudo dpkg -i vagrant/artifacts/debs/*.deb',
53+
path => '/bin/:/usr/bin',
54+
require => [Exec['build deb']]
55+
}
56+
}

0 commit comments

Comments
 (0)