How to Set Docker Image Tags Based on the Build Commit Count

2023-06-16 04:09 (2 years ago)
Commit Steam Counter
Play a song themed on this article

Assigning version numbers based on commit count for simplicity

docker/config.sh

#!/usr/bin/env zsh

image_name=ytyng/my-docker-image
image_tag=1.11.$(git rev-list --count HEAD)

docker/build.sh

#!/usr/bin/env zsh

cd "$(dirname $0)" || exit

. ./config.sh

cd ..

docker build --platform linux/amd64 \
  --ssh default -t ${image_name}:${image_tag} \
  --build-arg IMAGE_TAG=${image_tag} \
  -f docker/Dockerfile .

docker tag ${image_name}:${image_tag} ${image_name}:latest

docker/Dockerfile

FROM ...
...
ARG IMAGE_TAG='-'
RUN echo ${IMAGE_TAG} > /app/VERSION.txt
Please rate this article
Currently unrated
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.

Categories

Archive