This repository has been archived by the owner on May 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 154
/
Makefile
145 lines (111 loc) · 4.98 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
# Copyright (c) 2018 Uber Technologies, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
PWD := ${CURDIR}
PACKAGE_NAME = github.com/uber/makisu
PACKAGE_VERSION ?= $(shell git describe --always --tags)
OS = $(shell uname)
ALL_SRC = $(shell find . -name "*.go" | grep -v -e vendor \
-e ".*/\..*" \
-e ".*/_.*" \
-e ".*/mocks.*" \
-e ".*/*.pb.go")
ALL_PKGS = $(shell go list $(sort $(dir $(ALL_SRC))) | grep -v vendor)
ALL_PKG_PATHS = $(shell go list -f '{{.Dir}}' ./...)
FMT_SRC = $(shell echo "$(ALL_SRC)" | tr ' ' '\n')
EXT_TOOLS = github.com/axw/gocov/gocov github.com/AlekSi/gocov-xml github.com/matm/gocov-html github.com/golang/mock/mockgen golang.org/x/lint/golint golang.org/x/tools/cmd/goimports github.com/client9/misspell/cmd/misspell
EXT_TOOLS_DIR = ext-tools/$(OS)
BUILD_LDFLAGS = -X $(PACKAGE_NAME)/lib/utils.BuildHash=$(PACKAGE_VERSION)
GO_FLAGS = -gcflags '-N -l' -ldflags "$(BUILD_LDFLAGS)"
GO_VERSION = 1.14
REGISTRY ?= gcr.io/uber-container-tools
### Targets to compile the makisu binaries.
.PHONY: bins lbins cbins
bins: bin/makisu/makisu
bin/makisu/makisu: $(ALL_SRC) vendor
go build -tags bins $(GO_FLAGS) -o $@ bin/makisu/*.go
lbins: bin/makisu/makisu.linux
bin/makisu/makisu.linux: $(ALL_SRC) vendor
CGO_ENABLED=0 GOOS=linux go build -tags bins $(GO_FLAGS) -o $@ bin/makisu/*.go
cbins:
docker run -i --rm -v $(PWD):/workspace/$(PACKAGE_NAME) \
--net=host \
--entrypoint=bash \
-w /workspace/$(PACKAGE_NAME) \
golang:$(GO_VERSION) \
-c "make lbins"
$(ALL_SRC): ;
# TODO(pourchet): Remove this hack to make dep more reliable. For some reason `go mod download`
# fails sometimes on TravisCI, so run it a few times if it fails.
vendor: go.mod go.sum
go mod download || go mod download || go mod download
go mod vendor
ext-tools: vendor $(EXT_TOOLS)
.PHONY: $(EXT_TOOLS)
$(EXT_TOOLS): vendor
@echo "Installing external tool $@"
@(ls $(EXT_TOOLS_DIR)/$(notdir $@) > /dev/null 2>&1) || GOBIN=$(PWD)/$(EXT_TOOLS_DIR) go install ./vendor/$@
mocks: ext-tools
@echo "Generating mocks"
mkdir -p mocks/net/http
$(EXT_TOOLS_DIR)/mockgen -destination=mocks/net/http/mockhttp.go -package=mockhttp net/http RoundTripper
mkdir -p mocks/lib/registry
$(EXT_TOOLS_DIR)/mockgen -destination=mocks/lib/registry/mockclient.go -package=mockregistry github.com/uber/makisu/lib/registry Client
env: test/python/requirements.txt
[ -d env ] || virtualenv env
./env/bin/pip install -q -r test/python/requirements.txt
### Target to build the makisu docker images.
.PHONY: images publish
images:
docker build --build-arg GO_VERSION="$(GO_VERSION)" -t $(REGISTRY)/makisu:$(PACKAGE_VERSION) -f Dockerfile .
docker tag $(REGISTRY)/makisu:$(PACKAGE_VERSION) makisu:$(PACKAGE_VERSION)
docker tag $(REGISTRY)/makisu:$(PACKAGE_VERSION) makisu:latest
docker build --build-arg GO_VERSION="$(GO_VERSION)" -t $(REGISTRY)/makisu-alpine:$(PACKAGE_VERSION) -f Dockerfile.alpine .
docker tag $(REGISTRY)/makisu-alpine:$(PACKAGE_VERSION) makisu-alpine:$(PACKAGE_VERSION)
docker tag $(REGISTRY)/makisu-alpine:$(PACKAGE_VERSION) makisu-alpine:latest
publish: images
docker push $(REGISTRY)/makisu:$(PACKAGE_VERSION)
docker push $(REGISTRY)/makisu-alpine:$(PACKAGE_VERSION)
### Targets to test the codebase.
.PHONY: test unit-test integration cunit-test
test: unit-test integration
unit-test: $(ALL_SRC) vendor ext-tools
$(EXT_TOOLS_DIR)/gocov test $(ALL_PKGS) --tags "unit" | $(EXT_TOOLS_DIR)/gocov report
cunit-test: $(ALL_SRC)
docker run -i --rm -v $(PWD):/workspace/$(PACKAGE_NAME) \
--net=host \
--entrypoint=bash \
-w /workspace/$(PACKAGE_NAME) \
golang:$(GO_VERSION) \
-c "make ext-tools unit-test"
integration: env images
PACKAGE_VERSION=$(PACKAGE_VERSION) ./env/bin/py.test --maxfail=1 --durations=6 --timeout=300 -vv test/python
### Misc targets
.PHONY: clean integration-single
integration-single: env images
PACKAGE_VERSION=$(PACKAGE_VERSION) ./env/bin/py.test test/python/test_build.py::$(TEST_NAME)
# TODO(pourchet) fix gometalinter installation from source
lint: ext-tools
@echo "Running ineffassign, gofmt, misspell, gometalinter, gocyclo"
@ineffassign <<< $(ALL_PKG_PATHS)
@gofmt -l -s $(ALL_PKG_PATHS) | read; if [ $$? == 0 ]; then echo "gofmt check failed for:"; gofmt -l -s $(ALL_PKG_PATHS); exit 1; fi
@$(EXT_TOOLS_DIR)/misspell -w --error -i hardlinked $(ALL_PKG_PATHS)
gometalinter --vendor --disable vet -e 'warning' --fast ./...
@xargs -I@ gocyclo --over 15 @ <<< $(ALL_PKG_PATHS)
clean:
git clean -fd
-rm -rf vendor ext-tools env
-rm bin/makisu/makisu
.PHONY: docs
docs:
@./scripts/mkdocs.sh -q serve