Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding Vagrantfile and Makefile to support building RPMs and DEBs #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ build
dist
*.egg-info
.project
.pydevproject
.pydevproject
artifacts
.vagrant
90 changes: 90 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Base the name of the software on the spec file
PACKAGE := $(shell basename *.spec .spec)
# Override this arch if the software is arch specific
ARCH = noarch

# Variables for clean build directory tree under repository
BUILDDIR = ./build
ARTIFACTDIR = ./artifacts
SDISTDIR = ${ARTIFACTDIR}/sdist
RPMBUILDDIR = ${BUILDDIR}/rpm-build
RPMDIR = ${ARTIFACTDIR}/rpms
DEBBUILDDIR = ${BUILDDIR}/deb-build
DEBDIR = ${ARTIFACTDIR}/debs

# base rpmbuild command that utilizes the local buildroot
# not using the above variables on purpose.
# if you can make it work, PRs are welcome!
RPMBUILD = rpmbuild --define "_topdir %(pwd)/build" \
--define "_sourcedir %(pwd)/artifacts/sdist" \
--define "_builddir %{_topdir}/rpm-build" \
--define "_srcrpmdir %{_rpmdir}" \
--define "_rpmdir %(pwd)/artifacts/rpms"

# Allow which python to be overridden at the environment level
PYTHON := $(shell which python)

all: rpms

clean:
rm -rf ${BUILDDIR}/ *~
rm -rf *.egg-info
find . -name '*.pyc' -exec rm -f {} \;

clean_all: clean
rm -rf ${ARTIFACTDIR}/

build: clean
${PYTHON} setup.py build -f

install: build
${PYTHON} setup.py install -f

install_rpms: rpms
yum install ${RPMDIR}/${ARCH}/${PACKAGE}*.${ARCH}.rpm

reinstall: uninstall install

uninstall: clean
rm -f /usr/bin/${PACKAGE}
rm -rf /usr/lib/python*/site-packages/${PACKAGE}

uninstall_rpms: clean
rpm -e ${PACKAGE}

sdist:
${PYTHON} setup.py sdist -d "${SDISTDIR}"

