Chapter 3. Customizing GitLab pipelines and rebuilding container images When customizing pipelines in GitLab, rebuilding container image is a critical step to ensure your changes are included in the updated workflow. Pipelines in GitLab rely on specific container image, such as the GitLab runner image, to execute the tasks defined in your CI/CD workflow. The GitLab runner image provides the necessary tools, configuration, and scripts required for your pipeline to run. If you modify tasks in the pipeline, you must update and rebuild the container image to include those changes. This ensures that you pipeline tasks are properly executed when the pipeline is triggered. Rebuilding container image involves the following steps: Running podman to extract the existing pipeline files. Customizing the pipeline tasks as per your requirements. Rebuilding the container image. Pushing the updated image to a container registry. Prerequisites Before making changes, ensure that: You have podman installed on your system. You have login credentials for Quay.io to push the updated image. You have forked and cloned the Sample templates repository. Your forked repository is up to date and synced with the upstream repository. Procedure Create a directory for the build resources. The location of the directory depends on your role: Platform engineer: If you are rebuilding the image to update the default pipeline for your organization, you may create the directory within the location where you forked the tssc-sample-templates repository. For example, rebuild-image . Developers: If you are rebuilding the image for your own use or a specific project, create a directory in a location outside the organization-wide fork of tssc-sample-templates to avoid conflicts. mkdir rebuild-image Run the following command and copy the container image URL: more ../tssc-sample-templates/skeleton/ci/source-repo/gitlabci/.gitlab-ci.yml # Example: ... image: quay.io/redhat-appstudio/rhtap-task-runner:latest ... Copy the existing pipeline content locally by running the following command: podman run -v USD(pwd):/pwd:z <The_url_you_copied_in_step_2> cp -r /work/rhtap /pwd 1 1 This command starts the container using the <the_url_you_copied_in_step_2> image. It then copies the pipeline files from /work/rhtap inside the container to your working directory (USD(pwd)). Additionally, if you are not on a system with SELinux enabled (for example, Fedora, RHEL, pr CentOS), remove the :z option in the command to ensure compatibility. Navigate to the rhtap directory and customize the pipelines tasks as required. Create a Dockerfile in the rebuild-image directory and add the following content to include your changes in the container. Additionally, the base image quay.io/redhat-appstudio/rhtap-task-runner:latest is built on ubi/ubi-minimal , which provides a lightweight Universal Base Image (UBI). If you need to install additional software and dependencies, use microdnf . An example command: FROM quay.io/redhat-appstudio/rhtap-task-runner:latest 1 #Copy the updated pipeline tasks COPY ./rhtap /work/rhtap 2 # Example: Install additional software (for example, git) RUN microdnf -y install make 3 1 Uses the existing rhtap-runner container as the starting point. 2 Copies the updated pipeline tasks from the local rhtap folder into the /work/rhtap directory inside the container. 3 Demonstrates the use of the microdnf to install additional software or dependencies. Build the new container image with the following command: podman build -f Dockerfile -t quay.io/<namespace>/<new_image_name> 1 1 -f Dockerfile specifies the Dockerfile to use for the build the container image. The -f flag allows you to explicitly point to the Dockerfile if it's not named Dockerfile or is located in a different directory. -t quay.io/<namespace>/<new_image_name> assigns a tag (name) to the container image for easy identification. Login to Quay.io and push the updated image: podman login quay.io # Enter username and password podman push quay.io/<namespace>/<new_image_name> 1 1 This uploads the customized container image to Quay.io, making it available for use in GitLab pipelines. Platform engineer only: Navigate to tssc-sample-templates > skeleton > ci > source-repo > gitlabci > .gitlab-ci.yml file and replace the container image URL with the one you just created. This makes the new container image as the default. image: quay.io/<namespace>/<new_image_name> For developers only: To update the container image just for a single repository in GitLab: Navigate to the source repository > .gitlab-ci.yaml and replace the container image URL with the one you just created. image: quay.io/<namespace>/<new_image_name> Commit and push the changes to apply the updated pipeline configuration.

Commands:
mkdir rebuild-image
more ../tssc-sample-templates/skeleton/ci/source-repo/gitlabci/.gitlab-ci.yml Example: image: quay.io/redhat-appstudio/rhtap-task-runner:latest
run -v USD(pwd):/pwd:z <The_url_you_copied_in_step_2> cp -r /work/rhtap /pwd 1
FROM quay.io/redhat-appstudio/rhtap-task-runner:latest 1 #Copy the updated pipeline tasks COPY ./rhtap /work/rhtap 2 Example: Install additional software (for example, git) RUN microdnf -y install make 3
build -f Dockerfile -t quay.io/<namespace>/<new_image_name> 1
login quay.io Enter username and password push quay.io/<namespace>/<new_image_name> 1
image: quay.io/<namespace>/<new_image_name>
image: quay.io/<namespace>/<new_image_name>