From 32777630e1e4ef63536def0dde24b2ef50420f20 Mon Sep 17 00:00:00 2001
From: Sheogorath <sheogorath@shivering-isles.com>
Date: Wed, 11 May 2022 02:12:30 +0200
Subject: [PATCH] feat(Makefile): Add universal container build CLI

This patch adds some basic build instructions for the container image
build infrastructure.
---
 Makefile                         |  2 ++
 images/.utils/container-build.mk | 24 +++++++++---------------
 images/demo/Makefile             |  2 --
 utils/images.mk                  |  8 ++++++++
 4 files changed, 19 insertions(+), 17 deletions(-)
 create mode 100644 utils/images.mk

diff --git a/Makefile b/Makefile
index cfe0555dc..9ef41ea5a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,7 @@
 .DEFAULT_GOAL := help
 
+REGISTRY_HOST := quay.io
+
 include utils/*.mk
 
 .PHONY: check-machine
diff --git a/images/.utils/container-build.mk b/images/.utils/container-build.mk
index 9c437f025..520df59c2 100644
--- a/images/.utils/container-build.mk
+++ b/images/.utils/container-build.mk
@@ -1,5 +1,6 @@
 #
 #   Copyright 2015  Xebia Nederland B.V.
+#   Copyright 2022  Christoph (Sheogorath) Kern
 #
 #   Licensed under the Apache License, Version 2.0 (the "License");
 #   you may not use this file except in compliance with the License.
@@ -14,7 +15,7 @@
 #   limitations under the License.
 #
 REGISTRY_HOST=docker.io
-USERNAME=$(USER)
+USERNAME=$(shell podman login --get-login $(REGISTRY_HOST))
 NAME=$(shell basename $(CURDIR))
 
 RELEASE_SUPPORT := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))/.make-release-support
@@ -48,15 +49,8 @@ post-push:
 
 docker-build: .release
 	podman build $(DOCKER_BUILD_ARGS) -t $(IMAGE):$(VERSION) $(DOCKER_BUILD_CONTEXT) -f $(DOCKER_FILE_PATH)
-	@DOCKER_MAJOR=$(shell podman -v | sed -e 's/.*version //' -e 's/,.*//' | cut -d\. -f1) ; \
-	DOCKER_MINOR=$(shell podman -v | sed -e 's/.*version //' -e 's/,.*//' | cut -d\. -f2) ; \
-	if [ $$DOCKER_MAJOR -eq 1 ] && [ $$DOCKER_MINOR -lt 10 ] ; then \
-		echo podman tag -f $(IMAGE):$(VERSION) $(IMAGE):latest ;\
-		podman tag -f $(IMAGE):$(VERSION) $(IMAGE):latest ;\
-	else \
-		echo podman tag $(IMAGE):$(VERSION) $(IMAGE):latest ;\
-		podman tag $(IMAGE):$(VERSION) $(IMAGE):latest ; \
-	fi
+	echo podman tag $(IMAGE):$(VERSION) $(IMAGE):latest ;\
+	podman tag $(IMAGE):$(VERSION) $(IMAGE):latest ; \
 
 .release:
 	@echo "release=0.0.0" > .release
@@ -68,9 +62,9 @@ docker-build: .release
 release: check-status check-release build push
 
 
-push: pre-push do-push post-push 
+push: pre-push do-push post-push
 
-do-push: 
+do-push:
 	podman push $(IMAGE):$(VERSION)
 	podman push $(IMAGE):latest
 
@@ -80,13 +74,13 @@ showver: .release
 	@. $(RELEASE_SUPPORT); getVersion
 
 tag-patch-release: VERSION := $(shell . $(RELEASE_SUPPORT); nextPatchLevel)
-tag-patch-release: .release tag 
+tag-patch-release: .release tag
 
 tag-minor-release: VERSION := $(shell . $(RELEASE_SUPPORT); nextMinorLevel)
-tag-minor-release: .release tag 
+tag-minor-release: .release tag
 
 tag-major-release: VERSION := $(shell . $(RELEASE_SUPPORT); nextMajorLevel)
-tag-major-release: .release tag 
+tag-major-release: .release tag
 
 patch-release: tag-patch-release release
 	@echo $(VERSION)
diff --git a/images/demo/Makefile b/images/demo/Makefile
index 7b29fd87b..0869882fc 100644
--- a/images/demo/Makefile
+++ b/images/demo/Makefile
@@ -1,7 +1,5 @@
 include ../.utils/container-build.mk
 
-USERNAME=shivering-isles
-
 pre-build:
 	@echo do some stuff before the docker build
 
diff --git a/utils/images.mk b/utils/images.mk
new file mode 100644
index 000000000..cd52e07f4
--- /dev/null
+++ b/utils/images.mk
@@ -0,0 +1,8 @@
+IMG_DIRS := $(wildcard images/*)
+
+.PHONY: $(IMG_DIRS)
+$(IMG_DIRS):
+	$(MAKE) -C $@ snapshot REGISTRY_HOST=$(REGISTRY_HOST) USERNAME=$(USERNAME)
+
+.PHONY: images
+images: $(IMG_DIRS) ## Build all local images
-- 
GitLab