Enhance Makefile with publish target and add git information for Docker image versioning

This commit is contained in:
Krisztián Szabolcsi 2026-01-10 14:09:41 +01:00
parent 30357418b5
commit 2f8bce9a8a
2 changed files with 32 additions and 1 deletions

View File

@ -45,3 +45,33 @@ shell:
help: help:
@printf "Usage:\n make build Build local docker image ($(IMAGE))\n make run Run image mounting project into $(WORKDIR) (port $(PORT))\n make stop Stop running container\n make shell Start a shell in a container with project mounted\n\nOverride variables: IMAGE, CONTAINER, WORKDIR, PORT, DOCKER_BUILD_ARGS, DOCKER_RUN_ARGS\n" @printf "Usage:\n make build Build local docker image ($(IMAGE))\n make run Run image mounting project into $(WORKDIR) (port $(PORT))\n make stop Stop running container\n make shell Start a shell in a container with project mounted\n\nOverride variables: IMAGE, CONTAINER, WORKDIR, PORT, DOCKER_BUILD_ARGS, DOCKER_RUN_ARGS\n"
git_info:
$(eval GIT_HASH = $(shell git rev-parse HEAD))
$(eval GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD))
publish: git_info
$(eval VERSION = $(shell git describe --tags 2>/dev/null | grep -e '^[0-9]\.[0-9]*\.[0-9]'))
@if [ -z "${VERSION}" ]; \
then \
echo "Error: Nincs verzió szám"; \
exit 1; \
fi
#@sudo docker login $(DOCKER_REGISTRY)
@sudo docker build \
--no-cache \
--label version=$(VERSION) \
--label org.opencontainers.image.created=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") \
--label org.opencontainers.image.authors="Krisztián Szabolcsi" \
--label org.opencontainers.image.version=$(VERSION) \
--label org.opencontainers.image.licences=MIT \
--label org.opencontainers.image.source=https://${DOCKER_REGISTRY}/${OWNER}/${NAME} \
--label org.opencontainers.image.revision=$(GIT_HASH) \
--label org.opencontainers.image.vendor="Krisztián Szabolcsi" \
--label org.opencontainers.image.description="IMAP email notification service using ntfy.sh" \
--label org.opencontainers.image.source.branch=$(GIT_BRANCH) \
--label org.opencontainers.image.source.hash=$(GIT_HASH) \
-t $(DOCKER_REGISTRY)/${OWNER}/$(NAME):$(VERSION) \
.
@sudo docker push $(DOCKER_REGISTRY)/$(NAME):$(VERSION)

View File

@ -1 +1,2 @@
NAME=imap_notification NAME=imap_notification
DOCKER_REGISTRY=gitea.szabolcsi.dev