Skip to content

Packaging sample applications with RPM

Use this workflow to package a sample application that is available upstream. The sample application has several services:

  • engine-service: A service with a single event that signals when the car is in reverse.
  • radio-service: A service that emulates a radio, regularly publishing information about the current song, radio station, and volume. It accepts requests to turn the radio on and off, change the channel, and adjust the volume. If the engine service is available, the radio-service listens for events and temporarily lowers the radio volume while the car is in reverse.
  • radio-client: A command line program that displays the current state of the radio service and enables you to control it. The keyboard controls are displayed on the screen.

Procedure

  1. Clone the sample application repository:

    git clone https://gitlab.com/CentOS/automotive/src/sample-apps.git
    cd sample-apps
    
  2. Create a tar archive using upstream samples:

    git archive HEAD . --prefix=auto-apps-0.1/ --output=auto-apps-0.1.tar.gz
    
  3. Move the .tar archive of your software to the ~/rpmbuild/SOURCES directory:

    mv auto-apps-0.1.tar.gz ~/rpmbuild/SOURCES/
    
  4. From the ~/rpmbuild/SPECS/ directory, create a spec file for a new RPM package called auto-apps:

    rpmdev-newspec auto-apps
    

    This command creates a spec file named auto-apps.spec.

  5. Modify the ~/rpmbuild/SPECS/auto-apps.spec file with a text editor:

    auto-apps.spec file
    Name:           auto-apps
    Version:        0.1
    Release:        1%{?dist}
    Summary:        A test RPM of auto-apps
    
    License:        MIT
    Source0:        auto-apps-%{version}.tar.gz
    
    BuildRequires:  cmake make gcc-c++ boost-devel vsomeip3-devel
    
    %description
    Sample auto applications
    
    %prep
    %autosetup
    
    %build
    %cmake
    %cmake_build
    
    %install
    %cmake_install
    
    %files
    %{_bindir}/engine-service
    %{_bindir}/radio-client
    %{_bindir}/radio-service
    
    %changelog
    * Tue Feb 20 2024 your_name <your_email>
    - Initial packaging
    

    Be sure to update the %build, %install, and %files sections of the spec file. This spec file is a minimal working spec file for the sample auto-apps applications. You can further customize the spec file to control your RPM build process. For more information about spec files and how to customize them, see the RPM packaging Guide on GitHub.

  6. Build the binary RPM:

    rpmbuild -ba ~/rpmbuild/SPECS/auto-apps.spec
    
  7. 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.


© Red Hat