forked from vmware-archive/dispatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
161 lines (119 loc) · 4.85 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
GIT_VERSION = $(shell git describe --tags --dirty)
VERSION ?= $(GIT_VERSION)
GO ?= go
GOVERSIONS ?= go1.9 go1.10 go1.11
OS := $(shell uname)
SHELL := /bin/bash
.DEFAULT_GOAL := help
GOPATH := $(firstword $(subst :, ,$(GOPATH)))
SWAGGER := $(GOPATH)/bin/swagger
GOBINDATA := $(GOPATH)/bin/go-bindata
VERSION_PACKAGE := github.com/vmware/dispatch/pkg/version
CLICMD_PACKAGE := github.com/vmware/dispatch/pkg/dispatchcli/cmd
GO_LDFLAGS := -X $(VERSION_PACKAGE).version=$(VERSION)
GO_LDFLAGS += -X $(VERSION_PACKAGE).buildDate=$(shell date +'%Y-%m-%dT%H:%M:%SZ')
GO_LDFLAGS += -X $(VERSION_PACKAGE).commit=$(shell git rev-parse HEAD)
PKGS := pkg
# ?= cannot be used for these variables as they should be evaulated only once per Makefile
ifeq ($(PREFIX),)
PREFIX := .
endif
TAG ?= $(VERSION)
B64_ARGS :=
ifeq ($(OS),Linux)
B64_ARGS += -w0
endif
CLI_LDFLAGS := -X $(CLICMD_PACKAGE).imagesB64=$(shell cat $(PREFIX)/images.yaml | gzip | base64 $(B64_ARGS))
.PHONY: all
all: generate linux darwin
.PHONY: goversion
goversion:
@echo Checking go version...
@(goversion=$$($(GO) version | cut -d' ' -f3 | cut -d'.' -f1,2); echo "$(GOVERSIONS)" | grep -q $$goversion || ( echo "Please install one of $(GOVERSIONS) (found: $$goversion)" && exit 2 ))
.PHONY: check
check: goversion checkfmt checklint swagger-validate ## check if the source files comply to the formatting rules
@echo running metalint ...
# (If errors involves swagger-generated files) consider running "make generate" and retry.)
gometalinter --disable=gotype --vendor --deadline 30s --fast --errors ./...
@echo running header check ...
scripts/header-check.sh
.PHONY: check-all
check-all: goversion checkfmt checklint swagger-validate ## check if the source files comply to the formatting rules
@echo running metalint ...
# (If errors involves swagger-generated files) consider running "make generate" and retry.)
gometalinter --disable=gotype --exclude gen --vendor --deadline 30s --aggregate --fast ./...
@echo running header check ...
scripts/header-check.sh
.PHONY: fmt
fmt: ## format go source code
gofmt -w $$(find . -name '*.go' -not -path './vendor/*' -not -path './gen/*')
.PHONY: difffmt
difffmt: ## diplay formatting changes that would be made by fix
gofmt -d $$(find . -name '*.go' -not -path './vendor/*' -not -path './gen/*')
.PHONY: fix-headers
fix-headers: ## fix copyright headers if they are missing
scripts/header-check.sh fix
.PHONY: checkfmt
checkfmt: ## check formatting of source files
scripts/gofmtcheck.sh
.PHONY: checklint
checklint: ## check lint of source files
scripts/golintcheck.sh
.PHONY: test
test: ## run tests
@echo running tests...
$(GO) test -v $(shell go list -v ./... | grep -v /vendor/ | grep -v integration )
.PHONY: swagger-validate
swagger-validate: ## validate the swagger spec
swagger validate ./swagger/*.yaml
.PHONY: run-dev
run-dev: ## run the dev server
@./scripts/run-dev.sh
CLI = dispatch
SERVICES = dispatch-server event-sidecar
DARWIN_BINS = $(foreach bin,$(SERVICES),$(bin)-darwin)
LINUX_BINS = $(foreach bin,$(SERVICES),$(bin)-linux)
.PHONY: darwin linux $(LINUX_BINS) $(DARWIN_BINS)
linux: $(LINUX_BINS) cli-linux
darwin: $(DARWIN_BINS) cli-darwin
$(LINUX_BINS):
GOOS=linux go build -ldflags "$(GO_LDFLAGS)" -o bin/$@ $(PREFIX)/cmd/$(subst -linux,,$@)
$(DARWIN_BINS):
GOOS=darwin go build -ldflags "$(GO_LDFLAGS)" -o bin/$@ $(PREFIX)/cmd/$(subst -darwin,,$@)
cli-darwin:
GOOS=darwin go build -ldflags "$(GO_LDFLAGS) $(CLI_LDFLAGS)" -o bin/$(CLI)-darwin $(PREFIX)/cmd/$(CLI)
cli-linux:
GOOS=linux go build -ldflags "$(GO_LDFLAGS) $(CLI_LDFLAGS)" -o bin/$(CLI)-linux $(PREFIX)/cmd/$(CLI)
.PHONY: images
images: linux ci-images
.PHONY: ci-values
ci-values:
TAG=$(TAG) $(PREFIX)/scripts/values.sh
.PHONY: ci-images $(SERVICES)
ci-images: ci-values $(SERVICES)
$(SERVICES):
TAG=$(TAG) $(PREFIX)/scripts/images.sh $@
.PHONY: generate
generate: ## run go generate
scripts/generate-models.sh swagger/models.json
scripts/generate.sh functions Functions functions.yaml
scripts/generate.sh images Images images.yaml
scripts/generate.sh baseimages BaseImages baseimages.yaml
scripts/generate.sh endpoints Endpoints endpoints.yaml
scripts/generate.sh secrets Secrets secrets.yaml
scripts/generate.sh event-manager EventManager event-manager.yaml
scripts/generate.sh identity-manager IdentityManager identity-manager.yaml
scripts/generate-resources.sh baseimage
scripts/header-check.sh fix
.PHONY: gen-clean
gen-clean: ## Clean all files created with make generate
rm -rf ./pkg/*/gen
.PHONY: distclean
distclean: ## Clean ALL files including ignored ones
git clean -f -d -x .
.PHONY: clean
clean: ## Clean all compiled files
rm -f $(foreach bin,$(DARWIN_BINS),bin/$(bin))
rm -f $(foreach bin,$(LINUX_BINS),bin/$(bin))
help: ## Display make help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'