Welcome back to our blog post series about wolfi-act! In this installment, we're excited to show you how to harness the capabilities of wolfi-act within the GitLab CI/CD ecosystem. You may recall from our recent blog post that wolfi-act initially made waves in the GitHub Actions arena. Speaking of which, if you missed our previous post, we encourage you to give it a read for a deeper dive into the wolfi-act project. However, the good news is that it's not limited to GitHub Actions anymore!
In the ever-evolving world of software development, staying ahead of the curve requires the right tools and practices. Whether you're a developer, a DevOps engineer, or a tech enthusiast, you'll want to meet GitLab – a CI/CD platform that's transforming the way teams build, deploy, and manage software.
Now, let's get to the heart of the matter—integrating wolfi-act into your GitLab CI/CD pipeline. This powerful combination opens up a world of possibilities for automating and enhancing your development workflow. We'll guide you through the process, step by step, so you can leverage wolfi-act on GitLab and supercharge your CI/CD pipeline.
In the GitLab CI/CD ecosystem, executors are pivotal components that determine how your CI/CD jobs are executed. While they serve a similar purpose to GitHub-hosted Runners, GitLab Executors come with their own set of features and benefits.
At their core, GitLab Executors are responsible for running the jobs defined in your CI/CD pipelines. They dictate the environment in which these jobs are executed and influence key aspects of the execution process.
GitLab provides several types of Executors, each with its own unique characteristics, allowing you to tailor your CI/CD setup to match your project's specific requirements.
Today, we’ll be focusing on the Docker and Kubernetes executor types where the wolfi-act integration makes things easier for you. If you want to learn more about the other supported types of executors in GitLab, here is the full list.
Both executor types need container images to be able to execute jobs. This is where wolfi-act becomes handy.
The challenge remains consistent with what we discussed in our previous blog post. Ensuring that all the necessary tools are readily available within container images for running pipelines poses a significant hurdle. This issue arises because every time a new tool is required for a pipeline, it must be incorporated into the specified container image for the task. Consequently, there's a repetitive process of rebuilding the image to accommodate evolving needs, demanding both time and effort.
Moreover, this practice often leads to the creation of excessively large container images, exceeding 1 GB in size. These images tend to contain an abundance of tools that surpass the actual requirements of a given pipeline. As a result, this surplus of tools contributes to increased network bandwidth consumption and prolonged build times.
Furthermore, it's highly likely that these images will go unattended, as they're typically created for a specific, short-term purpose to fulfill current objectives. Additionally, they tend to accumulate in your Container Registry, essentially becoming digital clutter (needs to be garbage collected after a while). From a security standpoint, unmaintained container images can pose risks by potentially exposing your system to new vulnerabilities.
In the GitHub Actions demo within the previous blog post, we have used GitHub’s reusable workflow feature to avoid duplication in workflows. GitHub Actions offers reusable workflows as a means to create a centralized and easily maintainable set of job definitions. These workflows allow developers to define jobs in a single place and reuse them across repositories.
On the other hand, GitLab CI/CD provides hidden jobs, which enable job definition sharing without exposing them in the main CI/CD configuration file, promoting cleaner and more modular configurations. We have to explain what the hidden jobs are before because we defined the `wolfi-act` as a hidden job within the following example. You can learn more about tips and tricks for avoiding duplication in your CI/CD workflow on GitLab, here.
Talk is cheap, show me the code!
> Note: You can find all the source code in the GitLab repository, here.
The following code snippet is the equivalent of the example in the previous blog post with few differences:
As you can see here we defined `wolfi-act` as a hidden job and we used it in the `build-publish-oci-image-with-apko` job through the '.extends` keyword. We also expect two environment variables, one for packages that need to be installed and the other for the script as we did in the previous blog post for the GitHub Actions demo.
Whee! That’s all you need to do to install necessary tools for your scripts, easy peasy!
Thanks for reading, hope you enjoyed it, see you next time!