Skip to content

Packaging applications with RPM

To build and deploy applications for AutoSD, package the application with RPM Package Manager (RPM) and embed the packaged application in the operating system (OS) image. The Automotive SIG provides sample OS image manifests that you can customize for specific use cases and sample applications that you can package and deploy in your OS images.

There are two types of packages:

  • Binary packages (RPM packages): A binary package contains compiled software.
  • Source RPM packages (SRPM packages): A source package contains the source code of the application, the spec file that specifies how to compile the source code, and eventual patches to produce the binary packages.

In this example workflow, you will learn how to prepare the sample application source code that you want to package with RPM, create a spec file, build a binary RPM, and create a local RPM repository. Then configure the OS image build process to include your RPM at build time. To learn more about RPM packages, see the RHEL RPM guide.

Creating the RPM packaging workspace

To create an RPM package, you must first create a separate directory for your RPM packaging workspace. An RPM package consists of an archive of source code and a spec file. The spec file contains project metadata and different sections that you use to define how to compile project source code.

Prerequisites

  • A host machine that runs on CentOS Stream, Fedora, or RHEL

Procedure

  1. Install the tools required to build RPM packages, as well as dependencies required by the sample application:

    sudo dnf install rpmdevtools createrepo rpm-build rpm-devel cmake make gcc-c++ \
    boost-devel vsomeip3-devel
    
  2. From your home directory, run the rpmdev-setuptree utility to create a file structure for the RPM packaging workspace:

    cd && rpmdev-setuptree
    
  3. Verify that rpmdev-setuptree created the required directories:

    $ tree ~/rpmbuild/
    /home/<user>/rpmbuild/
    |-- BUILD
    |-- RPMS
    |-- SOURCES
    |-- SPECS
    |-- SRPMS
    
    5 directories, 0 files
    

The required directories each serve a unique purpose:

  • BUILD: The location of various %buildroot directories. These are useful for investigating a failed build if the log output is inconclusive.
  • RPMS: The location of your binary RPM packages. This directory contains subdirectories for different architectures.
  • SOURCES: The location of your source code. Package your source code in a tar archive and copy it to the SOURCES directory. At build time, the rpmbuild build tool extracts your software from this directory.
  • SPECS: The location of your spec files.
  • SRPMS: The location of your SRPM packages.

Packaging your application source code with RPM

Use this workflow to package your own application source code into an RPM package. After you package your software, add it to a local RPM repository. RPM Package Manager queries the RPM packages in this repository, resolves their dependencies, and installs them in your operating system (OS) image.

  1. Create a tar archive of your application source code:

    tar -cvf my-app.tar.gz my-app
    

    In this example, your application source code is in a directory named my-app.

  2. Move the .tar archive of your software to the rpmbuild/SOURCES directory:

    mv my-app.tar.gz rpmbuild/SOURCES/
    
  3. Create a spec file for a new RPM package called my-app:

    rpmdev-newspec my-app
    

    This command creates a spec file for your my-app application in ~/rpmbuild/SPECS/my-app.spec.

  4. Modify the ~/rpmbuild/SPECS/my-app.spec file with a text editor. For more information about spec files and how to customize them, see the RPM packaging Guide on GitHub.

  5. Build the binary RPM package:

    rpmbuild -ba ~/rpmbuild/SPECS/my-app.spec
    
  6. Create a directory for your RPM package repository, move your .rpm file to this directory, and initialize the directory as an RPM package repository:

    mkdir /var/tmp/my_repo
    cp -rp ~/rpmbuild/RPMS/* /var/tmp/my_repo/
    createrepo /var/tmp/my_repo
    

Your RPM package repository is now ready, and it contains your software packaged as a .rpm file. When you build the AutoSD image, include the RPM package repository in the build manifest to enable the OS image to incorporate your software. For more information about building the AutoSD image, see Building an AutoSD image.

Next steps


© Red Hat