This repository has been archived by the owner on Feb 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 106
/
Makefile
215 lines (178 loc) · 8.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
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
SHELL=/bin/bash
export GOPATH=$(shell pwd)
ROOT=$(shell pwd)
PACKAGE=github.com/ebay/akutan
# gorocksdb build settings
export CGO_LDFLAGS=-g -O2 -lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy -llz4 -lzstd
.PHONY: clean get test vet cover run dist protoc no_std_log bench fmt
all: get build test vet
clean:
rm -rf src/vendor
rm -rf bin
rm -rf pkg
rm -rf dist
find src/${PACKAGE} -name "*.pb.go" -delete
rm -f src/github.com/ebay/akutan/util/cmp/gen_cmp.go
# Set up git hooks. If you want to opt out of the hooks, set this config value
# to blank or some other directory.
hooks:
git config core.hooksPath >/dev/null || git config core.hooksPath githooks
get: get_clone get_install
get_clone:
mkdir -p src/vendor/github.com
go run src/github.com/ebay/akutan/tools/dep/*.go
get_install:
go install vendor/github.com/gogo/protobuf/protoc-gen-gogoslick
go install vendor/github.com/mauricelam/genny
go install vendor/github.com/mattn/goreman
go install vendor/golang.org/x/lint/golint
go install vendor/golang.org/x/tools/cmd/goimports
go install vendor/honnef.co/go/tools/cmd/staticcheck
# generate .go code for .proto input using the gogoslick plugin
# https://github.com/gogo/protobuf#more-speed-and-more-generated-code
# $1 = output directory
# $2 = input file directory (may or may not be the same as output directory)
# $3 = input file name (no directory)
define protoc_go
PATH=${ROOT}/bin:${PATH} protoc --gogoslick_out=plugins=grpc:$(strip $1) -Isrc:src/vendor:$(strip $2) $(strip $3)
( \
echo; \
echo '//lint:file-ignore ST1006 staticcheck disapproves of generated code'; \
echo '//lint:file-ignore ST1016 staticcheck disapproves of generated code'; \
) >> $(strip $1)/$(basename $(strip $3)).pb.go
endef
src/github.com/ebay/akutan/rpc/views.pb.go: src/github.com/ebay/akutan/rpc/views.proto src/github.com/ebay/akutan/tools/dep/deps.go
$(call protoc_go, src/github.com/ebay/akutan/rpc, src/github.com/ebay/akutan/rpc, views.proto)
src/github.com/ebay/akutan/logentry/commands.pb.go: src/github.com/ebay/akutan/logentry/commands.proto src/github.com/ebay/akutan/tools/dep/deps.go
$(call protoc_go, src/github.com/ebay/akutan/logentry, src/github.com/ebay/akutan/logentry, commands.proto)
src/github.com/ebay/akutan/diskview/meta.pb.go: src/github.com/ebay/akutan/diskview/meta.proto src/github.com/ebay/akutan/tools/dep/deps.go
$(call protoc_go, src/github.com/ebay/akutan/diskview, src/github.com/ebay/akutan/diskview, meta.proto)
src/github.com/ebay/akutan/api/akutan_api.pb.go: proto/api/akutan_api.proto src/github.com/ebay/akutan/tools/dep/deps.go
$(call protoc_go, src/github.com/ebay/akutan/api, proto/api, akutan_api.proto)
src/github.com/ebay/akutan/logspec/log.pb.go: proto/logspec/log.proto src/github.com/ebay/akutan/tools/dep/deps.go
$(call protoc_go, src/github.com/ebay/akutan/logspec, proto/logspec, log.proto)
src/github.com/ebay/akutan/tools/grpcbench/bench.pb.go: src/github.com/ebay/akutan/tools/grpcbench/bench.proto src/github.com/ebay/akutan/tools/dep/deps.go
$(call protoc_go, src/github.com/ebay/akutan/tools/grpcbench, src/github.com/ebay/akutan/tools/grpcbench, bench.proto)
generate: protoc
PATH=${PATH}:${ROOT}/bin go generate ${PACKAGE}/...
src/github.com/ebay/akutan/util/cmp/gen_cmp_test.go: src/github.com/ebay/akutan/util/cmp/cmp_test.template Makefile
cat src/github.com/ebay/akutan/util/cmp/cmp_test.template | bin/genny gen "Scalar=int64,uint64,int32,uint32,int,string" > src/github.com/ebay/akutan/util/cmp/gen_cmp_test.go
src/github.com/ebay/akutan/util/cmp/gen_cmp.go: src/github.com/ebay/akutan/util/cmp/cmp.template Makefile
cat src/github.com/ebay/akutan/util/cmp/cmp.template | bin/genny gen "Scalar=int64,uint64,int32,uint32,int,string" > src/github.com/ebay/akutan/util/cmp/gen_cmp.go
protoc: \
src/github.com/ebay/akutan/rpc/views.pb.go \
src/github.com/ebay/akutan/diskview/meta.pb.go \
src/github.com/ebay/akutan/api/akutan_api.pb.go \
src/github.com/ebay/akutan/logspec/log.pb.go \
src/github.com/ebay/akutan/tools/grpcbench/bench.pb.go \
src/github.com/ebay/akutan/logentry/commands.pb.go
build: generate src/github.com/ebay/akutan/util/cmp/gen_cmp.go src/github.com/ebay/akutan/util/cmp/gen_cmp_test.go
go install ${PACKAGE}/...
lint:
@FAIL=0; \
for pkg in $$(go list ${PACKAGE}/...); do \
if ! bin/golint --set_exit_status $$pkg; then \
FAIL=1; \
fi \
done; \
exit $$FAIL
staticcheck:
bin/staticcheck -checks all ${PACKAGE}/...
vet: generate no_std_log lint staticcheck fmtcheck
go vet ${PACKAGE}/...
no_std_log:
@go list -f "{{.ImportPath}} {{range .Imports}} {{.}} {{end}}" ${PACKAGE}/... | grep ' log ' \
| awk '{ if(err==0) {print "The following package(s) use the standard library log package, but should be using logrus instead";} print $$1; err=1 } END {exit err}'
test:
go test -timeout 30s ${PACKAGE}/...
cover:
go test -coverprofile=coverage.out -covermode=count ${PACKAGE}/...
go tool cover -html=coverage.out
bench:
go test -bench . ${PACKAGE}/...
# Reformats all the Go code. We used to use `go fmt` here, but goimports does
# all that and a little more.
fmt:
bin/goimports -w src/github.com/ebay/akutan
# Verifies that all the Go code is well-formatted, without changing any of it.
#
# The ! and grep are to get the right exit status: any output from goimports
# should fail this target.
fmtcheck:
@echo bin/goimports -d src/github.com/ebay/akutan
@! bin/goimports -d src/github.com/ebay/akutan | grep '.\?'
.PHONY: local/generated/Procfile
local/generated/Procfile:
bin/gen-local -cfg local/config.json -out local/generated
run: local/generated/Procfile
CLICOLOR_FORCE=1 bin/goreman -f local/generated/Procfile start
# uses dist/ as the docker context
# $1 = component name (Dockerfile must exist at docker/${1}/Dockerfile)
define docker_build
docker build --tag akutan-$(strip $1):latest --file docker/$(strip $1)/Dockerfile dist/
endef
docker-build-akutan-builder:
docker build --tag=akutan-builder:latest docker/build
docker-build-api: dist
$(call docker_build, api)
docker-build-diskview: dist
$(call docker_build, diskview)
docker-build-kafka: dist
$(call docker_build, kafka)
docker-build-txview: dist
$(call docker_build, txview)
# Run the latest builder image locally.
#
# The docker.sock volume enables docker in the container to interact with docker on
# the host.
#
# The pwd volume enables development of docker images by mounting the host source
# tree into /home/builder/akutan
docker-run-akutan-builder:
docker run --interactive --tty --rm \
--hostname akutan-builder \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume "${PWD}:/home/builder/akutan" \
akutan-builder:latest /bin/bash
# Create the Akutan builder docker image with the Docker daemon of Minukube. This
# builder image will then be used to build the core Akutan images.
docker-build-akutan-builder-in-minikube:
eval $$(minikube docker-env || echo "exit 1"); \
docker build --tag=akutan-builder:latest docker/build
# Build the core Akutan images using the Akutan builder image running within
# Minikube's Docker. These images will then be accessible from Minikube's
# Kubernetes.
#
# Note that these volume mounts are mounting volumes from Minikube's VirtualBox
# VM into the container. The reason ${PWD} is meaningful is because VirtualBox
# mounts /Users/ from the Mac host into the VM. Other directories, like
# /var/run, are local to the VM.
docker-build-akutan-service-in-minikube:
eval $$(minikube docker-env || echo "exit 1"); \
docker run --interactive --tty --rm \
--hostname akutan-builder \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume /home/docker/.docker:/home/builder/.docker \
--volume "${PWD}:/home/builder/akutan" \
--entrypoint /bin/bash \
akutan-builder:latest \
-c "cd /home/builder/akutan && make docker-build-{api,diskview,txview,kafka}"; \
docker tag akutan-api:latest akutan-api:local; \
docker tag akutan-diskview:latest akutan-diskview:local; \
docker tag akutan-txview:latest akutan-txview:local; \
docker tag akutan-kafka:latest akutan-kafka:local
dist: build
mkdir -p dist/docker
cp bin/* dist/
cp docker/kafka/{init.sh,*.properties} dist/docker
tar --exclude dist/akutan.tar.lz4 -c dist/ |lz4 -f - dist/akutan.tar.lz4
failed:
g++ --version
gcc --version
go version
protoc --version
find src -type d -name .git -print -exec git --git-dir={} log -n 1 --pretty=format:'%H %cD' \;
test -f /usr/local/lib/librocksdb.a && strings /usr/local/lib/librocksdb.a |grep -E 'rocksdb_build_git_(date|sha):'
ls -l /var/run/docker.sock
id
docker --version