GitLab

Refactor multi-architecture image building process

  • Review changes

  • Download

Update the GitLab CI/CD configuration to utilize Podman for multi-architecture image builds, replacing the previous Buildah-based approach. The new build-multiarch.sh script is refined to support both standard and testing build flows, with automated cleanup for testing images.

The previous setup used buildah directly in the .gitlab-ci.yml script. This change centralizes the build logic into a dedicated script, enhancing maintainability and reusability. Podman is a suitable alternative as it supports the same command-line options as Docker, offering a simpler CI configuration without the overhead of a Docker daemon pythonspeed.com.

Key changes include:

  • Migrate from buildah to quay.io/podman/stable as the base image for the build job in .gitlab-ci.yml.
  • Introduce dnf install -y skopeo to enable deleting images from the registry using Skopeo during testing, ensuring better cleanup practices docs.gitlab.com.
  • Implement podman login to explicitly authenticate with the GitLab Container Registry, aligning with best practices for building and pushing images docs.gitlab.com.
  • Refine the build-multiarch.sh script to:
    • Consolidate logic for extracting the project image name, handling GitLab CI/CD variables (CI_REGISTRY_IMAGE, CI_COMMIT_SHORT_SHA), or local Git configuration.
    • Add a --testing flag to append a -testing suffix to image tags and ensure automatic cleanup of remote images using skopeo after the push, which requires the GITLAB_TOKEN_REGISTRY environment variable. This helps to manage test artifacts in the registry.
    • Simplify argument parsing and improve error handling for better user experience.
    • Remove redundant local cleanup logic now that the script can clean up remote tags.

This refactoring streamlines the image building workflow within GitLab CI/CD, making it more robust and flexible for both production and development testing scenarios. Podman provides a stable and secure environment for container operations, including rootless builds, which enhances the security posture of the CI pipeline docs.gitlab.com. The Docker executor now uses Podman as its container runtime, supporting services when the FF_NETWORK_PER_BUILD feature flag is enabled docs.gitlab.com.

Read the original on gitlab.com ↗