Thursday 17 October 2024

GitHub Actions and Tagging Images

Sometimes an image created and put in some repository needs to have more than one tag. The most common case is when building on to tag it as latest. Or current. The GitHub actions by default tag it with the the short SHA of the commit that triggered the workflow. This is like the built image has its own ID whit which it can be addressed in later commands:

This is good ... in Github's own context. But in the lifecycle of the image it may exist in several other contexts (repository, deployment environment, automation scripts, etc.)

There are a few ways (command syntaxes). Probably the easiest way is to just list the image:tag pairs one after the other:

Yet, there is even simpler way: not to issue the tag command but to define the tags during build-time:

And this works fine. 

Next the tags have to be pushed to the desired repository. I ensured (for myself) that pushing the same image with different tags doesn't create multiple copies of the same image but only adds the new tags to the same image (silly thought but the question appears at some point).

Another question was if a push command has to be issued for every single tag, or this can be done in one go. You know - to reduce traffic (sometimes images are +1GB) ...

I found the correct syntax for pushing multiple tags with a single command:

And it worked just fine in a local experiment.


The key (obviously) was to use the --all-tags option of the docker push command. It also has the reduced form -a.

Unfortunately this didn't work in the Github action, since the Docker version in the runner's environment doesn't recognize the said option:

This, of course, is a bit unpleasant but not a showstopper. The solution is to simply issue the command once per every tag.  Which is another reason for striving to keep images smaller when possible.

Maybe I should try the same setup with podman sometime.

 

No comments: