diff --git a/images/.utils/.make-release-support b/images/.utils/.make-release-support new file mode 100644 index 0000000000000000000000000000000000000000..31b56a1dbe9bfb4dd5f81e2293fcb7299ab3fbf3 --- /dev/null +++ b/images/.utils/.make-release-support @@ -0,0 +1,105 @@ +#!/bin/bash +# +# Copyright 2015 Xebia Nederland B.V. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +function hasChanges() { + test -n "$(git status -s .)" +} + +function getRelease() { + awk -F= '/^release=/{print $2}' .release +} + +function getBaseTag() { + sed -n -e "s/^tag=\(.*\)$(getRelease)\$/\1/p" .release +} + +function getTag() { + if [ -z "$1" ] ; then + awk -F= '/^tag/{print $2}' .release + else + echo "$(getBaseTag)$1" + fi +} + +function setRelease() { + if [ -n "$1" ] ; then + sed -i.x -e "s~^tag=.*~tag=$(getTag $1)~" .release + sed -i.x -e "s~^release=.*~release=$1~g" .release + rm -f .release.x + runPreTagCommand "$1" + else + echo "ERROR: missing release version parameter " >&2 + return 1 + fi +} + +function runPreTagCommand() { + if [ -n "$1" ] ; then + COMMAND=$(sed -n -e "s/@@RELEASE@@/$1/g" -e 's/^pre_tag_command=\(.*\)/\1/p' .release) + if [ -n "$COMMAND" ] ; then + if ! OUTPUT=$(bash -c "$COMMAND" 2>&1) ; then echo $OUTPUT >&2 && exit 1 ; fi + fi + else + echo "ERROR: missing release version parameter " >&2 + return 1 + fi +} + +function tagExists() { + tag=${1:-$(getTag)} + test -n "$tag" && test -n "$(git tag | grep "^$tag\$")" +} + +function differsFromRelease() { + tag=$(getTag) + ! tagExists $tag || test -n "$(git diff --shortstat -r $tag .)" +} + +function getVersion() { + result=$(getRelease) + + if differsFromRelease; then + result="$result-$(git log -n 1 --format=%h .)" + fi + + if hasChanges ; then + result="$result-dirty" + fi + echo $result +} + +function nextPatchLevel() { + version=${1:-$(getRelease)} + major_and_minor=$(echo $version | cut -d. -f1,2) + patch=$(echo $version | cut -d. -f3) + version=$(printf "%s.%d" $major_and_minor $(($patch + 1))) + echo $version +} + +function nextMinorLevel() { + version=${1:-$(getRelease)} + major=$(echo $version | cut -d. -f1); + minor=$(echo $version | cut -d. -f2); + version=$(printf "%d.%d.0" $major $(($minor + 1))) ; + echo $version +} + +function nextMajorLevel() { + version=${1:-$(getRelease)} + major=$(echo $version | cut -d. -f1); + version=$(printf "%d.0.0" $(($major + 1))) + echo $version +} diff --git a/images/.utils/container-build.mk b/images/.utils/container-build.mk new file mode 100644 index 0000000000000000000000000000000000000000..9c437f025b3bb511b6c8fafa9aa7174b8415a722 --- /dev/null +++ b/images/.utils/container-build.mk @@ -0,0 +1,115 @@ +# +# Copyright 2015 Xebia Nederland B.V. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +REGISTRY_HOST=docker.io +USERNAME=$(USER) +NAME=$(shell basename $(CURDIR)) + +RELEASE_SUPPORT := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))/.make-release-support +IMAGE=$(REGISTRY_HOST)/$(USERNAME)/$(NAME) + +VERSION=$(shell . $(RELEASE_SUPPORT) ; getVersion) +TAG=$(shell . $(RELEASE_SUPPORT); getTag) + +SHELL=/bin/bash + +DOCKER_BUILD_CONTEXT=. +DOCKER_FILE_PATH=Containerfile + +.PHONY: pre-build docker-build post-build build release patch-release minor-release major-release tag check-status check-release showver \ + push pre-push do-push post-push + +build: pre-build docker-build post-build + +pre-build: + + +post-build: + + +pre-push: + + +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 + +.release: + @echo "release=0.0.0" > .release + @echo "tag=$(NAME)-0.0.0" >> .release + @echo INFO: .release created + @cat .release + + +release: check-status check-release build push + + +push: pre-push do-push post-push + +do-push: + podman push $(IMAGE):$(VERSION) + podman push $(IMAGE):latest + +snapshot: build push + +showver: .release + @. $(RELEASE_SUPPORT); getVersion + +tag-patch-release: VERSION := $(shell . $(RELEASE_SUPPORT); nextPatchLevel) +tag-patch-release: .release tag + +tag-minor-release: VERSION := $(shell . $(RELEASE_SUPPORT); nextMinorLevel) +tag-minor-release: .release tag + +tag-major-release: VERSION := $(shell . $(RELEASE_SUPPORT); nextMajorLevel) +tag-major-release: .release tag + +patch-release: tag-patch-release release + @echo $(VERSION) + +minor-release: tag-minor-release release + @echo $(VERSION) + +major-release: tag-major-release release + @echo $(VERSION) + + +tag: TAG=$(shell . $(RELEASE_SUPPORT); getTag $(VERSION)) +tag: check-status + @. $(RELEASE_SUPPORT) ; ! tagExists $(TAG) || (echo "ERROR: tag $(TAG) for version $(VERSION) already tagged in git" >&2 && exit 1) ; + @. $(RELEASE_SUPPORT) ; setRelease $(VERSION) + git add . + git commit -m "bumped to version $(VERSION)" ; + git tag $(TAG) ; + @ if [ -n "$(shell git remote -v)" ] ; then git push --tags ; else echo 'no remote to push tags to' ; fi + +check-status: + @. $(RELEASE_SUPPORT) ; ! hasChanges || (echo "ERROR: there are still outstanding changes" >&2 && exit 1) ; + +check-release: .release + @. $(RELEASE_SUPPORT) ; tagExists $(TAG) || (echo "ERROR: version not yet tagged in git. make [minor,major,patch]-release." >&2 && exit 1) ; + @. $(RELEASE_SUPPORT) ; ! differsFromRelease $(TAG) || (echo "ERROR: current directory differs from tagged $(TAG). make [minor,major,patch]-release." ; exit 1) diff --git a/images/demo/.release b/images/demo/.release new file mode 100644 index 0000000000000000000000000000000000000000..85f180f38cd7bb8259cfadf2e12bfde62fc8f99d --- /dev/null +++ b/images/demo/.release @@ -0,0 +1 @@ +release=0.1.0 diff --git a/images/demo/Containerfile b/images/demo/Containerfile new file mode 100644 index 0000000000000000000000000000000000000000..0f75c5943d10ebcb1dbd93683afe811d6664b5d4 --- /dev/null +++ b/images/demo/Containerfile @@ -0,0 +1,3 @@ +FROM registry.shivering-isles.com/fedora/fedora:35 + +RUN echo "Hello world" diff --git a/images/demo/Makefile b/images/demo/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..7b29fd87bdcb1fedd4d2ee7198986f74ea50c2a3 --- /dev/null +++ b/images/demo/Makefile @@ -0,0 +1,9 @@ +include ../.utils/container-build.mk + +USERNAME=shivering-isles + +pre-build: + @echo do some stuff before the docker build + +post-build: + @echo do some stuff after the docker build