|
| 1 | +# |
| 2 | +# Copyright 2015 Xebia Nederland B.V. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +# |
| 16 | + |
| 17 | +# If you set the environment variables with same name as variables then they will be used otherwise default |
| 18 | +# values will be used. |
| 19 | +REGISTRY_HOST ?= docker.io |
| 20 | +USERNAME ?= stakater |
| 21 | +NAME ?= base-debian |
| 22 | + |
| 23 | +RELEASE_SUPPORT := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))/.make-release-support |
| 24 | +IMAGE=$(REGISTRY_HOST)/$(USERNAME)/$(NAME) |
| 25 | + |
| 26 | +VERSION=$(shell . $(RELEASE_SUPPORT) ; getVersion) |
| 27 | +# TAG=$(shell . $(RELEASE_SUPPORT) ; getVersion) |
| 28 | + |
| 29 | +SHELL=/bin/bash |
| 30 | + |
| 31 | +.PHONY: pre-build docker-build post-build build release patch-release minor-release major-release tag check-status check-release showver \ |
| 32 | + push pre-push do-push post-push |
| 33 | + |
| 34 | +build: pre-build docker-build post-build |
| 35 | + |
| 36 | +pre-build: |
| 37 | + |
| 38 | +post-build: |
| 39 | + |
| 40 | +pre-push: |
| 41 | + |
| 42 | +post-push: |
| 43 | + |
| 44 | +docker-build: .release |
| 45 | + docker build $(DOCKER_BUILD_ARGS) -t $(IMAGE):$(VERSION) . --network=host |
| 46 | + @DOCKER_MAJOR=$(shell docker -v | sed -e 's/.*version //' -e 's/,.*//' | cut -d\. -f1) ; \ |
| 47 | + DOCKER_MINOR=$(shell docker -v | sed -e 's/.*version //' -e 's/,.*//' | cut -d\. -f2) ; \ |
| 48 | + if [ $$DOCKER_MAJOR -eq 1 ] && [ $$DOCKER_MINOR -lt 10 ] ; then \ |
| 49 | + echo docker tag -f $(IMAGE):$(VERSION) $(IMAGE):latest ;\ |
| 50 | + docker tag -f $(IMAGE):$(VERSION) $(IMAGE):latest ;\ |
| 51 | + else \ |
| 52 | + echo docker tag $(IMAGE):$(VERSION) $(IMAGE):latest ;\ |
| 53 | + docker tag $(IMAGE):$(VERSION) $(IMAGE):latest ; \ |
| 54 | + fi |
| 55 | + |
| 56 | +.release: |
| 57 | + @echo "release=0.0.0" > .release |
| 58 | + @echo INFO: .release created |
| 59 | + @cat .release |
| 60 | + |
| 61 | +release: check-status check-release build push |
| 62 | + |
| 63 | +push: pre-push do-push post-push |
| 64 | + |
| 65 | +do-push: |
| 66 | + docker push $(IMAGE):$(VERSION) |
| 67 | + docker push $(IMAGE):latest |
| 68 | + |
| 69 | +snapshot: build push |
| 70 | + |
| 71 | +showver: .release |
| 72 | + @. $(RELEASE_SUPPORT); getVersion |
| 73 | + |
| 74 | +tag-patch-release: VERSION := $(shell . $(RELEASE_SUPPORT); nextPatchLevel) |
| 75 | +tag-patch-release: .release tag |
| 76 | + |
| 77 | +tag-minor-release: VERSION := $(shell . $(RELEASE_SUPPORT); nextMinorLevel) |
| 78 | +tag-minor-release: .release tag |
| 79 | + |
| 80 | +tag-major-release: VERSION := $(shell . $(RELEASE_SUPPORT); nextMajorLevel) |
| 81 | +tag-major-release: .release tag |
| 82 | + |
| 83 | +patch-release: tag-patch-release release |
| 84 | + @echo $(VERSION) |
| 85 | + |
| 86 | +minor-release: tag-minor-release release |
| 87 | + @echo $(VERSION) |
| 88 | + |
| 89 | +major-release: tag-major-release release |
| 90 | + @echo $(VERSION) |
| 91 | + |
| 92 | +tag: TAG=$(shell . $(RELEASE_SUPPORT) ; getVersion) |
| 93 | +tag: check-status |
| 94 | + @. $(RELEASE_SUPPORT) ; ! tagExists $(VERSION) || (echo "ERROR: tag $(VERSION) for version $(VERSION) already tagged in git" >&2 && exit 1) ; |
| 95 | + @. $(RELEASE_SUPPORT) ; setRelease $(VERSION) |
| 96 | + @. $(RELEASE_SUPPORT) ; checkIfStatusChanged $(VERSION) |
| 97 | + git tag $(VERSION) |
| 98 | + git push --tags |
| 99 | + # @ if [ -n "$(shell git remote -v)" ] ; then git push --tags ; else echo 'no remote to push tags to' ; fi |
| 100 | + |
| 101 | +check-status: |
| 102 | + @. $(RELEASE_SUPPORT) ; ! hasChanges || (echo "ERROR: there are still outstanding changes" >&2 && exit 1) ; |
| 103 | + |
| 104 | +check-release: .release |
| 105 | + @. $(RELEASE_SUPPORT) ; tagExists $(VERSION) || (echo "ERROR: version not yet tagged in git. make [minor,major,patch]-release." >&2 && exit 1) ; |
| 106 | + @. $(RELEASE_SUPPORT) ; ! differsFromRelease $(VERSION) || (echo "ERROR: current directory differs from tagged $(VERSION). make [minor,major,patch]-release." ; exit 1) |
0 commit comments