Application packaging

The redpesk OS is based on RPM Package Manager. In order to build an RPM package, you need to write a spec file. You can find further information about how to write a spec file here:

Spec file development

A spec file is composed of several sections:

  • Name: RPM package name
  • Summary: a short description of the package
  • Version: the package version
  • Release: this number has to be incremented every time the package is recreated
  • License: the package license, it is necessary to fill in the gaps
  • URL: project URL
  • Source0 … SourceN: tarball defining the project sources location
  • BuildRequires: required dependencies for building
  • Requires: required dependencies for the package at run time

The Documentation section

  • %description: longer description of the package
  • %changelog: describes changes to apply when release is incremented

Metadata section

  • %files: contains files included in the package

Build section

  • %prep: describes how to extract tarball defined in SOURCE0…SOURCEN
  • %build: this is where packages are compiled. In many cases, there is a macro %configure before a make in this section

Install section

The %install section is where we instruct rpmbuild how to install our previously built software into the BUILDROOT.

  • %install: creates the final tarball as it will be in the RPM. Created files have to be in the %{buildroot} directory

Example

Here below is the spec file of the helloworld-binding.

This package has dependencies on other packages to run (“Requires” sections) and uses customized macros made available in the redpesk build infrastructure: %afm_package, %afm_package_test, %afm_configure_cmake, %afm_build_cmake, etc.

###########################################################################
# Copyright (C) 2015-2026 IoT.bzh Company
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###########################################################################
Name:    helloworld-binding
Version: 8.99.6
Release: 3%{?dist}
License: APL2.0
Summary: helloworld service set to be used in redpesk
URL:     https://github.com/redpesk-samples/helloworld-binding
Source0: %{name}-%{version}.tar.gz

BuildRequires: afm-rpm-macros
BuildRequires: cmake
BuildRequires: gcc gcc-c++
BuildRequires: afb-cmake-modules
BuildRequires: pkgconfig(json-c)
BuildRequires: pkgconfig(libsystemd) >= 222
BuildRequires: pkgconfig(libafb)
BuildRequires: pkgconfig(libmicrohttpd) >= 0.9.55
BuildRequires: pkgconfig(afb-libhelpers)

%description
The helloworld service gathers two bindings.
- helloworld-skeleton: Increment a counter
- helloworld-subscribe-event: Subscribe and get notified whether an event is emitted

# main package: default install in /var/local/lib/afm/applications/%%{name}
%afm_package
# test package: default install in /var/local/lib/afm/applications/%%{name}-test
%afm_package_test
%afm_package_redtest

%prep
%autosetup -p 1

%build
%afm_configure_cmake
%afm_build_cmake

%install
%afm_makeinstall

%check

%clean

%changelog

* Wed Jun 24 2020 IoT.bzh <armand.beneteau.iot.bzh> 8.99.6
- Add the use of cmake template for run-redtest

* Mon May 18 2020 IoT.bzh(iotpkg) <redpesk.list@iot.bzh> gcde438ae
- Upgrade version from source commit sha: cde438aed1e990b69d4ed2fb3aa3b4ba22e78a6a
- Commit message:
- 	Correction inside the run-redtest script (#3)
-

* Mon May 18 2020 IoT.bzh <clement.benier@iot.bzh> 8.99.6
- bump version of afm-rpm-macros

* Wed Apr 29 2020 IoT.bzh <redpesk.list.iot.bzh> 8.99.6
- Modifications in order to add a redtest subpackage

* Wed Feb 19 2020 IoT.bzh <redpesk.list.iot.bzh> 8.99.5
- Modifications in order to add a test subpackage

* Fri Feb 14 2020 IoT.bzh <redpesk.list.iot.bzh> 8.99.5
- Creation of the spec file from redpesk generator

Patch

This chapter is also the opportunity to present you a nice feature coming along with redpesk.

Let’s say you have noticed a missing semicolon in the helloworld source files and you want to do a fix without doing a commit in the source repository. Then, you can patch your source directly in the redpesk project.

First of all, create the patch which fixes the error you noticed. For instance, here is the one that fixes a missing semicolon:

devel@redpesk: ~/helloworld-binding git format-patch HEAD~1
0001-Quick-fix-for-build-in-redpesk.patch

Patch content:

From 4ac7f6bc8fc75cdf019cb1baee609d03c1fbd72c Mon Sep 17 00:00:00 2001
From: Marc-Antoine Riou <marc-antoine.riou@iot.bzh>
Date: Mon, 11 Jan 2021 13:58:40 +0000
Subject: [PATCH] Quick fix for build in redpesk

Signed-off-by: Marc-Antoine Riou <marc-antoine.riou@iot.bzh>
---
 helloworld-skeleton/helloworld-service-binding.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/helloworld-skeleton/helloworld-service-binding.c b/helloworld-skeleton/helloworld-service-binding.c
index a0b3c05..d0c01a1 100644
--- a/helloworld-skeleton/helloworld-service-binding.c
+++ b/helloworld-skeleton/helloworld-service-binding.c
@@ -26,7 +26,7 @@ static void pingSample(afb_req_t request)
 {
        static int pingcount = 0;

-       afb_req_success_f(request, json_object_new_int(pingcount), "Ping count = %d", pingcount)
+       afb_req_success_f(request, json_object_new_int(pingcount), "Ping count = %d", pingcount);

        AFB_API_NOTICE(afbBindingV3root, "Verbosity macro at level notice invoked at ping invocation count = %d", pingcount);

--
2.29.2

⚠️⚠️ Do not include this patch in your project. It is just an example to present you the patch feature ⚠️⚠️

For the patch to be effective during the build, follow the instructions below:

  • Add the patch in your project’s application
  • Edit the application’s spec file for the patch to be considered

There are two different ways of applying a patch in your project’s application:

  • Using a Web user interface, such as the community one.
  • Using rp-cli tool.

Patch with the Web UI

  1. As shown below, go to the File Manager tab of your application and upload your patch file among the Package source files.
  2. Edit the spec file and add the patch file name in the “Patch” section, then review and save your modification.

Patch your application

Patch with rp-cli

# Send the patch
rp-cli applications upload helloworld-binding --file-path ./0001-Quick-fix-for-build-in-redpesk.patch
# Modification of spec file to add the "Patch: 0001-Quick-fix-for-build-in-redpesk.patch" (cf. video above)
vim ./helloworld-binding.spec
# Send the new spec file
rp-cli applications upload helloworld-binding --file-path ./helloworld-binding.spec