top of page

How to Create an Efficient Pipeline for Pulling, Tagging, Validating, and Pushing Docker Images to GitHub Container Registry (GHCR)

  • Writer: Rajamohan Rajendran
    Rajamohan Rajendran
  • Feb 27
  • 3 min read

Updated: Mar 9


ree

Hey there, Docker enthusiasts! If you’ve ever been tangled up in the complexities of managing Docker images, especially for something as powerful as Grafana, you’re not alone. But fear not! Today, we’re diving into a nifty Azure DevOps pipeline configuration that helps you pull images from the public Docker Hub, tag them, validate them, and then push them to GitHub Container Registry (GHCR). Let’s break it down step by step!

What’s This Pipeline All About?

At its core, this pipeline automates the management of your Docker images. Whether you're working on updates, fixes, or just keeping things in check, this YAML configuration makes your life a whole lot easier by handling the grunt work for you.

Setting the Stage: Triggers and Pools

First things first, we set our trigger to respond to any changes on the grafana branch. When you make updates here, the pipeline jumps into action!

We’re also using an ubuntu-latest virtual machine image as our pool. Why? Because it’s robust, reliable, and perfect for our Docker needs.

Variables: The Hidden Heroes

In any pipeline, managing variables smoothly is crucial. We’ve got some handy ones here:

  • Variable Group: vg-github-package-access brings in credentials for GitHub packages effortlessly.

  • Build Configuration: Set to Release, because we’re all about pushing stable versions out there.

  • Versioning: We’ve added some sophistication here. Different variables for major, minor, and build versions help us keep track of image iterations. Plus, if the source branch isn't grafana, it appends -beta to the version. Nice touch, right?


Pipeline Steps: The How-To

Let’s break down the core steps that make all of this happen:

  1. Install Docker CLI: We kick things off by installing Docker CLI (version 20.10.23) using DockerInstaller@0. This gets us ready to work with Docker commands.

  2. Docker Login: Here, we connect to Docker Hub using a service connection called DockerHubConnection. It’s like saying, “Hey Docker Hub, let us in!”

  3. Pull Grafana Image: The magic begins! We make a call to pull the latest Grafana image from Docker Hub.

  4. Validate Grafana Image Details: What’s the point of pulling an image if you don’t know what you’re dealing with? Using jq, we inspect the image for its ID, size, and creation date.

  5. Tag Grafana Image: We tag the pulled image with two versions - one with our defined versioning scheme and another as the ‘latest’ tag for simplicity.

  6. Validate Tagged Image Details: Gotta double-check, right? We inspect our newly tagged image to ensure everything looks good before moving on.

  7. Push Docker Image to GHCR: Now we log in to the GitHub Container Registry using a personal access token (we’re all about security!) and push both the versioned and latest tags to GHCR.

  8. Verify Image Push: Finally, we check that our images made it to the registry. If something’s wrong, the script will let you know, giving you peace of mind.

  9. Docker Hub Logout: We wrap things up by logging out from Docker Hub, keeping our session neat and tidy.


Why Use This Pipeline?

This pipeline isn’t just about automating tasks; it’s about enhancing security and efficiency in your CI/CD workflow. Here's why it’s a game-changer:

  • Conditional Versioning: Flexible versioning scheme helps keep things organized based on your branches.

  • Comprehensive Validation: Ensuring both original and tagged images are validated reduces the chances of errors.

  • Secure Management: We manage sensitive info elegantly with variable groups and personal access tokens.


Wrapping It Up

By now, you should have a solid grasp of how this Azure DevOps pipeline can transform your Docker image management for your Grafana applications. Not only does it automate the process, but it also keeps everything secure and validated. So, if you’re looking to streamline your Docker workflows, give this pipeline a shot. Happy coding, and may your images always push successfully!

Code

To see yaml source code click the below link




Comments


bottom of page