{"id":124298,"date":"2022-04-27T08:00:00","date_gmt":"2022-04-27T08:00:00","guid":{"rendered":"https:\/\/fedoramagazine.org\/?p=36291"},"modified":"2022-04-27T08:00:00","modified_gmt":"2022-04-27T08:00:00","slug":"updating-edge-devices-with-ostree-and-pulp","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2022\/04\/27\/updating-edge-devices-with-ostree-and-pulp\/","title":{"rendered":"Updating Edge Devices with OSTree and Pulp"},"content":{"rendered":"<p>Connecting industrial machinery to the internet has given birth to infinite opportunities that range from performance improvements and predictive maintenance to data modelling that can lead to novel solutions and use cases. The possibilities are endless. Connecting machinery on such a scale can test the limits of cloud connectivity, depending on your location and network limitations.<\/p>\n<p>An edge device is any piece of hardware that sits at the boundary between two networks. When initial computation happens on servers at the edge, it speeds up user&#8217;s interactions with the cloud. Therefore, adding edge devices provides opportunities to optimize performance, shorten the journey, and lighten the load on your cloud connection.<\/p>\n<p>As amazing as it sounds, managing all of this functionality demands continuous attention from administrators. Having a reliable solution to distribute, deploy, and update systems for edge devices from the outset will help you spend time on things that matter.<\/p>\n<p>In this article, we look at how OSTree is well-positioned for upgrading and updating edge devices with versioned updates of Linux-based operating systems. Furthermore, we\u2019ll explore how Pulp facilitates managing and preparing updates of the OSTree content, as well as making it available to edge devices. Together, they provide a powerful free and open-source solution for administering edge devices.<\/p>\n<p> <span id=\"more-36291\"><\/span> <\/p>\n<h2>How does OSTree help manage Edge devices?<\/h2>\n<p>If you need to deploy hundreds of operating systems to edge devices, safe in the knowledge that you can easily manage future updates and maintenance, an OSTree\u2019s immutable and image-based operating system is ready for the task.<\/p>\n<p><a href=\"https:\/\/ostree.readthedocs.io\/en\/latest\/\" target=\"_blank\" rel=\"noreferrer noopener\">OSTree<\/a> functions like git, but for operating system binaries. It has git-like content-addressed repositories. The ability to commit and branch entire root filesystem trees resembles the way you submit changes in git. With OSTree, you build an operating system with pre-installed packages, known as an operating system image. After you build the operating system image, it is possible to track it, sign it, test it, and deploy it. These images function as immutable file system trees. When the time comes to change or update, you simply build a new image and deploy it. By atomically switching between different versions of images, you are completely replacing filesystem trees.<\/p>\n<p>OSTree also has a simple CLI that you can use for managing simple workflows, for example, for switching between different versions of images\/filesystem trees.<\/p>\n<h2>Where do Fedora-IoT Images feature?<\/h2>\n<p>As a standalone tool, the base OSTree CLI is not the most feature-rich utility for managing repository content. To make life easier, in the following demo, we will use <em><a href=\"https:\/\/coreos.github.io\/rpm-ostree\/\" target=\"_blank\" rel=\"noreferrer noopener\">rpm-ostree<\/a><\/em>.<em> rpm-ostree<\/em> is a hybrid image\/package system that combines the standard OSTree technology as a base image format and accepts RPM on both the client and server-side.<\/p>\n<p><em>rpm-ostree<\/em> integrates with Fedora IoT. In comparison to other ecosystems, instead of installing packages via DNF, you install packages with <em>rpm-ostree<\/em>. After rebooting all changes are applied to a new version of the image.<\/p>\n<p>You can also upgrade or install a new Fedora IoT image with the <em>rpm-ostree<\/em> utility.<\/p>\n<h2>Where and how does Pulp come into this?<\/h2>\n<p><a href=\"https:\/\/pulpproject.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">Pulp<\/a> is a platform that handles content management workflows. Using Pulp, you can sync packages from remote repositories such as an RPM server, PyPI, Docker Hub, Ansible Galaxy, and many more. You can host and modify synced packages in repositories inside the Pulp server. You can publish repositories that contain packages available for deployment to production environments.<\/p>\n<p>In our scenario, Pulp provides a platform for storing particular versions of OSTree content, promoting approved content through the content management lifecycle, for example from <em>dev<\/em> to <em>test<\/em>, and from <em>test<\/em> to <em>prod<\/em>. Pulp also provides a method for publishing content that is consumed by edge devices. Using Pulp, you can pull the latest packages, test, and publish only when safe to do so. Pulp ensures the safety, security, and repeatability of your content supply chain.<\/p>\n<p>The following diagram provides a simplified overview of Pulp. On the left are shown different content types that are mirrored into Pulp from remote sources. These repositories are then served, for instance, to different CI\/CD or production environments.<\/p>\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2022\/04\/updating-edge-devices-with-ostree-and-pulp.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2022\/04\/updating-edge-devices-with-ostree-and-pulp.png\" alt=\"\" class=\"wp-image-36292\" width=\"832\" height=\"417\" \/><\/a><figcaption>A simplified overview of Pulp. The content is mirrored from remote repositories and made available to different types of environments.<\/figcaption><\/figure>\n<p>Pulp creates a new repository version automatically when updating or removing packages in a repository. You can distribute each repository version independently.<\/p>\n<p>Pulp has a plugin-based architecture, which means that you must add a plugin for each content type you want to use. For managing OSTree content, you need <a href=\"https:\/\/github.com\/pulp\/pulp_ostree\" target=\"_blank\" rel=\"noreferrer noopener\">the OSTree plugin<\/a>. You can then mirror content from a remote repository, import content from a local tarball, and modify content within a Pulp repository while preserving the integrity of the original content. You can move commits and refs from one repository to another or delete them. Pulp ensures that you are safe to experiment while your production environment remains pinned to a particular version.<\/p>\n<h2>Putting it all together<\/h2>\n<p>In this section, let\u2019s look at how to build an image with an OSTree commit.<\/p>\n<h3>Building a Customized Fedora-IoT Image<\/h3>\n<p>We start by booting a new virtual machine (VM) that will have an installed Fedora-IoT OS. For the purposes of this example, it is best to have the same version of the OS installed as the running edge devices have.<\/p>\n<p>All commands in this section are executed on the main admin VM (Fedora IoT 35 OS). On this admin VM, we will build the images that we will then distribute to the edge devices.<\/p>\n<h4>Before you begin:<\/h4>\n<ul>\n<li>First, ensure that the VM is accessible via SSH. To test, enter the following command from within the target OS:<\/li>\n<\/ul>\n<pre class=\"wp-block-preformatted\">$ systemctl is-active sshd<\/pre>\n<ul>\n<li>Next, ensure that the following tools for composing operating system images are installed:&nbsp;<\/li>\n<\/ul>\n<pre class=\"wp-block-preformatted\">$ sudo rpm-ostree install osbuild-composer composer-cli\n$ sudo systemctl enable --now osbuild-composer.socket<\/pre>\n<ul>\n<li>Now, apply the installed packages by rebooting the system.<\/li>\n<\/ul>\n<hr class=\"wp-block-separator is-style-wide\" \/>\n<p>In this example a nano editor package is installed on all edge devices.\u00a0We need to build an image containing a commit with the package.<\/p>\n<p>Create a blueprint file that describes what changes you want to make to the image as shown here:<\/p>\n<pre class=\"wp-block-preformatted\">$ cat install-nano.toml name = \"nano-commit\"\ndescription = \"Installing nano\"\nversion = \"0.0.1\" [[packages]]\nname = \"nano\"\nversion = \"*\"<\/pre>\n<p>Push this blueprint to the os build composer utility, which is a tool for composing operating system images. <em>composer-cli<\/em> communicates with <em>osbuild composer<\/em> through the CLI:<\/p>\n<pre class=\"wp-block-preformatted\">$ composer-cli blueprints push install-nano.toml<\/pre>\n<p>Build a new image:<\/p>\n<pre class=\"wp-block-preformatted\">$ composer-cli compose start-ostree nano-commit fedora-iot-commit --ref fedora\/stable\/x86_64\/iot<\/pre>\n<p>The composer will use resources available in your current OS (such as a default operating system version).<\/p>\n<p>Regularly check the status of the build:<\/p>\n<pre class=\"wp-block-preformatted\">$ composer-cli compose status<\/pre>\n<p>When the build finishes, download the image:<\/p>\n<pre class=\"wp-block-preformatted\">$ composer-cli compose image ${IMAGE_UUID}<\/pre>\n<p>The downloaded image is basically an OSTree repository packed into a tarball. When you extract the archived content, you will notice that one ref is referencing the checksum of a commit. You can find it inside the <em>refs\/heads\/<\/em> directory.<\/p>\n<h3>Publishing the Customized Image with Pulp<\/h3>\n<p>All commands shown in this section are executed on the main admin VM (Fedora IoT 35 OS).<\/p>\n<h4>Before you begin:<\/h4>\n<ul>\n<li>Ensure that you have installed Pulp and the Pulp CLI for managing OSTree repositories:<\/li>\n<\/ul>\n<pre class=\"wp-block-preformatted\">$ python3 -m venv venv &amp;&amp; source venv\/bin\/activate\n$ pip install pulp-cli-ostree<\/pre>\n<ul>\n<li>Then <a href=\"https:\/\/docs.pulpproject.org\/pulp_cli\/configuration\/\" target=\"_blank\" rel=\"noreferrer noopener\">configure<\/a> the reference to the Pulp server:<\/li>\n<\/ul>\n<pre class=\"wp-block-preformatted\">$ pulp config create &amp;&amp; pulp status<\/pre>\n<p>Now configure a proxy server or SSH port forwarding to enable network communication between the VM and Pulp. Ensure that you can ping the Pulp server from the VM.<\/p>\n<hr class=\"wp-block-separator is-style-wide\" \/>\n<p>First, create a new OSTree repository:<\/p>\n<pre class=\"wp-block-preformatted\">$ pulp ostree repository create --name fedora-iot<\/pre>\n<p>The following command will import the tarball created in the previous section into Pulp:<\/p>\n<pre class=\"wp-block-preformatted\">$ pulp ostree repository import-commits --name fedora-iot --file ${IMAGE_TARBALL_C1} --repository_name repo<\/pre>\n<p>Publish the parsed commit as a remote OSTree repository hosted by Pulp:<\/p>\n<pre class=\"wp-block-preformatted\">$ pulp ostree distribution create --name fedora-iot --base-path fedora-iot --repository fedora-iot<\/pre>\n<p>Try to fetch the commit checksum from the ref:<\/p>\n<pre class=\"wp-block-preformatted\">$ curl http:\/\/${PULP_BASE_ADDR}\/pulp\/content\/pulp-fedora-iot\/refs\/heads\/fedora\/stable\/x86_64\/iot<\/pre>\n<h3><strong>Distributing the Customized Image to an Edge Device<\/strong><\/h3>\n<p>The Edge device can be another VM or a real device running Fedora IoT.<\/p>\n<p>All commands shown in this section are executed on an Edge device (Fedora IoT 35 OS).<\/p>\n<h4>Before you begin:<\/h4>\n<ul>\n<li>Configure a proxy server or SSH port forwarding to enable network communication between an Edge device and Pulp. Ensure that you can ping the Pulp server from the Edge device.&nbsp;<\/li>\n<li>Ensure that the Edge device is accessible with SSH:<\/li>\n<\/ul>\n<pre class=\"wp-block-preformatted\">$ systemctl is-active sshd<\/pre>\n<hr class=\"wp-block-separator is-style-wide\" \/>\n<p>The nano package should NOT come pre-installed with the official bare Fedora IoT 35 image. Verify that by attempting to run <em>nano<\/em> inside your terminal.<\/p>\n<p>In Fedora IoT, updates are retrieved from the URL defined in <strong>\/etc\/ostree\/remotes.d\/fedora-iot.conf<\/strong>. This file can be modified manually or by adding a new remote repository. Learn more at <a href=\"https:\/\/docs.fedoraproject.org\/en-US\/iot\/rebasing\/#_adding_and_removing_remote_repositories\" target=\"_blank\" rel=\"noreferrer noopener\">Adding and Removing Remote Repositories<\/a>.<\/p>\n<p>You can automate the upgrade procedure with an upgrade policy that will be configured at the beginning of deployment. This is done by writing a kickstart file that will boot up an edge device into a headless state. However, for demonstrative purposes, let\u2019s act like a villain and update the aforementioned configuration file manually to have the following content:<\/p>\n<pre class=\"wp-block-preformatted\">[remote \"fedora-iot\"]\nurl=http:\/\/${PULP_BASE_ADDR}\/pulp\/content\/pulp-fedora-iot\/refs\/heads\/fedora\/stable\/x86_64\/iot\ngpg-verify=false\nref=fedora\/stable\/x86_64\/iot<\/pre>\n<p>Do not forget to replace the variable <em>${PULP_BASE_ADDR}<\/em> with a valid base path to the pulp server.<\/p>\n<p>The following command shows you that some packages are going to be installed:<\/p>\n<pre class=\"wp-block-preformatted\">$ rpm-ostree upgrade<\/pre>\n<p>Reboot the edge device:<\/p>\n<pre class=\"wp-block-preformatted\">$ systemctl reboot<\/pre>\n<p><em>\u2026rebooting\u2026<\/em><\/p>\n<p>Log in to the edge VM via ssh, and check the presence of the nano package that comes from Pulp:<\/p>\n<pre class=\"wp-block-preformatted\">$ nano<\/pre>\n<p><strong>Done! You have successfully distributed a customized Fedora IoT image via Pulp!<\/strong><\/p>\n<p>In case of any questions, do not hesitate to reach out to us at <a href=\"https:\/\/pulpproject.org\/help\/#pulp-community-discourse\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/pulpproject.org\/help<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Connecting industrial machinery to the internet has given birth to infinite opportunities that range from performance improvements and predictive maintenance to data modelling that can lead to novel solutions and use cases. The possibilities are endless. Connecting machinery on such a scale can test the limits of cloud connectivity, depending on your location and network [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":124299,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48],"tags":[45,61,46,47],"class_list":["post-124298","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-fedora-os","tag-fedora","tag-fedora-project-community","tag-magazine","tag-news"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/124298","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=124298"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/124298\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media\/124299"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=124298"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=124298"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=124298"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}