From 952a240852c2e8d528a0d73c3fd5a229d396282c Mon Sep 17 00:00:00 2001 From: Luis Pabon Date: Tue, 14 May 2013 15:50:49 -0400 Subject: rpm: Enable creation of RPMs This is the first step. I have confirmed that I can install, update, and remove. I have also setup the ability for Jenkins to pass the BuildNumber and use that value as the release number for the RPM. The RPM depends on Grizzly(1.8.0) Swift from OpenStack. To verify you may need to add the appropiate repo file to your Fedora/RHEL system: http://repos.fedorapeople.org/repos/openstack/openstack-grizzly I have not had the opportunity to test that G4S itself works once installed, but I plan on doing that as the next phase. Change-Id: Ib90f335f5e1e4fc552c32e00ff29b6e8a680c42a Signed-off-by: Luis Pabon Reviewed-on: http://review.gluster.org/5006 Reviewed-by: Peter Portante Reviewed-by: Kaleb KEITHLEY Tested-by: Kaleb KEITHLEY --- README | 8 ++- gluster-swift.spec | 78 ----------------------------- gluster/swift/__init__.py | 23 ++++++--- glusterfs-openstack-swift.spec | 87 ++++++++++++++++++++++++++++++++ makerpm.sh | 110 +++++++++++++++++++++++++++++++++++++++++ pkgconfig.py | 8 +++ setup.py | 2 +- 7 files changed, 230 insertions(+), 86 deletions(-) delete mode 100644 gluster-swift.spec create mode 100644 glusterfs-openstack-swift.spec create mode 100644 makerpm.sh create mode 100644 pkgconfig.py diff --git a/README b/README index 1dd12e3..5f7df7a 100644 --- a/README +++ b/README @@ -19,4 +19,10 @@ Command to stop the servers (TBD) swift-init main stop Command to gracefully reload the servers - swift-init main reload \ No newline at end of file + swift-init main reload + +Building RPMs. RPMs will be located in the 'build' directory. + $ bash makerpm.sh + +Building RPM with a specific release value, useful for automatic Jenkin builds + $ PROG_RELEASE=123 bash makerpm.sh diff --git a/gluster-swift.spec b/gluster-swift.spec deleted file mode 100644 index af80e40..0000000 --- a/gluster-swift.spec +++ /dev/null @@ -1,78 +0,0 @@ -############################################################################################################ -# Command to build rpms.# -# $ rpmbuild -ta %{name}-%{version}-%{release}.tar.gz # -############################################################################################################ -# Setting up the environment. # -# * Create a directory %{name}-%{version} under $HOME/rpmbuild/SOURCES # -# * Copy the contents of gluster directory into $HOME/rpmbuild/SOURCES/%{name}-%{version} # -# * tar zcvf %{name}-%{version}-%{release}.tar.gz $HOME/rpmbuild/SOURCES/%{name}-%{version} %{name}.spec # -# For more information refer # -# http://fedoraproject.org/wiki/How_to_create_an_RPM_package # -############################################################################################################ - -%if ! (0%{?fedora} > 12 || 0%{?rhel} > 5) -%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")} -%endif - -%define _confdir %{_sysconfdir}/swift -%define _version 1.3 -%define _release 0 - -Summary : GlusterFS Integration with OpenStack Object Storage (Swift). -Name : gluster-for-swift -Version : %{_version} -Release : %{_release} -Group : Application/File -Vendor : Red Hat Inc. -Source0 : %{name}-%{version}-%{release}.tar.gz -Packager : gluster-users@gluster.org -License : Apache -BuildArch: noarch -Requires : memcached -Requires : openssl -Requires : python -Requires : openstack-swift >= 1.8.0 -Requires : openstack-swift-account >= 1.8.0 -Requires : openstack-swift-container >= 1.8.0 -Requires : openstack-swift-object >= 1.8.0 -Requires : openstack-swift-proxy >= 1.8.0 - -%description -Gluster-For-Swift (G4S, pronounced "gee-force") integrates GlusterFS as an -alternative back end for OpenStack Object Storage (Swift) leveraging the -existing front end OpenStack Swift code. Gluster volumes are used to store -objects in files, containers are maintained as top-level directories of volumes, -where accounts are mapped one-to-one to gluster volumes. - -%prep -%setup -q - -%build -%{__python} setup.py build - -%install -rm -rf %{buildroot} - -%{__python} setup.py install -O1 --skip-build --root %{buildroot} - -mkdir -p %{buildroot}/%{_confdir}/ -cp -r etc/* %{buildroot}/%{_confdir}/ - -mkdir -p %{buildroot}/%{_bindir}/ -cp bin/gluster-swift-gen-builders %{buildroot}/%{_bindir}/ - -%clean -rm -rf %{buildroot} - -%files -%defattr(-,root,root) -%{python_sitelib}/gluster -%{python_sitelib}/gluster_swift-%{version}-*.egg-info -%{_bindir}/gluster-swift-gen-builders -%dir %{_confdir} -%config %{_confdir}/account-server/1.conf-gluster -%config %{_confdir}/container-server/1.conf-gluster -%config %{_confdir}/object-server/1.conf-gluster -%config %{_confdir}/swift.conf-gluster -%config %{_confdir}/proxy-server.conf-gluster -%config %{_confdir}/fs.conf-gluster diff --git a/gluster/swift/__init__.py b/gluster/swift/__init__.py index ef350fd..14bb4e8 100644 --- a/gluster/swift/__init__.py +++ b/gluster/swift/__init__.py @@ -1,10 +1,18 @@ -""" Gluster Swift UFO """ +""" Gluster for Swift """ -class Version(object): - def __init__(self, canonical_version, final): +class PkgInfo(object): + def __init__(self, canonical_version, name, final): self.canonical_version = canonical_version + self.name = name self.final = final + def save_config(self, filename): + """Crates a file with the package configuration + which can be sourced by a bash script""" + with open(filename, 'w') as fd: + fd.write("PKG_NAME=%s\n" % self.name) + fd.write("PKG_VERSION=%s\n" % self.canonical_version) + @property def pretty_version(self): if self.final: @@ -13,6 +21,9 @@ class Version(object): return '%s-dev' % (self.canonical_version,) -_version = Version('1.1', False) -__version__ = _version.pretty_version -__canonical_version__ = _version.canonical_version +### +### Change the Package version here +### +_pkginfo = PkgInfo('1.8.0', 'glusterfs-openstack-swift', False) +__version__ = _pkginfo.pretty_version +__canonical_version__ = _pkginfo.canonical_version diff --git a/glusterfs-openstack-swift.spec b/glusterfs-openstack-swift.spec new file mode 100644 index 0000000..f9b8643 --- /dev/null +++ b/glusterfs-openstack-swift.spec @@ -0,0 +1,87 @@ +############################################################################################################ +# Command to build rpms.# +# $ rpmbuild -ta %{name}-%{version}-%{release}.tar.gz # +############################################################################################################ +# Setting up the environment. # +# * Create a directory %{name}-%{version} under $HOME/rpmbuild/SOURCES # +# * Copy the contents of gluster directory into $HOME/rpmbuild/SOURCES/%{name}-%{version} # +# * tar zcvf %{name}-%{version}-%{release}.tar.gz $HOME/rpmbuild/SOURCES/%{name}-%{version} %{name}.spec # +# For more information refer # +# http://fedoraproject.org/wiki/How_to_create_an_RPM_package # +############################################################################################################ + +%if ! (0%{?fedora} > 12 || 0%{?rhel} > 5) +%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")} +%endif + +%define _confdir %{_sysconfdir}/swift + +# The following values are provided by passing the following arguments +# to rpmbuild. For example: +# --define "_version 1.0" --define "_release 1" --define "_name g4s" +# +%{!?_version:%define _version XXX} +%{!?_release:%define _release XXX} +%{!?_name:%define _name XXX} + +Summary : GlusterFS Integration with OpenStack Object Storage (Swift). +Name : %{_name} +Version : %{_version} +Release : %{_release} +Group : Application/File +Vendor : Red Hat Inc. +Source0 : %{name}-%{version}-%{release}.tar.gz +Packager : gluster-users@gluster.org +License : Apache +BuildArch: noarch +Requires : memcached +Requires : openssl +Requires : python +Requires : openstack-swift >= 1.8.0 +Requires : openstack-swift-account >= 1.8.0 +Requires : openstack-swift-container >= 1.8.0 +Requires : openstack-swift-object >= 1.8.0 +Requires : openstack-swift-proxy >= 1.8.0 + +%description +Gluster-For-Swift (G4S, pronounced "gee-force") integrates GlusterFS as an +alternative back end for OpenStack Object Storage (Swift) leveraging the +existing front end OpenStack Swift code. Gluster volumes are used to store +objects in files, containers are maintained as top-level directories of volumes, +where accounts are mapped one-to-one to gluster volumes. + +%prep +%setup -q + +%build +%{__python} setup.py build + +%install +rm -rf %{buildroot} + +%{__python} setup.py install -O1 --skip-build --root %{buildroot} + +mkdir -p %{buildroot}/%{_confdir}/ +cp -r etc/* %{buildroot}/%{_confdir}/ + +mkdir -p %{buildroot}/%{_bindir}/ +cp bin/gluster-swift-gen-builders %{buildroot}/%{_bindir}/ + +# Remove tests +%{__rm} -rf %{buildroot}/%{python_sitelib}/test + +%clean +rm -rf %{buildroot} + +%files +%defattr(-,root,root) +%{python_sitelib}/gluster +%{python_sitelib}/gluster_swift-%{version}-*.egg-info +%{_bindir}/gluster-swift-gen-builders +%dir %{_confdir} +%config %{_confdir}/account-server/1.conf-gluster +%config %{_confdir}/container-server/1.conf-gluster +%config %{_confdir}/object-server/1.conf-gluster +%config %{_confdir}/swift.conf-gluster +%config %{_confdir}/proxy-server.conf-gluster +%config %{_confdir}/fs.conf-gluster diff --git a/makerpm.sh b/makerpm.sh new file mode 100644 index 0000000..6427df6 --- /dev/null +++ b/makerpm.sh @@ -0,0 +1,110 @@ +#!/bin/bash + +# Simple script to create RPMs for G4S + +cleanup() +{ + rm -rf ${RPMBUILDDIR} > /dev/null 2>&1 + rm -f ${PKGCONFIG} > /dev/null 2>&1 +} + +fail() +{ + cleanup + echo $1 + exit $2 +} + +create_dir() +{ + if [ ! -d "$1" ] ; then + mkdir -p "$1" + if [ $? -ne 0 ] ; then + fail "Unable to create dir $1" $? + fi + fi +} + +gittotar() +{ + # Only archives committed changes + git archive --format=tar.gz --prefix=${SRCTAR_DIR}/ HEAD --output ${SRCTAR} + if [ $? -ne 0 ] ; then + fail "Unable to create git archive" $? + fi +} + +prep() +{ + rm -rf ${RPMBUILDDIR} > /dev/null 2>&1 + create_dir ${RPMBUILDDIR} + + # Create a tar file out of the current committed changes + gittotar + +} + +create_rpm() +{ + # Create the rpm + # _topdir Notifies rpmbuild the location of the root directory + # containing the RPM information + # _release Allows Jenkins to setup the version using the + # build number + rpmbuild --define "_topdir ${RPMBUILDDIR}" \ + --define "_release ${PKG_RELEASE}" \ + --define "_version ${PKG_VERSION}" \ + --define "_name ${PKG_NAME}" \ + -ta ${SRCTAR} + if [ $? -ne 0 ] ; then + fail "Unable to create rpm" $? + fi + + # Move the rpms to the root directory + mv ${RPMBUILDDIR_RPMS}/noarch/*rpm ${BUILDDIR} + if [ $? -ne 0 ] ; then + fail "Unable to move rpm to ${BUILDDIR}" $? + fi + + echo "RPMS are now available in ${BUILDDIR}" +} + +################## MAIN ##################### + +# Create a config file with the package information +PKGCONFIG=${PWD}/pkgconfig.in +env python pkgconfig.py +if [ ! -f "${PKGCONFIG}" ] ; then + fail "Unable to create package information file ${PKGCONFIG}" 1 +fi + +# Get PKG_NAME and PKG_VERSION +. ${PKGCONFIG} +if [ -z "${PKG_NAME}" ] ; then + fail "Unable to read the package name from the file created by pkgconfig.py" 1 +fi +if [ -z "${PKG_VERSION}" ] ; then + fail "Unable to read the package version from the file created by pkgconfig.py" 1 +fi + +# +# This can be set by JENKINS builds +# If the environment variable PKG_RELEASE +# has not been set, then we set it locally to +# a default value +# +if [ -z "$PKG_RELEASE" ] ; then + PKG_RELEASE=0 +fi + + +BUILDDIR=$PWD/build +RPMBUILDDIR=${BUILDDIR}/rpmbuild +RPMBUILDDIR_RPMS=${RPMBUILDDIR}/RPMS +SRCNAME=${PKG_NAME}-${PKG_VERSION}-${PKG_RELEASE} +SRCTAR_DIR=${PKG_NAME}-${PKG_VERSION} +SRCTAR=${RPMBUILDDIR}/${SRCNAME}.tar.gz + +prep +create_rpm +cleanup diff --git a/pkgconfig.py b/pkgconfig.py new file mode 100644 index 0000000..2895ceb --- /dev/null +++ b/pkgconfig.py @@ -0,0 +1,8 @@ +# Simple program to save all package information +# into a file which can be sourced by a bash script + +from gluster.swift import _pkginfo as pkginfo + +PKGCONFIG='pkgconfig.in' + +pkginfo.save_config(PKGCONFIG) diff --git a/setup.py b/setup.py index 2da9353..7c23a67 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ setup( license='Apache License (2.0)', author='Red Hat, Inc.', author_email='gluster-users@gluster.org', - url='https://gluster.org/', + url='https://forge.gluster.org/gluster-swift', packages=find_packages(exclude=['test', 'bin']), test_suite='nose.collector', classifiers=[ -- cgit