
~ 3 minutes read
no time? jump straight to Customized Docker Image Tags
Do you want to customize docker image tags you push to GitHub Packages? This is how.
The preferred way to push to GitHub packages is GitHub Actions. GitHub Packages allows to publish docker images as well as other artifacts.
- name: Push to GitHub Packages
uses: docker/build-push-action@v1
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: docker.pkg.github.com
repository: lotharschulz/hello-github-actions/${{ github.sha }}
tag_with_ref: true
The GitHub Actions step above is straight forward and basically a copy/paste from these GitHub docs: Publishing images to GitHub Packages.
This setup creates sha hash docker image tags. There are more contexts available than just sha.

Actually, I was not happy with the limit capabilities to create docker image tags in this setup. I envisioned docker tags that includes:
- the repository name
- a time stamp
- the sha hash
Customized Docker Image Tags
- uses: actions/checkout@v1
- name: Build and Push
env:
DOCKER_USERNAME: ${{ github.actor }}
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
run: |
d=$(date +%Y-%m-%d--%H-%M-%S--%N)
tag=$d-${{ matrix.os }}-${{ github.sha }}
docker build -t docker.pkg.github.com/lotharschulz/hello-github-actions/hello-github-actions:$tag .
echo ${{ secrets.GITHUB_TOKEN }} | docker login https://docker.pkg.github.com -u USERNAME --password-stdin
docker push docker.pkg.github.com/lotharschulz/hello-github-actions/hello-github-actions:$tag
Publishing docker images using a step as above enables you to use all options of the docker cli – within the ubuntu shell in my case [link zu meinem Repo einfügen].
This is more flexible compared with the initial approach and thus my favorite.
However, it also comes with a price: you also need to login and push via docker cli.
I like this docker image tag much better:

Links
- https://docs.docker.com/engine/reference/commandline/tag/
- https://docs.github.com/en/packages
- https://docs.github.com/en/actions/getting-started-with-github-actions/core-concepts-for-github-actions#step
- https://docs.github.com/en/actions/language-and-framework-guides/publishing-docker-images#publishing-images-to-github-packages
- https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#contexts
- https://en.wikipedia.org/wiki/Ubuntu
- https://en.wikipedia.org/wiki/Unix_shell
- https://docs.docker.com/engine/reference/commandline/cli/
- https://github.com/lotharschulz/hello-github-actions/blob/gps/.github/workflows/cicd.yml
Other artifacts you can publish to GitHub Packages are node and java packages. Magnus and me explore in Publishing artifacts with AWS Codeartifact and GitHub Packages the node and java package publication not only for GitHub Packages, but also for AWS Codeartifact.