Chapter 1 - Working with Golden Images
Build the demo base image for RHEL
The first steps we will build our base SOE (golden) image that we are going to use within the workshop. We will start with RHEL 9 and during the workshop update to RHEL 10.
We will name our SOE (Standard Operating Environment/Golden) image soe-rhel:9 and also tag it as our latest rhel base image as soe-rhel:latest.
-
Use podman to build our soe base RHEL "golden image". Change to the directory where you have cloned this repo and use
podman buildto build the image from theContainerfile. The following command will work if you cloned it into your home directory. -
If we want to test our image we can run it in a container. You can log in with user
bootc-userand passwordredhatand runcurl localhostto test if the httpd service is running and you can see the base image welcome page. You can stop and exit the container withsudo halt. We are going to run our container in the next step to check that the httpd service is running and that we can see our homepage before deploying it to a VM. -
Push the base rhel image to our registry.
Tip
We could base the initial image on an older release of RHEL, such as rhel:9.6, or a specific timestamp version of RHEL such as rhel:9.6-1747275992, or fix it at a certain release such as rhel:9.7, instead of pulling the latest release by specifying the release number in the Containerfile FROM statement.
Deploying the Homepage Virtual Machine
We need to create an image for our httpd service based on the RHEL 9 base image we created in the previous step.
We will name our httpd service image httpd:rhel9 and also tag it as our latest rhel base image as httpd:latest.
-
Use podman to build httpd service image. Change to the httpd-service folder.
Review httpd-service/Containerfile
FROM quay.io/$QUAY_USER/soe-rhel:latest RUN dnf -y install httpd ADD etc/ /etc RUN <<EOF set -euxo pipefail mv /var/www /usr/share/www sed -i 's-/var/www-/usr/share/www-' /etc/httpd/conf/httpd.conf EOF ADD html/ /usr/share/www/html RUN cp /etc/redhat-release /usr/share/www/html/redhat-release RUN cp /etc/os-release /usr/share/www/html/os-release RUN uname -sr > /usr/share/www/html/uname.txt RUN systemctl enable httpd EXPOSE 80 -
Change the $QUAY_USER in the
Containerfileto your Quay userid or your registry. -
Use
podman buildto build the image from theContainerfile. -
Push the httpd service image to our registry.
-
If we want to test our image we can run it in a container.
-
You can log in with user
bootc-userand passwordredhatand runcurl localhostto test if the httpd service is running and you can see the base image welcome page. You can test the homepage in a browser on the local machine by using the URLhttp://localhost:8080. You can stop and exit the container withsudo halt.
Now we are ready to create the virtual machine disk image that we are going to import into our new VM.
Since we need to run the Image Builder convert tool as superuser we need to pull the image from the registry using sudo to add it to sudo's image repository.
-
Since we need to run podman as root to build the virtual machine qcow2 image file, we need to pull the image as root.
Tip
You may also get an error
Error: unable to copy from source. You need to go to your repository, in our example, Quay, and make the repositoriespublic. -
We need to use podman to run the Image Mode virtual machine disk builder to pull the image from the registry and create the virtual machine disk file. You can edit the
config.tomlfile to change it to add or replace the user, password, ssh key and more. Refer to Supported image customizations for a configuration file.Tip
If you get an error
Error: unable to copy from sourceyou may have to do asudo podman login registry.redhat.io -u $REDHAT_USER -p $REDHAT_PASSWORD.sudo podman run \ --rm \ -it \ --privileged \ --pull=newer \ --security-opt label=type:unconfined_t \ -v $(pwd)/config.toml:/config.toml:ro \ -v $(pwd):/output \ -v /var/lib/containers/storage:/var/lib/containers/storage registry.redhat.io/rhel9/bootc-image-builder:latest \ --type qcow2 \ quay.io/$QUAY_USER/httpd:latest -
We will copy the new disk image to the libvirt images pool.
Tip
You can move the disk image if you don't plan to use it for another VM using the mv command.
-
Create the VM from the copied virtual machine image qcow2 file. We will give it 4GB of RAM and set the boot option to UEFI.
-
Start the VM.
-
Login via ssh. You can use the following command that will get the IP address from virsh and log you in.
-
You can run a
curl localhostto check if the httpd service with our base image homepage is working. Exit the VM withexit,logoutor Ctrl-d. -
Since we are going to refer to the quay.io registry, let us add $QUAY_USER to our .bashrc file.
-
and reload the .bashrc file to bring QUAY_USER into the variables.
-
Finally for this section run the bootc status command to view the booted image registry source and the RHEL version.
Our virtual machine based on Image Mode is now running and we are ready to make updates to the web page.
Update the Homepage VM to our Image Mode web page
The next steps we will update the web page in our homepage VM from the basic RHEL webpage that we created to an more updated web page showing the advantages of using Image Mode.
On our image builder server we will build a new Image Mode for RHEL 9 homepage image that we will deploy to the VM.
-
Change directory to the new web page Container file and the RHEL 9 Image Mode web page at
homepage-rhel9. You can open theindex.htmlfile in thehtmldirectory to see the updates to the homepage. -
Build the new homepage images from the
Containerfile.Tip
Remeber to change the $QUAY_USER in the
Containerfileto your repository userid. Remeber to make the homepage repository on your Quay registry public. -
Push the image to the registry using the
homepage:rhel9andhomepage:latesttags. -
Switch to the Homepage virtual machine and login to the
homepageVM using ssh. -
We are now going to use the
bootc switchcommand to switch the virtual machine to the homepage image in the registry.Tip
If you didn't add the
$QUAY_USERto the.bashrcfile then run the following -
Let us check the we have staged the new homepage image in the virtual machine.
-
and we check that we have the old RHEL 9 homepage without our new Image Mode content.
-
We need to reboot the virtual machine to activate the new layers and have our new home page.
-
Login to the virtual machine to verify that we have a new updated Image Mode homepage.
-
Something went wrong! Our httpd service has failed during the update! Let us check the service.
-
There is no httpd service. We will rollback in the next section and fix the problem.
Rollback and fix our homepage
In the previous section the httpd service wasn't in the image. This is due to a mistake we made in the Containerfile. First we will rollback so that we have the old homepage up and running and then we will fix the problem.
On our image builder server we will build a new Image Mode for RHEL 9 homepage image that we will deploy to the VM.
-
If you aren't in the
homepage-rhel9directory then change directory to the new web page Container file and the updated web page athomepage-rhel9. You can open theindex.htmlfile in thehtmldirectory to see the updates to the homepage. -
We need to fix the Containerfile to pull the correct image from the registry. Use an editor to change the following line to
Tip
Remeber to change the $QUAY_USER in the
Containerfileto your repository userid.change to
-
Build the new homepage images from the
Containerfileand tag to a new versionhomepage:rhel9-fix. -
Push the image to the registry using the
homepage:rhel9-fixandhomepage:latesttags. -
Switch to the Homepage virtual machine and login to the
homepageVM using ssh. -
We are going to use the
bootc switchcommand to switch the virtual machine to the homepage image in the registry.Tip
If you didn't add the
$QUAY_USERto the.bashrcfile then run the following -
Let us check the we have staged the new homepage image in the virtual machine.
-
and we check that we have the old RHEL 9 homepage without our new Image Mode content.
-
We need to reboot the virtual machine to activate the new layers and have our new home page.
-
Login to the virtual machine to verify that we have a new updated Image Mode homepage.
Build the database virtual machine
We will then deploy a new virtual machine named database as this will be our new demo database server.
We will build the two images in one linked command and push it as the version 1 and latest images to our registry.
We are following a less complex deployment for the database server than the deployment we did for the homepage. We are going to deploy the mariadb service using a bash script to automate the deployment.
In the mariadb_service directory update the QUAY_USER variable in the mariadb-deploy-rhel9.sh file and the Containerfile with your quay user id.
Review mariadb-service/mariadb-deploy-rhel9.sh
#! /bin/bash
# This script deploys a MariaDB database using Podman.
QUAY_USER="your quay username"
podman build -t quay.io/$QUAY_USER/database:latest -t quay.io/$QUAY_USER/database:rhel9.6 -f Containerfile
podman push quay.io/$QUAY_USER/database:latest && podman push quay.io/$QUAY_USER/database:rhel9.6
sudo podman pull quay.io/$QUAY_USER/database:latest
sudo podman run \
--rm \
-it \
--privileged \
--pull=newer \
--security-opt label=type:unconfined_t \
-v $(pwd)/config.toml:/config.toml:ro \
-v $(pwd):/output \
-v /var/lib/containers/storage:/var/lib/containers/storage registry.redhat.io/rhel9/bootc-image-builder:latest \
--type qcow2 \
--tls-verify=false \
quay.io/$QUAY_USER/database:latest
sudo mv qcow2/disk.qcow2 /var/lib/libvirt/images/database.qcow2
sudo virt-install \
--connect qemu:///system \
--name database \
--import \
--boot uefi \
--memory 4096 \
--graphics none \
--osinfo rhel9-unknown \
--noautoconsole \
--noreboot \
--disk /var/lib/libvirt/images/database.qcow2
sudo virsh start database
and the Containerfile
Review mariadb-service/Containerfile
-
Change to the
mariadb-servicedirectory. -
Ensure that the
mariadb-deploy.shfile is executable. -
Edit the mariadb-deploy.sh file and change the entry for the QUAY_USER to your quay.io user name.
-
Run the bash script
mariadb-deploy.shto create the database images and the database VM.
This will build and push the mariadb service image and deploy the VM from the image.