-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Makefile
127 lines (105 loc) · 3.59 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
GOOS ?=
GOARCH ?=
GO111MODULE ?= on
CGO_ENABLED ?= 0
CGO_CFLAGS ?=
CGO_LDFLAGS ?=
BUILD_TAGS ?=
TAG ?=
BIN_EXT ?=
DOCKER_REPOSITORY ?= mosuka
PACKAGES = $(shell $(GO) list -tags="$(BUILD_TAGS)" ./... | grep -v '/vendor/')
PROTOBUFS = $(shell find . -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq | grep -v /vendor/)
TARGET_PACKAGES = $(shell find $(CURDIR) -name 'main.go' -print0 | xargs -0 -n1 dirname | sort | uniq | grep -v /vendor/)
ifeq ($(GOOS),)
GOOS = $(shell go version | awk -F ' ' '{print $$NF}' | awk -F '/' '{print $$1}')
endif
ifeq ($(GOARCH),)
GOARCH = $(shell go version | awk -F ' ' '{print $$NF}' | awk -F '/' '{print $$2}')
endif
ifeq ($(TAG),)
TAG = latest
endif
LDFLAGS = -ldflags "-s -w -X \"github.com/mosuka/phalanx/version.Version=$(TAG)\""
ifeq ($(GOOS),windows)
BIN_EXT = .exe
endif
BUILD_FLAGS := GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) CGO_CFLAGS=$(CGO_CFLAGS) CGO_LDFLAGS=$(CGO_LDFLAGS) GO111MODULE=$(GO111MODULE)
GO := $(BUILD_FLAGS) go
.DEFAULT_GOAL := build
.PHONY: show-env
show-env:
@echo ">> show env"
@echo " GOOS = $(GOOS)"
@echo " GOARCH = $(GOARCH)"
@echo " GO111MODULE = $(GO111MODULE)"
@echo " CGO_ENABLED = $(CGO_ENABLED)"
@echo " CGO_CFLAGS = $(CGO_CFLAGS)"
@echo " CGO_LDFLAGS = $(CGO_LDFLAGS)"
@echo " BUILD_TAGS = $(BUILD_TAGS)"
@echo " TAG = $(TAG)"
@echo " BIN_EXT = $(BIN_EXT)"
@echo " LDFLAGS = $(LDFLAGS)"
@echo " PACKAGES = $(PACKAGES)"
@echo " PROTOBUFS = $(PROTOBUFS)"
@echo " TARGET_PACKAGES = $(TARGET_PACKAGES)"
.PHONY: protoc
protoc: show-env
@echo ">> generating proto3 code"
for proto_dir in $(PROTOBUFS); do echo $$proto_dir; protoc --proto_path=. --proto_path=$$proto_dir --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative $$proto_dir/*.proto || exit 1; done
.PHONY: fmt
fmt: show-env
@echo ">> formatting code"
$(GO) fmt $(PACKAGES)
.PHONY: mock
mock:
@echo ">> generating mocks"
mockgen -source=./metastore/storage.go -destination=./mock/metastore/storage.go
.PHONY: test
test: show-env
@echo ">> testing all packages"
$(GO) clean -testcache
$(GO) test -v -tags="$(BUILD_TAGS)" $(PACKAGES)
.PHONY: clean
clean:
@echo ">> cleaning repository"
$(GO) clean
.PHONY: build
build: show-env
@echo ">> building binaries"
$(GO) build -tags="$(BUILD_TAGS)" $(LDFLAGS) -o bin/phalanx
cp ./scripts/phalanx_docs.sh ./bin/phalanx_docs.sh
.PHONY: docs
docs:
@echo ">> building document"
gitbook install ./docs_md
gitbook build ./docs_md
cp ./docs_md/README.md ./README.md
rm -rf docs
mv ./docs_md/_book docs
.PHONY: tag
tag: show-env
@echo ">> tagging github"
ifeq ($(TAG),$(filter $(TAG),latest master ""))
@echo "please specify TAG"
else
git tag -a $(TAG) -m "Release $(TAG)"
git push origin $(TAG)
endif
.PHONY: docker-build
docker-build: show-env
@echo ">> building docker container image"
docker build -t $(DOCKER_REPOSITORY)/phalanx:latest --build-arg TAG=$(TAG) .
docker tag $(DOCKER_REPOSITORY)/phalanx:latest $(DOCKER_REPOSITORY)/phalanx:$(TAG)
.PHONY: docker-push
docker-push: show-env
@echo ">> pushing docker container image"
docker push $(DOCKER_REPOSITORY)/phalanx:latest
docker push $(DOCKER_REPOSITORY)/phalanx:$(TAG)
.PHONY: docker-clean
docker-clean:
docker rmi -f $(shell docker images --filter "dangling=true" -q --no-trunc)
.PHONY: cert
cert:
@echo ">> generating certification"
openssl req -x509 -nodes -newkey rsa:4096 -keyout ./examples/phalanx-key.pem -out ./examples/phalanx-cert.pem -days 365 -subj '/CN=localhost'