This repository has been archived by the owner on Oct 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathstandard.mk
58 lines (49 loc) · 1.75 KB
/
standard.mk
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
# Validate variables in project.mk exist
ifndef IMAGE_REGISTRY
$(error IMAGE_REGISTRY is not set; check project.mk file)
endif
ifndef IMAGE_REPOSITORY
$(error IMAGE_REPOSITORY is not set; check project.mk file)
endif
ifndef IMAGE_NAME
$(error IMAGE_NAME is not set; check project.mk file)
endif
ifndef VERSION_MAJOR
$(error VERSION_MAJOR is not set; check project.mk file)
endif
ifndef VERSION_MINOR
$(error VERSION_MINOR is not set; check project.mk file)
endif
# Generate version and tag information from inputs
COMMIT_NUMBER=$(shell git rev-list `git rev-list --parents HEAD | egrep "^[a-f0-9]{40}$$"`..HEAD --count)
CURRENT_COMMIT=$(shell git rev-parse --short=8 HEAD)
VERSION=$(VERSION_MAJOR).$(VERSION_MINOR).$(COMMIT_NUMBER)-$(CURRENT_COMMIT)
IMG?=$(IMAGE_REGISTRY)/$(IMAGE_REPOSITORY)/$(IMAGE_NAME):v$(VERSION)
IMAGE_URI=${IMG}
IMAGE_URI_LATEST=$(IMAGE_REGISTRY)/$(IMAGE_REPOSITORY)/$(IMAGE_NAME):latest
DOCKERFILE ?=./Dockerfile
default: build
.PHONY: isclean
isclean:
@(test "$(ALLOW_DIRTY_CHECKOUT)" != "false" || test 0 -eq $$(git status --porcelain | wc -l)) || (echo "Local git checkout is not clean, commit changes and try again." && exit 1)
.PHONY: build
build: isclean envtest
docker build . -f $(DOCKERFILE) -t $(IMAGE_URI)
docker tag $(IMAGE_URI) $(IMAGE_URI_LATEST)
.PHONY: push
push:
docker push $(IMAGE_URI)
docker push $(IMAGE_URI_LATEST)
.PHONY: envtest
envtest:
@# test that the env target can be evaluated, required by osd-operators-registry
@eval $$($(MAKE) env --no-print-directory) || (echo 'Unable to evaluate output of `make env`. This breaks osd-operators-registry.' && exit 1)
.PHONY: test
test: envtest
.PHONY: env
.SILENT: env
env: isclean
echo NAME=$(NAME)
echo NAMESPACE=$(NAMESPACE)
echo VERSION=$(VERSION)
echo IMAGE_URI=$(IMAGE_URI)