From dd19d2c306972b0927b606ec5a78d4055c067af5 Mon Sep 17 00:00:00 2001 From: Tony Rogers Date: Fri, 24 Apr 2015 23:32:17 -0500 Subject: [PATCH] adding Vagrantfile and Makefile to support building RPMs and DEBs --- .gitignore | 4 +- Makefile | 90 +++++++++++++++++++++++++++++++++++++++++++++ README.txt | 20 ++++++++++ Vagrantfile | 41 +++++++++++++++++++++ debian/changelog | 5 +++ debian/control | 11 ++++++ debian/files | 0 debian/rules | 6 +++ manifests/centos.pp | 49 ++++++++++++++++++++++++ manifests/ubuntu.pp | 56 ++++++++++++++++++++++++++++ zbxsend.spec | 34 +++++++++++++++++ 11 files changed, 315 insertions(+), 1 deletion(-) create mode 100644 Makefile create mode 100644 Vagrantfile create mode 100644 debian/changelog create mode 100644 debian/control create mode 100644 debian/files create mode 100644 debian/rules create mode 100644 manifests/centos.pp create mode 100644 manifests/ubuntu.pp create mode 100644 zbxsend.spec diff --git a/.gitignore b/.gitignore index 7abc146..1c83f0a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ build dist *.egg-info .project -.pydevproject \ No newline at end of file +.pydevproject +artifacts +.vagrant diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7db9c6f --- /dev/null +++ b/Makefile @@ -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}/ + diff --git a/README.txt b/README.txt index 52fca96..041a776 100644 --- a/README.txt +++ b/README.txt @@ -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 diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..584b165 --- /dev/null +++ b/Vagrantfile @@ -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 diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..b69f822 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +zbxsend (0.1.6) unstable; urgency=low + + * Initial release + + -- Tony Rogers Sat, 25 Apr 2015 01:14:00 +0500 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..38b5331 --- /dev/null +++ b/debian/control @@ -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) diff --git a/debian/files b/debian/files new file mode 100644 index 0000000..e69de29 diff --git a/debian/rules b/debian/rules new file mode 100644 index 0000000..cc6c071 --- /dev/null +++ b/debian/rules @@ -0,0 +1,6 @@ + #!/usr/bin/make -f + # -*- makefile -*- + # Uncomment this to turn on verbose mode. + #export DH_VERBOSE=1 + %: + dh $@ diff --git a/manifests/centos.pp b/manifests/centos.pp new file mode 100644 index 0000000..db8c634 --- /dev/null +++ b/manifests/centos.pp @@ -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']] + } +} diff --git a/manifests/ubuntu.pp b/manifests/ubuntu.pp new file mode 100644 index 0000000..08f7b35 --- /dev/null +++ b/manifests/ubuntu.pp @@ -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']] + } +} diff --git a/zbxsend.spec b/zbxsend.spec new file mode 100644 index 0000000..02268c7 --- /dev/null +++ b/zbxsend.spec @@ -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 - 0.1.6-1 +- Initial Spec