Configure, Pack and Distribute: An RPM Creation Workshop
Upcoming SlideShare
Loading in...5
×
 

Configure, Pack and Distribute: An RPM Creation Workshop

on

  • 3,093 views

This session is for you if:...

This session is for you if:
You are an ISV who wants to create appliances from your software
You are a customer with your own software development team who wants to package this software for deploying it in the data center—as a package or on your self-built appliance
You have trouble with your data center due to commercial software that is not packaged in a secure and maintainable way
In this workshop you will learn how to build Linux RPM packages. We will demonstrate packaging from source code, and for commercial software (existing as a tar-ball). You will learn best practices and get links to further information.

Statistics

Views

Total Views
3,093
Views on SlideShare
3,080
Embed Views
13

Actions

Likes
2
Downloads
70
Comments
0

1 Embed 13

http://www.slideshare.net 13

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Configure, Pack and Distribute: An RPM Creation Workshop Configure, Pack and Distribute: An RPM Creation Workshop Presentation Transcript

  • Configure, Pack, Distribute An RPM Creation Workshop Bart Whiteley Matthias G. Eckermann Senior Software Engineer Senior Product Manager Novell, Inc. SUSE Linux Enterprise ® bwhiteley@novell.com mge@novell.com
  • Agenda Part I: Challenges of software management Part II: Introduction into RPM – Overview of RPM build process – The RPM “Spec” file – Dependencies – Building RPMs Part III: Hands-on – Building from source locally – Building in a change-root environment using the “build” tool – Building from a binary package – Building in the BuildService 2 © Novell, Inc. All rights reserved.
  • Part I: Challenges of Software Management
  • Challenges of Software Management ? 4 © Novell, Inc. All rights reserved.
  • Requirements to a Sophisticated Software Management System • Systems management and consistency – Easy to install and uninstall – Easy to determine what is installed, and where – Leverage package management tools > ZENworks Linux Management ® • Dependency management • Life-cycle management – Easy to create packages > Leverage openSUSE Build Service ® – Easy to update and upgrade • Security and reliability – Easy to verify the installation 5 © Novell, Inc. All rights reserved.
  • Applications • Executable (binary), libraries, data files, icons, Executable mime types • Documentation – normally included, might be removed Libraries Data during installation due to space constraints Configuration • Configuration – normally created after installation, Documentation can be pre-configured or defaults are pre-installed 6 © Novell, Inc. All rights reserved.
  • Applications and Metadata • Application • Meta-data – Support for installation and management – Description, version, requirements and dependencies – what needs to be installed on the system to be able to run the application or its parts • Install, upgrade and remove process – Using system provided software management stack – No interaction needed (useful for auto-installation, appliances) – Clean remove – no leftovers, configuration files optionally 7 © Novell, Inc. All rights reserved.
  • High Level Package Overview Package Meta-data Application Version Executable Description Libraries Data Requirements Configuration Documentation 8 © Novell, Inc. All rights reserved.
  • Build Overview - Theory Installable Metadata Source File Software Packs Source File Application Source File Source File Tool Local changes Archive Patch Patch 9 © Novell, Inc. All rights reserved.
  • Part II: Introduction into RPM
  • Build Overview – RPM SPEC File Binary RPM Source File Source File SourceFile Source SourceFile File rpmbuild-ba Patch Source RPM Patch Patch 11 © Novell, Inc. All rights reserved.
  • What Is it RPM? • RPM Package Manager – Program to manipulate with packages (rpm files) • Package file format specification – Files are named like: make-3.81-2.i586.rpm – [name]-[version]-[subversion].[architecture].rpm or just file.rpm • Library to manipulate (install, remove) rpm packages • Baseline of Linux Standard Base (LSB) packaging • The most common format in Enterprise Linux 12 © Novell, Inc. All rights reserved.
  • RPM Philosophy • Standard, uniform and clean way to build, install, remove, update and manage software • Multi-architecture support • Non-interactive install process, easy to automate • Security – packages can be cryptographically signed • Reliability – package does not affect contents of other packages • Dependencies – package can be installed only if requirements are already installed • Verification – all files included in a package can be verified for permissions or contents modification • Building software – reproducible – unattended 13 © Novell, Inc. All rights reserved.
  • Inputs and Outputs • Inputs – Spec file > Directs RPM in the build process – Source files > May be source archives (e.g. tarball or .zip) or single files – Patches > Patches to the pristine source archive, usually created with 'diff -u' • Outputs – One or more binary RPMS – Source RPM > An archive of the inputs 14 © Novell, Inc. All rights reserved.
  • The Spec File • The preamble section • The prep section • The build section • The install section • Install and uninstall scripts • The clean section • File list 15 © Novell, Inc. All rights reserved.
  • Preamble • Required tags • Optional tags – Name – Source – Patch – Version – Url – Release – Requires – Summary – Provides – License – Conflicts – Obsoletes – Group – PreReq – %description – BuildArch – BuildRoot – Serial – BuildRequires 16 © Novell, Inc. All rights reserved.
  • Preamble Example # # Example spec file for cdplayer app... # Summary: A CD player app that rocks! Name: cdplayer Version: 1.0 Release: 1 License: GPL Group: Applications/Sound Source: ftp://ftp.gnomovision.com/pub/cdplayer/cdplayer-1.0.tgz URL: http://www.gnomovision.com/cdplayer/cdplayer.html Distribution: WSS Linux Vendor: White Socks Software, Inc. Packager: Santa Claus <sclaus@northpole.com> %description It slices! It dices! It's a CD player app that can't be beat. By using the resonant frequency of the CD itself, it is able to simulate 20X oversampling. This leads to sound quality that cannot be equaled with more mundane software... 17 © Novell, Inc. All rights reserved.
  • The % Prep Section • Prepares the build environment • Executed as a bash script – Automatically removes remnants of a previous build – Expand source archive – Apply patches • Macros – %setup > Often all that is needed in %prep – %patch %prep > Apply a patch to the sources %setup 18 © Novell, Inc. All rights reserved.
  • The % Build Section • Compile the software • Executed as a bash script %build ./configure make 19 © Novell, Inc. All rights reserved.
  • The % Install Section • Executed as a bash script • Runs during the package build • Does not run during package installation • Install the software into a staging area – $RPM_BUILD_ROOT %install %{__rm} -rf $RPM_BUILD_ROOT %{__mkdir} $RPM_BUILD_ROOT make DESTDIR=$RPM_BUILD_ROOT install 20 © Novell, Inc. All rights reserved.
  • The % Clean Section • This section is optional • Can be used to clean up files that are not part of the application's normal build area • Executed as a bash script 21 © Novell, Inc. All rights reserved.
  • The % Files Section • Lists the files that are part of the package • Declare file ownership and permissions • Special handling for configuration files – %config – %config(noreplace) %files %defattr(-,root,root) %config(noreplace) /etc/foo.conf /usr/bin/* /usr/lib/* 22 © Novell, Inc. All rights reserved.
  • Install/Uninstall Scripts • %pre – Executed prior to package installation • %post – Executed after package installation • %preun – Executed prior to package deletion • %postun – Executed after package deletion • Best to do as much as possible in build scripts, and as little as possible in install/uninstall scripts 23 © Novell, Inc. All rights reserved.
  • Scripts During Upgrade • Scripts can complicate upgrades – %preun and %postun scripts also run during upgrade – The order of execution is not intuitive > Run %pre of new package > Install new files > Run %post of new package > Run %preun of old package > Delete any old files not overwritten by newer ones > Run %postun of old package – Important to get scripts right the first time > If you release a package with a bad %preun or %postun script, you can't fix it with an update 24 © Novell, Inc. All rights reserved.
  • Distinguishing Upgrade from Delete • The first parameter passed to RPM scripts is the number of copies of the package that will be installed after the current package is installed or deleted – In %preun and %postun, if $1 is 0, the package is being deleted – In %preun and %postun, if $1 is > 0, the package is being upgraded %postun if [ $1 -gt 0 ]; then # package being upgraded else # package being deleted; cleanup fi 25 © Novell, Inc. All rights reserved.
  • Dependencies • If anything listed in • Manual dependencies % files is a shared can be declared with library, its soname Preamble tags is added to the capabilities of – Requires the package – Provides • For all executables and shared libraries – Obsoletes in %files, ldd is – Conflicts used to determine the package – PreReq requirements 26 © Novell, Inc. All rights reserved.
  • RPMbuild RPMbuild -bp execute %prep -bc execute %prep, %build -bi execute %prep, %build, %install -bb execute %prep, %build, %install (bin) -ba execute %prep, %build, %install (bin, src) 27 © Novell, Inc. All rights reserved.
  • Build Environment • The RPM build directory structure – /usr/src/packages/SOURCES %{_sourcedir} > Contains source files and patches – /usr/src/packages/SPECS %{_specdir} > Contains Spec files – /usr/src/packages/BUILD %{_builddir} > Sources are unpacked and patched here > Compile takes place here – /usr/src/packages/RPMS/<arch> %{_rpmdir} > Binary RPMs end up here – /usr/src/packages/SRPMS %{_srcrpmdir} > Source RPMs end up here 28 © Novell, Inc. All rights reserved.
  • Customized Build Environment • To build as a non-root user (good idea), define different paths for the build environment. – In ~/.rpmmacros $ cat ~/.rpmmacros %_topdir /home/jdoe/packages – On the command line $ cat ~/bin/myrpmbuild #!/bin/sh TOPDIR=${PWD}/rpmbuild mkdir -p ${TOPDIR}/{RPMS,SRPMS,SPECS,SOURCES,BUILD,tmp} rpmbuild --define "_topdir ${TOPDIR}" --define "_sourcedir ${PWD}" --define "_tmppath ${TOPDIR}/tmp" "$@" 29 © Novell, Inc. All rights reserved.
  • Benefits of Using a Standard Package Format – Such as RPM • Software development more manageable • Multi architecture support easier • Software installation more secure • Software deployment manageable • Handling multiple version easy • Consistent systems and compliance 30 © Novell, Inc. All rights reserved.
  • Part III: Hands-on
  • Building from Source Locally (1) Source Code // / / Copyr i ght ( c) 2010 SUSE Li nux Pr oduct s GmbH w com but t on. set Geom r y( 32, 32, 448, 192) ; el e_ et / / Aut hor : M t hi as G. Ecker m at ann < ge@ m novel l . com> QObj ect : : connect ( / / Li cense: GPL v2 &w com but t on, el e_ // SI GNAL( cl i cked( ) ) , &hel l o_ br ai nshar e, #i ncl ude <QAppl i cat i on> SLOT( qui t ( ) ) #i ncl ude <QFont > ); #i ncl ude <QPushBut t on> m n_w ndow show ) ; ai i . ( #i ncl ude < i dget > QW r et ur n hel l o_ br ai nshar e. exec( ) ; i nt m n( i nt ar gc, char *ar gv[ ] ) { ai } QAppl i cat i on hel l o_ br ai nshar e( ar gc, ar gv ) ; QW dget m n_w ndow i ai i ; m n_ w ndow r esi ze( 512, 256 ) ; ai i . QPushBut t on w comel e_but t on( " W com t o Br ai nshar e 2010! el e nNovel l - M aki ng I T W k as One. " , or &m n_ w ndow ai i ); w com but t on. set Font ( el e_ QFont ( " Ar i al " , 16, QFont : : Bol d ) ); 32 © Novell, Inc. All rights reserved.
  • 1. Building from Source Locally (2) .spec file # Nam e: hel l o_br ai nshar e % nst al l i Li cense: GPL v2 i f [ - n " $RPM _BUI LD_ROOT" ] ; t hen Ver si on: 1 [ " $RPM _BUI LD_ROOT" ! = " / " ] && Rel ease: 1. m ge r m - r f $RPM BUI LD_ROOT && _ Sum ar y: m Hel l o Br ai nshar e 2010 m r $RPM kdi _BUI LD_ROOT Sour ce0: hel l o_br ai nshar e. cpp fi Gr oup: Pr oduct i vi t y m r -p kdi Bui l dRoot : % m {_t ppat h}/ % {nam bui l d e}- $RPM _BUI LD_ROOT/ usr / bi n Bui l dRequi r es: l i bqt 4- devel i nst al l hel l o_br ai nshar e $RPM _BUI LD_ROOT/ usr / bi n/ %descr i pt i on Hel l o Br ai nshar e 2010 pr ogr am f or demonst r at i on % i l es f pur poses. % at t r ( - , r oot , r oot ) def / usr / bi n/ hel l o_br ai nshar e % ep pr % up - c - T set % ean cl cp - a % 0} . {S: i f [ - n " $RPM _BUI LD_ROOT" ] ; t hen [ " $RPM _BUI LD_ROOT" ! = " / " ] && % ld bui r m - r f $RPM BUI LD_ROOT _ g++ - I / usr / i ncl ude/ Qt Gui - l Qt Cor e - l Qt Gui fi $RPM OPT_ FLAGS _ - s - o hel l o_br ai nshar e hel l o_br ai nshar e. cpp %changel og * M on M ar 08 2010 - m novel l . com ge@ - i ni t i al ver si on 33 © Novell, Inc. All rights reserved.
  • Challenges and Risks When Building from Source Locally • Software-build might interfere with the buildhost – Security and Consistency: Risk of polluting the host with freshly built software – Resource Constraints: a build process might need lots of disk space, memory, compute power • Software-build might depend on special settings of the local build-host – violates goal of reproducible software builds • Multi-User and Multi-Architecture goal not easy to implement – even building 32bit on 64bit hosts is not always easy 34 © Novell, Inc. All rights reserved.
  • Alternatives to Building from Source Locally • Change root environment – Create a build system within the host system; same kernel, but userland is separated – Mitigates: security, consistency, reproducible – Controls: Multi-architecture requirements. – Does not mitigate: Resource constraints – Technology used by the “build” tool, see #2 below • Virtualization – Create a build system within the host system; completely separated – Mitigates: security, consistency, reproducible – Controls: Resource constraints, Multi-architecture requirements – See #4 below: openSUSE Buildservice ® 35 © Novell, Inc. All rights reserved.
  • 2. Building in a Change-root Environment Using the “Build” Tool (1) • “build” is available on the SUSE Linux Enterprise 11 ® Software Development Kit and on openSUSE ® • Build installs a minimal SUSE Linux as build system into some directory and will chroot to this system to compile the package. • Special .spec file options to support build # norootforbuild # needsrootforbuild 36 © Novell, Inc. All rights reserved.
  • Building in a Change-root Environment Using the “Build” Tool (2) Functionality overview build [--clean|--no-init] [--no-checks] [--repository PATH] [--rpms path1:path2:...] [--arch arch1:arch2:...] [--root buildroot] [specfile|srcrpm] build --verify • Environment variables BUILD_RPMS BUILD_ROOT BUILD_RPM_BUILD_STAGE 37 © Novell, Inc. All rights reserved.
  • 3. Building from a Binary Package (1) • Differences – No compile stage necessary – Can be used for nearly any type of existing software • Challenges – Binary packages might need an “installer” to run – system specific configuration – Installation paths not following the Linux Filesystem Hierarchy Standard (FHS) • Caveats – Legal aspects – Licensing 38 © Novell, Inc. All rights reserved.
  • Building from a Binary Package (2) Binary Package Example: Mendeley Desktop (freeware, non-opensoure) • prepackaged tar, no rpm • Directories: mendeleydesktop-0.9.6.1-linux-x86_64/bin mendeleydesktop-0.9.6.1-linux-x86_64/lib mendeleydesktop-0.9.6.1-linux-x86_64/lib/mendeleydesktop mendeleydesktop-0.9.6.1-linux-x86_64/lib/mendeleydesktop/libexec mendeleydesktop-0.9.6.1-linux-x86_64/lib/mendeleydesktop/plugins mendeleydesktop-0.9.6.1-linux-x86_64/lib/mendeleydesktop/plugins/sqldrivers mendeleydesktop-0.9.6.1-linux-x86_64/share mendeleydesktop-0.9.6.1-linux-x86_64/share/applications mendeleydesktop-0.9.6.1-linux-x86_64/share/doc mendeleydesktop-0.9.6.1-linux-x86_64/share/doc/mendeleydesktop mendeleydesktop-0.9.6.1-linux-x86_64/share/icons mendeleydesktop-0.9.6.1-linux-x86_64/share/icons/hicolor mendeleydesktop-0.9.6.1-linux-x86_64/share/icons/hicolor/128x128 mendeleydesktop-0.9.6.1-linux-x86_64/share/icons/hicolor/128x128/apps mendeleydesktop-0.9.6.1-linux-x86_64/share/icons/hicolor/16x16 mendeleydesktop-0.9.6.1-linux-x86_64/share/icons/hicolor/16x16/apps mendeleydesktop-0.9.6.1-linux-x86_64/share/icons/hicolor/22x22 mendeleydesktop-0.9.6.1-linux-x86_64/share/icons/hicolor/22x22/apps mendeleydesktop-0.9.6.1-linux-x86_64/share/icons/hicolor/32x32 mendeleydesktop-0.9.6.1-linux-x86_64/share/icons/hicolor/32x32/apps mendeleydesktop-0.9.6.1-linux-x86_64/share/icons/hicolor/48x48 mendeleydesktop-0.9.6.1-linux-x86_64/share/icons/hicolor/48x48/apps mendeleydesktop-0.9.6.1-linux-x86_64/share/icons/hicolor/64x64 mendeleydesktop-0.9.6.1-linux-x86_64/share/icons/hicolor/64x64/apps mendeleydesktop-0.9.6.1-linux-x86_64/share/mendeleydesktop mendeleydesktop-0.9.6.1-linux-x86_64/share/mendeleydesktop/citationStyles mendeleydesktop-0.9.6.1-linux-x86_64/share/mendeleydesktop/citationStyles/default mendeleydesktop-0.9.6.1-linux-x86_64/share/mendeleydesktop/generated-svm-models mendeleydesktop-0.9.6.1-linux-x86_64/share/mendeleydesktop/openOfficePlugin mendeleydesktop-0.9.6.1-linux-x86_64/share/mendeleydesktop/word-lists Goal: install to /opt/mendeleydesktop 39 © Novell, Inc. All rights reserved.
  • Building from a Binary Package (3) .spec file Nam e: mendel eydeskt op % nst al l i Li cense: Com er ci al ( M m endel ey Lt d. ) i f [ - n " $RPM BUI LD_ ROOT" ] ; t hen _ Ver si on: 0. 9. 6. 1 [ " $RPM BUI LD_ ROOT" ! = " / " ] && _ Rel ease: 1. mge r m - r f $RPM BUI LD_ ROOT && _ Sum ar y: m Mendel ey i s a f r ee r esear ch m r $RPM kdi _BUI LD_ ROOT managem ent t ool fi Bui l dAr ch: x86_ 64 m r -p kdi $RPM BUI LD_ ROOT/ opt _ % i ne _f nam % def e {nam % e}- {ver si on}- l i nux- %{bui l dar ch} t ar - C $RPM BUI LD_ ROOT/ opt - xsj pf % 0} _ {S: Sour ce0: % f nam t ar . bz2 {_ e}. mv $RPM_BUI LD_ROOT/ opt / % nam {_f e} Gr oup: Pr oduct i vi t y $RPM_BUI LD_ROOT/ opt / %{name} URL: ht t p: / / w w m w . endel ey. com dow oad- / nl mendel ey- deskt op/ % i l es f Bui l dRoot : % tm {_ ppat h}/ % {nam bui l d e}- % at t r ( - , r oot , r oot ) def / opt / %{name} %descr i pt i on Mendel ey i s a f r ee r esear ch management t ool f or % ean cl deskt op & w eb i f [ - n " $RPM BUI LD_ ROOT" ] ; t hen _ [ " $RPM BUI LD_ ROOT" ! = " / " ] && _ % ep pr r m - r f $RPM BUI LD_ ROOT _ % up - c - T set fi % ld bui %changel og * M on M ar 08 2010 - m novel l . com ge@ - i ni t i al ver si on 40 © Novell, Inc. All rights reserved.
  • 4. Building in the Buildservice • Open and complete distribution development platform • Create RPMs for multiple distributions and architectures • Create online package repositories • openSUSE Build Service is open source ® – Deploy your own internal build service • User Interfaces – Webinterface http://build.opensuse.org/ – Commandline interface: “osc” – Fat-clients – Integration into other tool-chains (qt-creator, kde4) 41 © Novell, Inc. All rights reserved.
  • Building in the Buildservice (2) • “osc” command line interface • Very similar to “cvs” and “svn” command line tools: familiar for developers • Overview – Checking – Commit – Add – importsrcpkg – Build – Rebuild 42 © Novell, Inc. All rights reserved.
  • Next Steps Learn more at: Brainshare Session ® BOF 102 en.opensuse.org/Build_Service build.opensuse.org Go, and build Join the openSUSE ® your packages! Buildservice online! 43 © Novell, Inc. All rights reserved.
  • Appendix
  • References http://rpm.org/max-rpm/ http://docs.fedoraproject.org/drafts/rpm-guide-en/ http://en.opensuse.org/SUSE_Build_Tutorial http://en.opensuse.org/Packaging/SUSE_Package_Conventions SUSE software management stack: ® http://en.opensuse.org/Libzypp http://www-128.ibm.com/developerworks/linux/library/l-rpm3.html http://www.ibm.com/developerworks/library/l-rpm1/ 45 © Novell, Inc. All rights reserved.
  • Unpublished Work of Novell, Inc. All Rights Reserved. This work is an unpublished work and contains confidential, proprietary, and trade secret information of Novell, Inc. Access to this work is restricted to Novell employees who have a need to know to perform tasks within the scope of their assignments. No part of this work may be practiced, performed, copied, distributed, revised, modified, translated, abridged, condensed, expanded, collected, or adapted without the prior written consent of Novell, Inc. Any use or exploitation of this work without authorization could subject the perpetrator to criminal and civil liability. General Disclaimer This document is not to be construed as a promise by any participating company to develop, deliver, or market a product. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. Novell, Inc. makes no representations or warranties with respect to the contents of this document, and specifically disclaims any express or implied warranties of merchantability or fitness for any particular purpose. The development, release, and timing of features or functionality described for Novell products remains at the sole discretion of Novell. Further, Novell, Inc. reserves the right to revise this document and to make changes to its content, at any time, without obligation to notify any person or entity of such revisions or changes. All Novell marks referenced in this presentation are trademarks or registered trademarks of Novell, Inc. in the United States and other countries. All third-party trademarks are the property of their respective owners.