forked from piraeusdatastore/piraeus-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
108 lines (95 loc) · 4.39 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
PROJECT ?= piraeus-operator
REGISTRY ?= piraeusdatastore
TAG ?= latest
NOCACHE ?= false
# Some operator-sdk versions struggle when these are not set, even if go
# is perfectly content with using sane defaults. So we just query go on
# what these defaults are
GOROOT ?= $(shell go env GOROOT)
GOPATH ?= $(shell go env GOPATH)
OPERATORSDK ?= operator-sdk
OPERATORSDKCMD := GOROOT=$(GOROOT) GOPATH=$(GOPATH) $(OPERATORSDK)
help:
@echo "Useful targets: 'update', 'upload'"
all: update upload
.PHONY: update
update:
docker build -t $(PROJECT):$(TAG) --no-cache=$(NOCACHE) -f build/Dockerfile .
docker tag $(PROJECT):$(TAG) $(PROJECT):latest
.PHONY: upload
upload:
for r in $(REGISTRY); do \
docker tag $(PROJECT):$(TAG) $$r/$(PROJECT):$(TAG) ; \
docker tag $(PROJECT):$(TAG) $$r/$(PROJECT):latest ; \
docker push $$r/$(PROJECT):$(TAG) ; \
docker push $$r/$(PROJECT):latest ; \
done
test:
go test ./...
deep-copy:
$(OPERATORSDKCMD) generate k8s
crds:
$(OPERATORSDKCMD) generate crds
mv ./deploy/crds/* ./charts/piraeus/crds
helm-values:
cp ./charts/piraeus/values.yaml ./charts/piraeus/values.cn.yaml
sed 's|gcr.io/etcd-development/etcd|daocloud.io/piraeus/etcd|' -i ./charts/piraeus/values.cn.yaml
sed 's|docker.io/openstorage/stork|daocloud.io/piraeus/stork|' -i ./charts/piraeus/values.cn.yaml
sed 's|k8s.gcr.io/kube-scheduler-amd64|daocloud.io/piraeus/kube-scheduler-amd64|' -i ./charts/piraeus/values.cn.yaml
sed 's|quay.io/piraeusdatastore|daocloud.io/piraeus|' -i ./charts/piraeus/values.cn.yaml
sed 's|k8s.gcr.io/sig-storage|daocloud.io/piraeus|' -i ./charts/piraeus/values.cn.yaml
sed 's|quay.io/k8scsi|daocloud.io/piraeus|' -i ./charts/piraeus/values.cn.yaml
release:
# check that VERSION is set
@if [ -z "$(VERSION)" ]; then \
echo "Usage: make prepare-release VERSION=<version>" >&2 ; \
exit 1 ; \
fi
# check that version has expected format
# regex taken from https://semver.org/
@if ! echo -e "$(VERSION)" | grep -qP '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$$' ; then \
echo "version format: <maj>.<min>.<patch>" >&2 ; \
exit 1 ; \
fi
# check that version does not exist
@if git rev-parse "v$(VERSION)" >/dev/null 2>&1 ; then \
echo "version v$(VERSION) already exists" >&2 ; \
exit 1 ; \
fi
# check that working tree is clean
@if ! git diff-index --quiet HEAD -- ; then \
echo "Refusing to create release from dirty repository" >&2 ; \
exit 1; \
fi
# replace changelog header "Unreleased" with version and replace link target
sed 's/^## \[Unreleased\]/## [v$(VERSION)] - $(shell date +%Y-%m-%d)/' -i CHANGELOG.md
sed 's#^\[Unreleased\]: \(.*\)HEAD$$#[v$(VERSION)]: \1v$(VERSION)#' -i CHANGELOG.md
# replace go operator version
sed 's/var Version = ".*"/var Version = "$(VERSION)"/' -i version/version.go
# replace chart version+appVersion
yq w -i charts/piraeus/Chart.yaml version $(VERSION)
yq w -i charts/piraeus/Chart.yaml appVersion $(VERSION)
# set operator image to tagged version
yq w -i charts/piraeus/values.yaml operator.image "quay.io/piraeusdatastore/piraeus-operator:v$(VERSION)"
yq w -i charts/piraeus/values.cn.yaml operator.image "daocloud.io/piraeus/piraeus-operator:v$(VERSION)"
# update full yaml deployment
$(MAKE) deploy/piraeus
git add --update
# commit as current release + tag
git commit -aevm "Release v$(VERSION)" --signoff
# We don't do git tag v$(VERSION) here, as the commit will change once its merged in github
# add "Unreleased" section at top + create comparison link against current master
sed 's/^## \[v$(VERSION)\]/## [Unreleased]\n\n## [v$(VERSION)]/' -i CHANGELOG.md
echo "[Unreleased]: https://github.com/piraeusdatastore/piraeus-operator/compare/v$(VERSION)...HEAD" >> CHANGELOG.md
# set operator image back to :latest during development
yq w -i charts/piraeus/values.yaml operator.image "quay.io/piraeusdatastore/piraeus-operator:latest"
yq w -i charts/piraeus/values.cn.yaml operator.image "daocloud.io/piraeus/piraeus-operator:latest"
# reset full yaml deployment
$(MAKE) deploy/piraeus
# commit begin of new dev cycle
git commit -aevm "Prepare next dev cycle" --signoff
.PHONY: deploy/piraeus
deploy/piraeus:
rm -rf "$@"
mkdir -p "$@"
helm template -n default piraeus-op charts/piraeus --set stork.schedulerTag=v1.18.0 --set operator.controller.masterPassphrase=changemeplease --output-dir deploy >/dev/null