prep_rpmbuild: prep_build
mkdir -p ${RPMBUILDDIR}
mkdir -p ${RPMDIR}
cp ${SDISTDIR}/*gz ${RPMBUILDDIR}/

rpms: prep_rpmbuild
${RPMBUILD} -ba ${PACKAGE}.spec

srpm: prep_rpmbuild
${RPMBUILD} -bs ${PACKAGE}.spec

prep_build: sdist
mkdir -p ${BUILDDIR}

prep_debbuild: prep_build
mkdir -p ${DEBBUILDDIR}
mkdir -p ${DEBDIR}
SDISTPACKAGE=`ls ${SDISTDIR}`; \
BASE=`basename $$SDISTPACKAGE .tar.gz`; \
DEBBASE=`echo $$BASE | sed 's/-/_/'`; \
TARGET=${DEBBUILDDIR}/$$DEBBASE.orig.tar.gz; \
ln -f -s ../../${SDISTDIR}/$$SDISTPACKAGE $$TARGET; \
tar -xz -f $$TARGET -C ${DEBBUILDDIR}; \
rm -rf ${DEBBUILDDIR}/$$BASE/debian; \
cp -pr debian/ ${DEBBUILDDIR}/$$BASE

debs: prep_debbuild
SDISTPACKAGE=`ls ${SDISTDIR}`; \
BASE=`basename $$SDISTPACKAGE .tar.gz`; \
cd ${DEBBUILDDIR}/$$BASE; \
debuild -uc -us
mv ${DEBBUILDDIR}/*.deb ${DEBDIR}/

20 changes: 20 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,23 @@ Sample usage:::

>>> from zbxsend import Metric, send_to_zabbix
>>> send_to_zabbix([Metric('localhost', 'bucks_earned', 99999)], 'localhost', 10051)

=====
Build
=====

To build an RPM:::
>>> make rpms
>>> yum install ./artifacts/rpms/noarch/*.rpm

To build a deb:::
>>> make debs
>>> apt-get install ./artifacts/deb/*.deb

=======
Vagrant
=======

To test building a package (rpm/deb) and installing that package:::
>>> vagrant up centos
>>> vagrant up ubuntu
41 changes: 41 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Every Vagrant virtual environment requires a box to build off of.

if Vagrant.has_plugin?("vagrant-cachier")
# Configure cached packages to be shared between instances of the same base box.
# More info on http://fgrehm.viewdocs.io/vagrant-cachier/usage
config.cache.scope = :box
config.cache.auto_detect = false
config.cache.enable :yum
end

nodes = [{:hostname => 'centos', :box => 'centos-6.5-64-vagrant'},
{:hostname => 'ubuntu', :box => 'hashicorp/precise64'}]

nodes.each do |node|
config.vm.define node[:hostname] do |node_config|
node_config.vm.box = node[:box]
node_config.vm.host_name = node[:hostname]

memory = node[:ram] ? node[:ram] : 1024;
node_config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", memory.to_s]
vb.customize ["modifyvm", :id, "--name", node[:hostname]]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end

node_config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "manifests"
puppet.manifest_file = "#{node[:hostname]}.pp"
puppet.options = "--verbose --debug"
end
end
end
end
5 changes: 5 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
zbxsend (0.1.6) unstable; urgency=low

* Initial release

-- Tony Rogers <[email protected]> Sat, 25 Apr 2015 01:14:00 +0500
11 changes: 11 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Source: zbxsend
Maintainer: Sergey Kirillov
Section: misc
Build-Depends: debhelper (>= 8.0.0)
Priority: optional
Standards-Version: 0.1.6

Package: zbxsend
Description: Module used to send metrics to Zabbix.
Architecture: all
Depends: ${shlibs:Depends}, ${misc:Depends}, python (>=2.6)
Empty file added debian/files
Empty file.
6 changes: 6 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/make -f
# -*- makefile -*-
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
%:
dh $@
49 changes: 49 additions & 0 deletions manifests/centos.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
include system_requirements
include zbxsend

Class['system_requirements'] -> Class['zbxsend']

class system_requirements {
# Sets up basic system requirements

package { 'python':
ensure => present,
provider => yum,
}

package { 'python-devel':
ensure => present,
provider => yum,
}

package { 'rpm-build':
ensure => present,
provider => yum,
}

package { 'python-setuptools':
ensure => present,
provider => yum,
}

exec { 'python-pip':
command => 'easy_install pip==1.5.4',
path => '/usr/bin/',
require => Package['python-setuptools']
}

}

class zbxsend {
exec { 'build deb':
command => 'sudo rm -rf vagrant ; cp -r /vagrant . && cd vagrant && sudo make rpms',
path => '/bin/:/usr/bin',
require => [Exec['python-pip']]
}

exec { 'install deb':
command => 'sudo rpm -ivh vagrant/artifacts/rpms/noarch/*.rpm',
path => '/bin/:/usr/bin',
require => [Exec['build deb']]
}
}
56 changes: 56 additions & 0 deletions manifests/ubuntu.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
include system_requirements
include zbxsend

Class['system_requirements'] -> Class['zbxsend']

class system_requirements {
# Sets up basic system requirements

package { 'python':
ensure => present,
provider => apt,
}

package { 'python-dev':
ensure => present,
provider => apt,
}

package { 'debhelper':
ensure => present,
provider => apt,
}

package { 'devscripts':
ensure => present,
provider => apt,
}

package { 'python-setuptools':
ensure => present,
provider => apt,
}

exec { 'python-pip':
command => 'easy_install pip==1.5.4',
path => '/usr/bin/',
require => Package['python-setuptools']
}

}

class zbxsend {
# Sets up the zbxsend project by linking things through so updates are live.
# THIS SHOULD NOT BE USED AS A TEMPLATE FOR PRODUCTION
exec { 'build deb':
command => 'sudo rm -rf vagrant ; cp -r /vagrant . && cd vagrant && sudo make debs',
path => '/bin/:/usr/bin',
require => [Exec['python-pip']]
}

exec { 'install deb':
command => 'sudo dpkg -i vagrant/artifacts/debs/*.deb',
path => '/bin/:/usr/bin',
require => [Exec['build deb']]
}
}
34 changes: 34 additions & 0 deletions zbxsend.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")}

Name: zbxsend
Version: 0.1.6
Release: 1%{?dist}
Summary: Module used to send metrics to Zabbix.

License: ASLv2
URL: https://github.com/pistolero/zbxsend
Source0: %{name}-%{version}.tar.gz
BuildArch: noarch
BuildRequires: python-devel

%description


%prep
%setup -q


%build
%{__python} setup.py build


%install
rm -rf $RPM_BUILD_ROOT
%{__python} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT

%files
%{python_sitelib}/*

%changelog
* Fri Apr 24 2015 Tony Rogers <[email protected]> - 0.1.6-1
- Initial Spec