-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
266 lines (212 loc) · 7.92 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# ___ ___ ___ ___
# /\ \ /\ \ /\ \ /\ \ _____
# \:\ \ /::\ \ /::\ \ /::\ \ /::\ \
# \:\ \ /:/\:\ \ /:/\:\ \ /:/\:\__\ /:/\:\ \
# ___ /::\ \ /:/ \:\ \ /:/ /::\ \ /:/ /:/ / /:/ \:\__\
# /\ /:/\:\__\ /:/__/ \:\__\ /:/_/:/\:\__\ /:/_/:/__/___ /:/__/ \:|__|
# \:\/:/ \/__/ \:\ \ /:/ / \:\/:/ \/__/ \:\/:::::/ / \:\ \ /:/ /
# \::/__/ \:\ /:/ / \::/__/ \::/~~/~~~~ \:\ /:/ /
# \:\ \ \:\/:/ / \:\ \ \:\~~\ \:\/:/ /
# \:\__\ \::/ / \:\__\ \:\__\ \::/ /
# \/__/ \/__/ \/__/ \/__/ \/__/
#
# Hoard Makefile
#
# Requires go version 1.8 or later.
#
# To compile gRPC service also requires protobuf 3 and the protobuf go plugin.
# See http://www.grpc.io/docs/quickstart/go.html to get started.
#
SHELL := bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
# Gets implicit default GOPATH if not set
GOPATH?=$(shell go env GOPATH)
BIN_PATH?=${GOPATH}/bin
NODE_BIN=$(shell yarn --cwd js bin)
SHELL := /bin/bash
REPO := $(shell pwd)
GOFILES := $(shell find . -name '*.pb.go' -prune -o -not -path './vendor/*' -type f -name '*.go' -print)
# Protobuf generated go files
PROTO_FILES = $(shell find . -path ./js -prune -o -path ./node_modules -prune -o -type f -name '*.proto' -print)
PROTO_GO_FILES = $(patsubst %.proto, %.pb.go, $(PROTO_FILES))
PROTO_GO_FILES_REAL = $(shell find . -type f -name '*.pb.go' -print)
PROTO_TS_FILES = $(patsubst %.proto, %.pb.ts, $(PROTO_FILES))
HOARD_TS_PATH = ./js
PROTO_GEN_TS_PATH = ${HOARD_TS_PATH}/proto
PROTOC_GEN_TS_PATH = ${HOARD_TS_PATH}/node_modules/.bin/protoc-gen-ts
PROTOC_GEN_GRPC_PATH= ${HOARD_TS_PATH}/node_modules/.bin/grpc_tools_node_protoc_plugin
GO_BUILD_ARGS = -ldflags "-extldflags '-static' -X $(shell go list)/project.commit=$(shell cat commit_hash.txt) -X $(shell go list)/project.date=$(shell date '+%Y-%m-%d')"
export REGRESSION_DIR=test/regression
export REGRESSION_SNAPSHOT=v8.2.3
export DOCKER_HUB := quay.io
export DOCKER_REPO := $(DOCKER_HUB)/monax/hoard
export BUILD_IMAGE := $(DOCKER_REPO):build
## Release and Versioning
VERSION := $(shell go run ./project/cmd/version/main.go)
## print version
.PHONY: version
version:
@echo $(VERSION)
# Formatting, linting and vetting
## check the code for style standards; currently enforces go formatting.
.PHONY: check
check:
@echo "Checking code for formatting style compliance."
@gofmt -l -d ${GOFILES}
@gofmt -l ${GOFILES} | read && echo && echo "Your marmot has found a problem with the formatting style of the code." 1>&2 && exit 1 || true
## just fix it
.PHONY: fix
fix:
@goimports -l -w ${GOFILES}
## lint installs golint and prints recommendations for coding style.
.PHONY: lint
lint:
@echo "Running lint checks."
@for file in $(GOFILES); do \
echo; \
golint --set_exit_status $${file}; \
done
# Building
## output commit_hash but only if we have the git repo (e.g. not in docker build)
.PHONY: commit_hash
commit_hash:
@git status &> /dev/null && scripts/commit_hash.sh > commit_hash.txt || true
# Protobuffing
## compile hoard.proto interface definition
%.pb.go: %.proto
@mkdir -p .gopath
protoc -I protobuf $< --gogo_out=plugins=grpc:.gopath
# We are using this plugin to match usage in other modules: https://github.com/agreatfool/grpc_tools_node_protoc_ts
%.pb.ts: %.proto
mkdir -p ${PROTO_GEN_TS_PATH}
$(NODE_BIN)/grpc_tools_node_protoc -I protobuf \
--plugin="protoc-gen-ts=$(NODE_BIN)/protoc-gen-ts" \
--js_out="import_style=commonjs,binary:${PROTO_GEN_TS_PATH}" \
--ts_out="grpc_js:${PROTO_GEN_TS_PATH}" \
--grpc_out="grpc_js:${PROTO_GEN_TS_PATH}" \
$<
.PHONY: protobuf
protobuf: ${PROTO_GO_FILES} ${PROTO_TS_FILES}
rsync -r .gopath/github.com/monax/hoard/v8/ ./
rm -rf .gopath
.PHONY: clean_protobuf
clean_protobuf:
rm -f $(PROTO_GO_FILES_REAL)
.PHONY: yarn_install
yarn_install:
cd ${HOARD_TS_PATH} && yarn install
## build the hoard binary
.PHONY: build_hoard
build_hoard: commit_hash
go build $(GO_BUILD_ARGS) -o bin/hoard ./cmd/hoard
## build the hoard binary
.PHONY: build_hoarctl
build_hoarctl: commit_hash
go build $(GO_BUILD_ARGS) -o bin/hoarctl ./cmd/hoarctl
.PHONY: install
install: build_hoarctl build_hoard
mkdir -p ${BIN_PATH}
install -T ${REPO}/bin/hoarctl ${BIN_PATH}/hoarctl
install -T ${REPO}/bin/hoard ${BIN_PATH}/hoard
## build all targets in github.com/monax/hoard
.PHONY: build
build: check build_hoard build_hoarctl
.PHONY: docker_build
docker_build: commit_hash
@scripts/build_tool.sh
## build binaries for all architectures
.PHONY: build_dist
build_dist:
@goreleaser --rm-dist --skip-publish --skip-validate
.PHONY: publish_js
publish_js:
yarn --cwd js install
yarn --cwd js build
yarn --cwd js publish --non-interactive --access public --no-git-tag-version --new-version $(shell ./scripts/local_version.sh)
# Testing
.PHONY: test
test: check
go test -v ./...
.PHONY: test_js
test_js: build install yarn_install
scripts/with_hoard.sh yarn --cwd js test
.PHONY: test_hoarctl
test_hoarctl: build install
scripts/with_hoard.sh test/hoarctl.sh
## run tests including integration tests
.PHONY: test_integration
test_integration: check
go test -v -tags integration ./...
scripts/integration/test_gcp.sh
# @scripts/integration/test_ipfs.sh ## needs work
# Run a regression test against the currently targeting regression snapshot
.PHONY: test_regression
test_regression:
scripts/test_regression.sh
# Create a new regression test snapshot using the current git version as a name
# (note: update REGRESSION_SNAPSHOT at top of Makefile if you want to start testing against this snapshot in the future)
.PHONY: regression_snapshot
regression_snapshot: export REGRESSION_SNAPSHOT=$(shell git describe --tags)
regression_snapshot:
scripts/test_regression.sh
# Clean Up
## clean removes the target folder containing build artefacts
.PHONY: clean
clean:
-rm -r ./bin
## generate full changelog of all release notes
CHANGELOG.md: project/history.go project/cmd/changelog/main.go
@go run ./project/cmd/changelog/main.go > CHANGELOG.md
## generated release note for this version
NOTES.md: project/history.go project/cmd/notes/main.go
@go run ./project/cmd/notes/main.go > NOTES.md
.PHONY: docs
docs: CHANGELOG.md NOTES.md
## tag the current HEAD commit with the current release defined in
## ./project/history.go and push to remote to trigger actual release
.PHONY: tag_release
tag_release: test check docs build
@scripts/tag_release.sh
## To be run by CI to effect actual release
.PHONY: release
release:
@scripts/is_checkout_dirty.sh || (echo "checkout is dirty so not releasing!" && exit 1)
@scripts/release.sh
.PHONY: build_ci_image
build_ci_image:
docker build -t ${BUILD_IMAGE} -f ./.circleci/Dockerfile .
.PHONY: push_ci_image
push_ci_image: build_ci_image
docker push ${BUILD_IMAGE}
HELM_PATH?=helm/package
HELM_PACKAGE=$(HELM_PATH)/hoard-$(VERSION).tgz
ARCH?=linux-amd64
# Note --set flag currently needs helm 3 version < 3.0.3 https://github.com/helm/helm/issues/3141 - but hopefully they will reintroduce support
bin/helm:
@echo Downloading helm...
mkdir -p bin
curl https://get.helm.sh/helm-v3.0.2-$(ARCH).tar.gz | tar xvzO $(ARCH)/helm > bin/helm && chmod +x bin/helm
.PHONY: helm_deps
helm_deps: bin/helm
@bin/helm repo add --username "$(CM_USERNAME)" --password "$(CM_PASSWORD)" chartmuseum $(CM_URL)
.PHONY: helm_test
helm_test: bin/helm
bin/helm dep up helm/hoard
bin/helm lint helm/hoard
helm_package: $(HELM_PACKAGE)
$(HELM_PACKAGE): helm_test bin/helm
bin/helm package helm/hoard \
--version "$(VERSION)" \
--app-version "$(VERSION)" \
--set "image.tag=$(VERSION)" \
--dependency-update \
--destination helm/package
.PHONY: helm_push
helm_push: helm_package
@echo pushing helm chart...
@curl -u ${CM_USERNAME}:${CM_PASSWORD} \
--data-binary "@$(HELM_PACKAGE)" $(CM_URL)/api/charts