This repository has been archived by the owner on Feb 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
116 lines (99 loc) · 4.19 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Import config
# You can change the default config with `make config="config_special.env" build`
config ?= config.env
include $(config)
VERSION := $(shell cat VERSION)
GITCOMMIT := $(shell git rev-parse --short HEAD)
GITBRANCH := $(shell git rev-parse --abbrev-ref HEAD)
GITUNTRACKEDCHANGES := $(shell git status --porcelain --untracked-files=no)
ifneq ($(GITUNTRACKEDCHANGES),)
GITCOMMIT := $(GITCOMMIT)-dirty
endif
LATEST_KUBERNETES_VERSION := $(shell curl -s https://storage.googleapis.com/kubernetes-release/release/latest.txt)
STABLE_KUBERNETES_VERSION := $(shell curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)
KUBERNETES_VERSION ?= latest
VERSION_TAG := v$(GITCOMMIT)-k8s-$(KUBERNETES_VERSION)
LATEST_TAG := v$(GITCOMMIT)-k8s-$(KUBERNETES_VERSION)
BUILD_TAG := $(GITBRANCH)-$(GITCOMMIT)-k8s-$(KUBERNETES_VERSION)
ifeq ($(KUBERNETES_VERSION),stable)
override KUBERNETES_VERSION := $(STABLE_KUBERNETES_VERSION)
VERSION_TAG := $(VERSION)
LATEST_TAG := stable
BUILD_TAG := $(GITBRANCH)-$(GITCOMMIT)-k8s-$(KUBERNETES_VERSION)
endif
ifeq ($(KUBERNETES_VERSION),latest)
override KUBERNETES_VERSION := $(LATEST_KUBERNETES_VERSION)
VERSION_TAG := $(VERSION)-k8s-$(KUBERNETES_VERSION)
LATEST_TAG := latest
BUILD_TAG := $(GITBRANCH)-$(GITCOMMIT)-k8s-$(KUBERNETES_VERSION)
endif
ifdef TRAVIS
ifneq ($(TRAVIS_TAG),)
VERSION_TAG := $(VERSION)-k8s-$(KUBERNETES_VERSION)
LATEST_TAG := $(VERSION)-k8s-$(KUBERNETES_VERSION)
endif
BUILD_TAG := travis-$(TRAVIS_BUILD_NUMBER)-$(TRAVIS_BRANCH)-$(GITCOMMIT)-k8s-$(KUBERNETES_VERSION)
endif
.DEFAULT_GOAL := help
.PHONY: all
all: docker-build docker-images docker-push ## Runs a docker-build, docker-images, docker-push
.PHONY: check-env
check-env: ## Checks the environment variables
ifndef KUBERNETES_VERSION
$(error KUBERNETES_VERSION is undefined)
endif
@echo "KUBERNETES_VERSION: $(KUBERNETES_VERSION)"
@echo "VERSION_TAG: $(VERSION_TAG)"
@echo "LATEST_TAG: $(LATEST_TAG)"
@echo "BUILD_TAG: $(BUILD_TAG)"
.PHONY: docker-build
docker-build: check-env ## Build the container
@echo "+ $@"
@docker build --build-arg KUBERNETES_VERSION=$(KUBERNETES_VERSION) -t $(REPO):$(GITCOMMIT) .
@docker tag $(REPO):$(GITCOMMIT) $(DOCKER_REGISTRY)/$(REPO):$(LATEST_TAG)
@docker tag $(REPO):$(GITCOMMIT) $(DOCKER_REGISTRY)/$(REPO):$(VERSION_TAG)
@docker tag $(REPO):$(GITCOMMIT) $(DOCKER_REGISTRY)/$(REPO):$(BUILD_TAG)
.PHONY: docker-login
docker-login: ## Log in into the repository
@echo "+ $@"
@docker login -u="${QUAY_USER}" -p="${QUAY_PASS}" $(DOCKER_REGISTRY)
.PHONY: docker-images
docker-images: ## List all local containers
@echo "+ $@"
@docker images
.PHONY: docker-push
docker-push: docker-login ## Push the container
@echo "+ $@"
@docker push $(DOCKER_REGISTRY)/$(REPO):$(LATEST_TAG)
@docker push $(DOCKER_REGISTRY)/$(REPO):$(VERSION_TAG)
@docker push $(DOCKER_REGISTRY)/$(REPO):$(BUILD_TAG)
.PHONY: bump-version
BUMP := patch
bump-version: ## Bump the version in the version file. Set BUMP to [ patch | major | minor ]
@go get -u github.com/jessfraz/junk/sembump # update sembump tool
$(shell command -v sembump)
$(eval NEW_VERSION=$(shell sembump --kind $(BUMP) $(VERSION)))
@echo "Bumping VERSION from $(VERSION) to $(NEW_VERSION)"
echo $(NEW_VERSION) > VERSION
@echo "Updating version from $(VERSION) to $(NEW_VERSION) in README.md"
sed -i s/$(VERSION)/$(NEW_VERSION)/g README.md
@echo "Updating version from $(VERSION) to $(NEW_VERSION) in kubernetes/ergaleia.yaml"
sed -i s/$(VERSION)/$(NEW_VERSION)/g kubernetes/ergaleia.yaml
git add VERSION README.md kubernetes/ergaleia.yaml
git commit -vsam "Bump version to $(NEW_VERSION)"
@echo "Run make tag to create and push the tag for new version $(NEW_VERSION)"
.PHONY: tag
tag: ## Create a new git tag to prepare to build a release
git tag -sa $(VERSION) -m "$(VERSION)"
@echo "Run git push origin $(VERSION) to push your new tag to GitHub and trigger a travis build."
.PHONY: help
help:
@grep -Eh '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: status
status: ## Shows git and dep status
@echo "Changed files:"
@git status --porcelain
@echo
@echo "Ignored but tracked files:"
@git ls-files -i --exclude-standard
@echo