forked from antrea-io/antrea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
175 lines (145 loc) · 4.77 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
# go options
GO ?= go
LDFLAGS :=
GOFLAGS :=
BINDIR := $(CURDIR)/bin
GO_FILES := $(shell find . -type d -name '.cache' -prune -o -type f -name '*.go' -print)
GOPATH ?= $$(go env GOPATH)
DOCKER_CACHE := $(CURDIR)/.cache
.PHONY: all
all: build
include versioning.mk
LDFLAGS += $(VERSION_LDFLAGS)
UNAME_S := $(shell uname -s)
.PHONY: bin test-unit test-integration
ifeq ($(UNAME_S),Linux)
bin: .linux-bin
test-unit: .linux-test-unit
test-integration: .linux-test-integration
else
bin:
$(error Cannot use target 'bin' on a non-Linux OS, but you can build Antrea with 'docker-bin')
test-unit:
$(error Cannot use target 'test-unit' on a non-Linux OS, but you can run unit tests with 'docker-test-unit')
test-integration:
$(error Cannot use target 'test-integration' on a non-Linux OS)
endif
.PHONY: build
build: build-ubuntu
.PHONY: test
test: build
test: test-unit
test: test-fmt
$(DOCKER_CACHE):
@mkdir -p $@/gopath
@mkdir -p $@/gocache
# Since the WORKDIR is mounted from host, the $(id -u):$(id -g) user can access it.
# Inside the docker, the user is nameless and does not have a home directory. This is ok for our use case.
DOCKER_ENV := \
@docker run --rm -u $$(id -u):$$(id -g) \
-e "GOCACHE=/tmp/gocache" \
-e "GOPATH=/tmp/gopath" \
-w /usr/src/github.com/vmware-tanzu/antrea \
-v $(DOCKER_CACHE)/gopath:/tmp/gopath \
-v $(DOCKER_CACHE)/gocache:/tmp/gocache \
-v $(CURDIR):/usr/src/github.com/vmware-tanzu/antrea \
golang:1.13
.PHONY: docker-bin
docker-bin: $(DOCKER_CACHE)
$(DOCKER_ENV) make bin
@chmod -R 0755 $<
.PHONY: docker-test-unit
docker-test-unit: $(DOCKER_CACHE)
@$(DOCKER_ENV) make test-unit
@chmod -R 0755 $<
.PHONY: docker-tidy
docker-tidy: $(DOCKER_CACHE)
@rm -f go.sum
@$(DOCKER_ENV) go mod tidy
@chmod -R 0755 $<
@chmod 0644 go.sum
.PHONY: .linux-bin
.linux-bin:
GOBIN=$(BINDIR) $(GO) install $(GOFLAGS) -ldflags '$(LDFLAGS)' github.com/vmware-tanzu/antrea/cmd/...
.PHONY: .linux-test-unit
.linux-test-unit:
@echo
@echo "==> Running unit tests <=="
$(GO) test -race -cover github.com/vmware-tanzu/antrea/pkg/...
.PHONY: tidy
tidy:
@rm -f go.sum
@$(GO) mod tidy
.PHONY: .linux-test-integration
.linux-test-integration:
@echo
@echo "==> Running integration tests <=="
@echo "SOME TESTS WILL FAIL IF NOT RUN AS ROOT!"
$(GO) test github.com/vmware-tanzu/antrea/test/integration/...
test-fmt:
@echo
@echo "===> Checking format of Go files <==="
@test -z "$$(gofmt -s -l -d $(GO_FILES) | tee /dev/stderr)"
test-tidy:
@echo
@echo "===> Checking go.mod tidiness <==="
@GO=$(GO) $(CURDIR)/hack/tidy-check.sh
.PHONY: fmt
fmt:
@echo
@echo "===> Formatting Go files <==="
@gofmt -s -l -w $(GO_FILES)
.PHONY: .linter
.linter:
@if ! PATH=$$PATH:$(GOPATH)/bin command -v golint > /dev/null; then \
echo "===> Installing Golint <==="; \
go get -u golang.org/x/lint/golint; \
fi
.PHONY: lint
lint: export GOOS=linux
lint: .linter
@PATH=$$PATH:$(GOPATH)/bin golint ./cmd/... ./pkg/...
.PHONY: clean
clean:
@rm -rf $(BINDIR)
@rm -rf $(DOCKER_CACHE)
@rm -f .mockgen .protoc
# Install a specific version of gomock to avoid generating different source code
# for the mocks every time a new version of gomock is released. If a new version
# of gomock is desired, this file should be updated.
.mockgen:
@echo "===> Installing Mockgen <==="
@go get github.com/golang/mock/[email protected]
@go install github.com/golang/mock/mockgen
@touch .mockgen
.PHONY: mocks
mocks: .mockgen
@echo "===> Re-generating mocks with Mockgen <==="
PATH=$$PATH:$(GOPATH)/bin $(GO) generate ./...
# Install a specific version of k8s.io/code-generator to
# generate monitoring CRDs client and deepcopy
.PHONY: crd-gen
crd-gen:
@echo "===> Re-generating CRD client and deepcopy with code-generator <==="
$(CURDIR)/hack/update-codegen.sh
### Docker images ###
.PHONY: ubuntu
ubuntu:
@echo "===> Building antrea/antrea-ubuntu Docker image <==="
docker build -t antrea/antrea-ubuntu -f build/images/Dockerfile.ubuntu .
docker tag antrea/antrea-ubuntu antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION)
# Build bins in a golang container, and build the antrea-ubuntu Docker image.
.PHONY: build-ubuntu
build-ubuntu:
@echo "===> Building Antrea bins and antrea/antrea-ubuntu Docker image <==="
docker build -t antrea/antrea-ubuntu -f build/images/Dockerfile.build.ubuntu .
docker tag antrea/antrea-ubuntu antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION)
.PHONY: manifest
manifest:
@echo "===> Generating dev manifest for Antrea <==="
$(CURDIR)/hack/generate-manifest.sh --mode dev > build/yamls/antrea.yml
.PHONY: octant-antrea-ubuntu
octant-antrea-ubuntu:
@echo "===> Building octant-antrea-ubuntu Docker image <==="
docker build -t octant-antrea-ubuntu -f build/images/Dockerfile.octant.ubuntu .
docker tag octant-antrea-ubuntu octant-antrea-ubuntu:$(DOCKER_IMG_VERSION)