-
Notifications
You must be signed in to change notification settings - Fork 42
/
Makefile
104 lines (84 loc) · 3.64 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
.ONESHELL:
SHA := $(shell git rev-parse --short=8 HEAD)
GITVERSION := $(shell git describe --long --all)
BUILDDATE := $(shell date -Iseconds)
VERSION := $(or ${VERSION},devel)
CGO_ENABLED := $(or ${CGO_ENABLED},0)
GO := go
GO111MODULE := on
LINKMODE := -extldflags '-static -s -w'
.EXPORT_ALL_VARIABLES:
all: proto server client test fuzz bench
ci: proto test
.PHONY: bench
bench:
CGO_ENABLED=1 $(GO) test -bench ./... -run=- -benchmem -timeout 20m
.PHONY: benchstat
benchstat:
git stash
CGO_ENABLED=1 $(GO) test -bench . -run=- -count 5 -benchmem > old.txt
git stash pop
CGO_ENABLED=1 $(GO) test -bench . -run=- -count 5 -benchmem > new.txt
benchstat old.txt new.txt
.PHONY: test
test:
CGO_ENABLED=1 $(GO) test ./... -coverprofile=coverage.out -covermode=atomic && go tool cover -func=coverage.out
.PHONY: fuzz
fuzz:
CGO_ENABLED=1 $(GO) test -fuzz=Fuzz -fuzztime 30s -v -run ^Fuzz github.com/metal-stack/go-ipam
.PHONY: golangcicheck
golangcicheck:
@bash -c "type -P golangci-lint;" 2>/dev/null || (echo "golangci-lint is required but not available in current PATH. Install: https://github.com/golangci/golangci-lint#install"; exit 1)
.PHONY: lint
lint: golangcicheck
golangci-lint run -p bugs -p unused
.PHONY: proto
proto:
$(MAKE) -C proto protoc
.PHONY: server
server:
go build -tags netgo,osusergo,urfave_cli_no_docs \
-ldflags "$(LINKMODE) -X 'github.com/metal-stack/v.Version=$(VERSION)' \
-X 'github.com/metal-stack/v.Revision=$(GITVERSION)' \
-X 'github.com/metal-stack/v.GitSHA1=$(SHA)' \
-X 'github.com/metal-stack/v.BuildDate=$(BUILDDATE)'" \
-o bin/server github.com/metal-stack/go-ipam/cmd/server
strip bin/server
.PHONY: client
client:
go build -tags netgo,osusergo,urfave_cli_no_docs \
-ldflags "$(LINKMODE) -X 'github.com/metal-stack/v.Version=$(VERSION)' \
-X 'github.com/metal-stack/v.Revision=$(GITVERSION)' \
-X 'github.com/metal-stack/v.GitSHA1=$(SHA)' \
-X 'github.com/metal-stack/v.BuildDate=$(BUILDDATE)'" \
-o bin/cli github.com/metal-stack/go-ipam/cmd/client
strip bin/cli
.PHONY: postgres-up
postgres-up: postgres-rm
docker run -d --name ipamdb -p 5433:5432 -e POSTGRES_PASSWORD="password" postgres:$(PG_VERSION) -c 'max_connections=200'
.PHONY: postgres-rm
postgres-rm:
docker rm -f ipamdb || true
.PHONY: cockroach-up
cockroach-up: cockroach-rm postgres-rm
# https://www.cockroachlabs.com/docs/v19.2/start-a-local-cluster-in-docker-linux.html#main-content
docker network create -d bridge roachnet
docker run -d --name=roach1 --hostname=roach1 --net=roachnet -p 5433:26257 -p 8080:8080 cockroachdb/cockroach:$(COCKROACH_VERSION) start-single-node --insecure --listen-addr=0.0.0.0
.PHONY: cockroach-up-cluster
cockroach-up-cluster: cockroach-rm
# https://www.cockroachlabs.com/docs/v19.2/start-a-local-cluster-in-docker-linux.html#main-content
docker network create -d bridge roachnet
docker run -d --name=roach1 --hostname=roach1 --net=roachnet -p 5433:26257 -p 8080:8080 cockroachdb/cockroach:$(COCKROACH_VERSION) start --insecure --join=roach1,roach2,roach3
docker run -d --name=roach2 --hostname=roach2 --net=roachnet cockroachdb/cockroach:$(COCKROACH_VERSION) start --insecure --join=roach1,roach2,roach3
docker run -d --name=roach3 --hostname=roach3 --net=roachnet cockroachdb/cockroach:$(COCKROACH_VERSION) start --insecure --join=roach1,roach2,roach3
docker exec -it roach1 ./cockroach init --insecure
.PHONY: cockroach-rm
cockroach-rm:
docker rm -f roach1 roach2 roach3 || true
docker network rm roachnet || true
.PHONY: redis-up
redis-up: redis-rm
docker run -d --name ipamredis -p 6379:6379 redis
.PHONY: redis-rm
redis-rm:
docker rm -f ipamredis || true