Working with RHEL Universal Base Images

Have you ever wanted to bring your pull request changes in a cloud image easily?

Curious about how easy it can be? With Packit, it can be just a matter of commenting on your pull request with the following command:

/packit vm-image-build

With the above command, Packit automates all the manual steps needed to create an RPM package with your pull request changes and asks the Red Hat Enterprise Linux image builder (RHEL image builder) to install it inside a brand new cloud image.

Let's have a look at the prerequisites for this.

Join the Red Hat Developer program

If you don't already have a business account, you can create a Red Hat Developer account at no cost.

You need a subscription in order to use the RHEL image builder service and launch the builded images in the Amazon Web Services (AWS) management console.

Prepare to upload the Amazon Machine Image

Before uploading an Amazon Machine Image (AMI), you must configure the AWS system for receiving them.

Prerequisites

Procedure

Follow these steps to satisfy the above prerequisites.

The manual steps

Are you wondering what are the manual steps for bringing your pull request changes in a cloud image and why you should automate them?

There could be many ways to achieve this goal, but let's see together the closest to our automated solution. Below you can find a summary of all the needed manual steps; I am quite sure after reading them, you will want to automate them with Packit!

Build an RPM package with your pull request changes through COPR.

  1. Install copr-cli.
  2. Create your account and service token.
  3. Add your token to ~/.config/copr.
  4. Create a new COPR project.
  5. Start a build with your local pull request changes using copr-cli.
  6. Wait for the build to finish.

Create a new cloud image through the RHEL image builder console.

  1. Log in with your Red Hat Developer account.
  2. Click on the Create Image button. Choose the AWS image type and follow the wizard.
  3. Wait for the build to finish.
  4. Open the Launch link for the built image.

Launch and access the AWS image through the AWS management console.

  1. The previous link will open an AWS console tab with the Launch an Instance wizard preset to use the builded image. You need to log in into the AWS management console using an AWS account ID allowed to access the AMI image you just created.
  2. Select a key pair (or create one if you don't have it already) to be able to ssh the image later.
  3. Click Launch Instance.
  4. Connect to instance using an ssh client.
  5. Add the previously created COPR repo to the list of available dnf repositories.
  6. Install the package you have created in step 4.
  7. Now you are ready to test your code in a real cloud image.

For every new pull request you want to test directly in a cloud image you have to repeat steps 4-16, or automate them through Packit.

Automate the steps

Install Packit

Installing Packit is pretty straightforward:

  1. Create a valid Fedora Account System (FAS) account (if you don't already have one). Why do you need this? After these few steps you will start building (and potentially shipping) Fedora packages through the COPR service, and we need you to agree with the Fedora license.
  2. Install our GitHub application on GitHub Marketplace, or configure a webhook on GitLab (depending on where your project lives).
  3. Make Packit approve your FAS username; on GitHub, the approval process is automated, and for GitLab, you have to contact us.

Once installed, you are ready to automate the process as described below.

Set up Packit

Create a .packit.yaml configuration file in your pull request—but just the first time! After your pull request has been merged, Packit will take the .packit.yaml file from the target main branch.

The configuration file will look like the following:

---

jobs:
- job: copr_build
  trigger: pull_request
  targets:
  - fedora-all

- job: vm_image_build
  trigger: pull_request
  image_request:
    architecture: x86_64
    image_type: aws
    upload_request:
      type: aws
      options:
        share_with_accounts:
        - < shared-aws-account-id >
  image_distribution: fedora-39
  copr_chroot: fedora-39-x86_64
  image_customizations:
    packages: [hello-world]

copr_build job

The first job tells the Packit service to build an RPM package for the Fedora release you want—in this example all the active Fedora releases—and to add your pull request changes to the package.

To further customize the COPR builds made by Packit, you might want to refer to this guide.

vm_image_build job

The second job tells Packit how to configure the RHEL image builder service.

The first two lines of this job are still meant for Packit; they allow Packit to react to your pull request comment /packit vm-image-build. Packit does not build a VM image automatically, as it does when it builds a COPR package, to save you from unwanted costs.

- job: vm_image_build
  trigger: pull_request

The other lines are meant to customize the RHEL image builder behavior.

You are asking to build an AWS image, with a fedora-39 distribution, for the x86_64 architecture and you want to share it with the listed AWS Account IDs.

  image_request:
    architecture: x86_64
    image_type: aws
    upload_request:
      type: aws
      options:
        share_with_accounts:
        - < shared-aws-account-id >
  image_distribution: fedora-39

You don't want to manually install the COPR package into the image; for this reason, you'll ask RHEL image builder to install it (hello-world).

You tell RHEL image builder to take it from the COPR chroot fedora-39-x86_64, and you don't need to create or specify a COPR project because Packit has automatically created it for you.

  copr_chroot: fedora-39-x86_64
  image_customizations:
    packages: [hello-world]

Create, comment, and test a pull request

Create a pull request; mine will show you the word world in green.

All you need to do is comment your pull request with:

/packit vm-image-build

And the image will be built and customized for you.

Look for the check named vm-image-build-fedora-39-x86_64 and wait for it to finish (Figure 1).

Wait for check vm-image-build-fedora-39-x86_64 to finish
Figure 1: The image is being built

Open its details (Figure 2) and you will find the link to the AWS image.

The check details have a link to the AWS image
Figure 2: The AWS image link now appears in the sidebar.

Open the AWS link (you will need to be logged in) and see the details of your image ready to be launched (Figure 3).

The AWS image details
Figure 3: The AMI details window.

Launch your image instance and connect to it (Figure 4).

Connect to instance details
Figure 4: Connecting to the image instance.

Test it, as shown in Figure 5.

Test it!
Figure 5: The word "world" now appears in green.

Conclusions

Packit can automate building RPM packages with changes taken from pull requests, creating cloud images, and installing packages into them so that they are ready to be manually tested.

But this is not all—Packit can also help you automating tests or releases. Want to know more? Visit packit.dev.