# RPM packaging: adding a sub package to an already existing package (RHEL & centos) In this document we will follow an example where existing package is ignition (https://gitlab.com/redhat/centos-stream/rpms/ignition) and we want to add fedora-iot/ignition-edge (https://github.com/fedora-iot/ignition-edge) as a sub-package . - Fork https://gitlab.com/redhat/centos-stream/rpms/ignition this repo with your gitlab account. - Clone the forked repository of the package to which you intend to add a sub-package. ``` git clone git@gitlab.com:<your-git-username>/ignition.git cd ignition ``` - At minimal a package will have .spec file, which basically holds steps for packaging. Now we need to make changes in the .spec file. - Refer https://rpm-packaging-guide.github.io/#working-with-spec-files to get better understanding of spec files. - In order to add a sub-package we need to mention source of the sub-package as follows ``` %global ignedgecommit a3a8f0abb2a1c7fc1c9e5d0e7a3e8830b2e2d766 %global ignedgeshortcommit %(c=%{ignedgecommit}; echo ${c:0:7}) Source1: https://github.com/fedora-iot/ignition-edge/archive/%{ignedgecommit}/ignition-edge-%{ignedgeshortcommit}.tar.gz ``` - In above code `ignedgecommit` and `ignedgeshortcommit` are nothing but two macros which hold commit id of the latest commit of ignition-edge sub-package. - Update the release version accordingly. ```Release: x%{?dist} ``` - Add necessary info about the sub-package: ``` ############## ignition-edge sub-package ############## %if 0%{?rhel} && !0%{?eln} %package edge Summary: Enablement glue for Ignition on ostree systems License: ASL 2.0 %description edge This package contains dracut modules, services and binaries needed to enable Ignition on ostree systems. %endif ``` - Add following under `%prep` section ``` tar xvf %{SOURCE1} ``` - Add following under `%install` section ``` %if 0%{?rhel} && !0%{?eln} %make_install -C ignition-edge-%{ignedgecommit} %endif ``` - Add all the required modules and services under `%files` section - For example in this case ``` %if 0%{?rhel} && !0%{?eln} %files edge %license %{golicenses} %doc %{godocs} %{dracutlibdir}/modules.d/35ignition-edge/* %{dracutlibdir}/modules.d/10coreos-sysctl/* %{dracutlibdir}/modules.d/99emergency-shell-setup/* %{dracutlibdir}/modules.d/99journal-conf/* %{_unitdir}/coreos-check-ssh-keys.service %{_unitdir}/coreos-ignition-write-issues.service %{_unitdir}/ignition-firstboot-complete.service %{_libexecdir}/coreos-ignition-write-issues %{_libexecdir}/coreos-check-ssh-keys %endif ``` - Add relative information about your change under `%changelog` section. - Once done with changes in .spec file, generate `sources` file by uploading the the sub-package (ignition-edge) to the build system. - We need `centpkg` utility for this. For Fedora, install with `dnf install centpkg` command . OR follow instructions under https://copr.fedorainfracloud.org/coprs/james/centpkg/. - Before that make sure you have krb5 tickets generated for your system. Following command fkinit generates the tickets for specified username. ``` sudo dnf install fedora-packager fedora-review sudo usermod -a -G mock <username> fkinit -u <username> ``` - Also generate/update ca-certificate to avoid SSL certificate error ``` sudo wget https://password.corp.redhat.com/RH-IT-Root-CA.crt -O /etc/pki/ca-trust/source/anchors/Red_Hat_IT_Root_CA.crt --no-check-certificate sudo wget https://password.corp.redhat.com/pki-ca-chain.crt -O /etc/pki/ca-trust/source/anchors/PKI_CA_Chain.crt --no-check-certificate ln -sf /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem /etc/pki/tls/certs/ca-bundle.crt sudo update-ca-trust ``` - Download the ignition-edge-a3a8f0a.tar.gz subpackage locally. ``` curl -O https://github.com/fedora-iot/ignition-edge/archive/a3a8f0abb2a1c7fc1c9e5d0e7a3e8830b2e2d766/ignition-edge-a3a8f0a.tar.gz ``` - Upload the source of sub-package ``` centpkg upload ignition-edge-a3a8f0a.tar.gz ``` - Verify if that adds SHA512 hash of the source in `sources` file ``` cat sources SHA512 (ignition-2.14.0.tar.gz) = e66d42bcfc516055f61abd1808e7ed1bdb4bf4e99b69c16ab9031be173a709c5864e74f23033cb33288e758b2f98a1dd878ef1aa802220afa504997fc3440af3 SHA512 (ignition-edge-a3a8f0a.tar.gz) = cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e ``` - So in the above file, ignition-2.14.0.tar.gz is the main package and we have added ignition-edge-a3a8f0a.tar.gz this as a sub-package successfully. - Create a merge request from your forked repo and once this change is approved and merged, latest package will be made available for centos and rhel. ## Refer Please refer https://rpm-packaging-guide.github.io/ this documentation for understanding more about rpm packaging.