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

2023-06-16 13:09 (1 years ago) ytyng

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
Currently unrated

Comments

Archive

2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011