RPM repository SLES12 and RPM packaging

Introduction

The following post will describe how a rpm repository to install packaged applications from can be configured and how the build process does work.

General

Preconditions

The documentation is written and tested for SUSE Enterprise Linux 12 (SP1) (SLES12) as build- and reposerver.

The following packages need to be installed:

  • createrepo
  • httpd
  • rpmbuild

Operation Protocol

The following steps can be performed to create a rpm repository and build an rpm package.

Access control lists

To access the logfiles of the httpd service and to be able to create the repository in the htdocs directory one will need the following access control list settings:

sudo setfacl -R -m u:user:r-X /var/log/apache2
sudo setfacl -R -m u:user:rwX /srv/www/htdocs

(r: read, w: write, x: execute, X: directory access)

Create rpm repository

We will only build packages on x86_64 architecture for SLES12. One can create additional packages for different architectures or linux derivates using the example directory structure.

mkdir -p /srv/www/htdocs/repo/SUSE/Updates/12/x86_64
createrepo /srv/www/htdocs/repo/SUSE/Updates/12/x86_64

Build rpm package

To build an example minimal rpm package for the rpm repository the following steps are needed. All steps to achieve this I did not find out myself. The source is an article of devzero2000  (http://stackoverflow.com/questions/880227/what-is-the-minimum-i-have-to-do-to-create-an-rpm-file/1165200#1165200).

Create rpm build environment

mkdir -p ~/rpmbuild/{RPMS,SRPMS,BUILD,SOURCES,SPECS,tmp}

cat <<EOF >~/.rpmmacros
%_topdir   %(echo $HOME)/rpmbuild
%_tmppath  %{_topdir}/tmp
EOF

cd ~/rpmbuild

Create a tarball of the project

This step shows how to create a tarball that consists of a war file for deployment on Apache Tomcat and a web page, because the application I tested it with has a rest backend running in a tomcat container and a Angular web app for the client side.

mkdir myapp-1.0
mkdir -p myapp-1.0/srv/www/htdocs/
mkdir -p myapp-1.0/usr/share/tomcat/webapps/

Now copy the webapp in a subfolder of the htdocs folder and the war file in the webapps directory (this is only a minimal example, in production the apache2 configuration in /etc/apache2/conf.d with an alias to some folder in /usr/share/ containing the web app should be used).

Afterwards create the tar ball and copy it to SOURCES:

tar -zcvf myapp-1.0.tar.gz myapp-1.0
cp msbs-1.0.tar.gz SOURCES/

Now create a spec file with the basic install commands:

cat <<EOF > SPECS/myapp.spec

%define        __spec_install_post %{nil}
%define          debug_package %{nil}
%define        __os_install_post %{_dbpath}/brp-compress

Summary: MyApp - An example application
Name: myapp
Version: 1.0
Release: 1
License: Your license
Group: Tools
SOURCE0 : %{name}-%{version}.tar.gz
URL: https://science-site.de

BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root

%description
%{summary}
%prep
%setup -q

%build
# Empty section.

%install

rm -rf %{buildroot}
mkdir -p  %{buildroot}

# in builddir
cp -a * %{buildroot}


%clean
rm -rf %{buildroot}


%files
%defattr(-,root,root,-)
# %config(noreplace) %{_sysconfdir}/%{name}/%{name}.conf
/srv/*
/usr/*

%changelog
* Wed Nov 27 2016   Your Name <your@mailaddress.de> 1.0-1
- First Build
EOF

Afterwards the package can be created using the following command:

rpmbuild -ba SPECS/myapp.spec

Deploy rpm package

To deploy the created package to the repository the rpm file has to be copied and the repository has to be refreshed:

cp RPMS/x86_64/myapp-1.0-1.x86_64.rpm /srv/www/htdocs/repo/SUSE/Updates/12/x86_64
sudo createrepo --update /srv/www/htdocs/repo/SUSE/Updates/12/x86_64

Add repository on target host

The repository can now be added as source to install using zypper or yum. The following example describes the process using zypper.

cat <<EOF > /etc/zypp/repos.d/MYAPP-SLE12.repo
[MYAPP-REPO]
name=MYAPP-REPO
enabled=1
autorefresh=1
baseurl=http://hostname/repo/SUSE/Updates/12/x86_64
type=rpm-md
EOF

After refreshing the repositories the new package can be installed:

sudo zypper refresh
sudo zypper search myapp

S | Name | Summary                                                                                    | Type   
--+------+--------------------------------------------------------------------------------------------+--------
i | myapp | MyApp - An example application                                                            | package

sudo zypper install myapp

Next steps

The next steps should be to configure package dependencies for the rpm package (Tomcat and httpd), to use an Apache alias for the web app and to add an undeploy step before installing the tomcat war.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.