This is a portion of a Makefile where I select a Git tag, validate its name using regular expresion and build a Docker image with it as tag.
# it is evaluated when is used (recursively expanded variable)
# https://ftp.gnu.org/old-gnu/Manuals/make-3.79.1/html_chapter/make_6.html#SEC59
git_tag = $(shell git describe --abbrev=0 --tags)
# Semantic versioning format https://semver.org/
tag_regex := ^v([0-9]{1,}\.){2}[0-9]{1,}$
build-image-prod:
ifeq ($(shell echo ${git_tag} | egrep "${tag_regex}"),)
@echo "No Git tag selected. Are there tags?"
else
@git checkout ${git_tag} -q
@echo "Building image for production for Git tag $(git_tag)"
docker build --target prod --tag trivago/ha-ci-api:$(git_tag) --file docker/api/Dockerfile .
endif
I think in Makefiles you have to scape the dollar sign so this is interpreted correctly by grep as the end of the string