-
Notifications
You must be signed in to change notification settings - Fork 55
/
Makefile
259 lines (203 loc) · 8.26 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# Rule of thumb (to prevent huge containers):
# A single torpedo container should contain only one test binary.
#
# make {build|container}:
# create basic.test binary/container (<repo>/torpedo:<tag>)
#
# make {build-pds|container-pds}:
# create pds.test binary/container (<repo>/torpedo-pds:<tag>)
#
# make {build-backup|container-backup}:
# create backup.test binary/container (<repo>/torpedo-backup:<tag>)
#
# make {build-longevity|container-longevity}:
# create longevity.test binary/container (<repo>/torpedo-longevity:<tag>)
#
# make all:
# verify that all test binaries build successfully
#
# Note that DOCKER_HUB_TORPEDO_IMAGE environment variable is not used since
# it is set automatically depending on which binary is being built.
#
.PHONY: vendor
export GO111MODULE=on
export GOFLAGS = -mod=vendor
HAS_GOMODULES := $(shell go help mod why 2> /dev/null)
ifndef HAS_GOMODULES
$(error torpedo can only be built with go 1.11+ which supports go modules)
endif
ifndef TAGS
TAGS := daemon
endif
ifndef PKGS
# shell does not honor export command above, so we need to explicitly pass GOFLAGS here
PKGS := $(shell GOFLAGS=-mod=vendor go list ./... 2>&1 | grep -v 'github.com/portworx/torpedo/tests')
PKGIN := $(shell GOFLAGS=-mod=vendor go list ./... 2>&1 | grep -v 'github.com/portworx/torpedo/apiServer/taas')
endif
ifeq ($(BUILD_TYPE),debug)
BUILDFLAGS := -gcflags "-N -l"
endif
ifndef DOCKER_HUB_REPO
DOCKER_HUB_REPO := $(shell id -un)px
$(warning DOCKER_HUB_REPO not defined, using '$(DOCKER_HUB_REPO)' instead)
endif
ifndef DOCKER_HUB_TAG
DOCKER_HUB_TAG := latest
$(warning DOCKER_HUB_TAG not defined, using '$(DOCKER_HUB_TAG)' instead)
endif
BASE_DIR := $(shell git rev-parse --show-toplevel)
BIN :=$(BASE_DIR)/bin
GOFMT := gofmt
.DEFAULT_GOAL=all
SIDECAR_WP_CLI_DOCKER_TAG=1.2.28
SIDECAR_WP_CLI_IMG=$(DOCKER_HUB_REPO)/wp-cli:$(SIDECAR_WP_CLI_DOCKER_TAG)
SIDECAR_DIR=drivers/scheduler/sidecars
SYSBENCH_IMG=$(DOCKER_HUB_REPO)/torpedo-sysbench:latest
PGBENCH_IMG=$(DOCKER_HUB_REPO)/torpedo-pgbench:latest
ESLOAD_IMG=$(DOCKER_HUB_REPO)/torpedo-esload:latest
all: vet build build-pds build-backup build-taas build-longevity fmt
deps:
go get -d -v $(PKGS)
update-deps:
go get -d -v -u -f $(PKGS)
test-deps:
go get -d -v -t $(PKGS)
update-test-deps:
go get -tags "$(TAGS)" -d -v -t -u -f $(PKGS)
fmt:
@echo -e "Performing gofmt on following: $(PKGS)"
@./scripts/do-gofmt.sh $(PKGS)
# Tools
$(GOPATH)/bin/ginkgo:
GOFLAGS= GO111MODULE=on go install -mod=mod github.com/onsi/ginkgo/v2/[email protected]
# this target builds the basic.test binary only. Use build-pds for pds.test binary.
build: GINKGO_BUILD_DIR=./tests/basic
build: $(GOPATH)/bin/ginkgo
mkdir -p $(BIN)
go build -tags "$(TAGS)" $(BUILDFLAGS) $(PKGS)
ginkgo build -r $(GINKGO_BUILD_DIR)
find $(GINKGO_BUILD_DIR) -name '*.test' | awk '{cmd="cp "$$1" $(BIN)"; system(cmd)}'
chmod -R 755 bin/*
# this target builds the pds.test binary only.
build-pds: GINKGO_BUILD_DIR=./tests/pds
build-pds: $(GOPATH)/bin/ginkgo
mkdir -p $(BIN)
go build -tags "$(TAGS)" $(BUILDFLAGS) $(PKGS)
ginkgo build -r $(GINKGO_BUILD_DIR)
find $(GINKGO_BUILD_DIR) -name '*.test' | awk '{cmd="cp "$$1" $(BIN)"; system(cmd)}'
chmod -R 755 bin/*
# this target builds the backup.test binary only.
build-backup: GINKGO_BUILD_DIR=./tests/backup
build-backup: $(GOPATH)/bin/ginkgo
mkdir -p $(BIN)
go build -tags "$(TAGS)" $(BUILDFLAGS) $(PKGS)
ginkgo build -r $(GINKGO_BUILD_DIR)
find $(GINKGO_BUILD_DIR) -name '*.test' | awk '{cmd="cp "$$1" $(BIN)"; system(cmd)}'
chmod -R 755 bin/*
build-longevity: GINKGO_BUILD_DIR=./tests/longevity
build-longevity: $(GOPATH)/bin/ginkgo
mkdir -p $(BIN)
go build -tags "$(TAGS)" $(BUILDFLAGS) $(PKGS)
ginkgo build -r $(GINKGO_BUILD_DIR)
find $(GINKGO_BUILD_DIR) -name '*.test' | awk '{cmd="cp "$$1" $(BIN)"; system(cmd)}'
chmod -R 755 bin/*
# this target builds the taas binary only.
build-taas: TAAS_BUILD_DIR=./apiServer/taas
build-taas:
mkdir -p $(BIN)
go build -tags "$(TAGS)" $(BUILDFLAGS) $(PKGIN)
go build $(TAAS_BUILD_DIR)
find . -name 'taas' | awk '{cmd="cp "$$1" $(BIN)"; system(cmd)}'
chmod -R 755 bin/*
vendor-update:
go mod download
vendor-tidy:
go mod tidy
vendor:
go mod vendor
sed -i '1 i\// +build skipcompile\n' vendor/kubevirt.io/client-go/kubecli/kubevirt_test_utils.go
install:
go install -tags "$(TAGS)" $(PKGS)
lint:
(mkdir -p tools && GO111MODULE=off go get -v golang.org/x/lint/golint)
for file in $$(find . -name '*.go' | grep -v vendor | grep -v '\.pb\.go' | grep -v '\.pb\.gw\.go'); do \
golint $${file}; \
if [ -n "$$(golint $${file})" ]; then \
exit 1; \
fi; \
done
vet:
go vet $(PKGS)
errcheck:
(mkdir -p tools && GO111MODULE=off && go get -v github.com/kisielk/errcheck)
errcheck -tags "$(TAGS)" $(PKGS)
pretest: vet errcheck
test:
go test -tags "$(TAGS)" $(TESTFLAGS) $(PKGS)
# this target builds a container with test.basic binary only. Repo is hardcoded to ".../torpedo".
container: TORPEDO_IMG=$(DOCKER_HUB_REPO)/torpedo:$(DOCKER_HUB_TAG)
container:
@echo "Building basic.test container "$(TORPEDO_IMG)
sudo DOCKER_BUILDKIT=1 docker build --tag $(TORPEDO_IMG) --build-arg MAKE_TARGET=build -f Dockerfile .
# this target builds a container with pds.test binary only. Repo is hardcoded to ".../torpedo-pds".
container-pds: TORPEDO_IMG=$(DOCKER_HUB_REPO)/torpedo-pds:$(DOCKER_HUB_TAG)
container-pds:
@echo "Building pds.test container "$(TORPEDO_IMG)
sudo DOCKER_BUILDKIT=1 docker build --tag $(TORPEDO_IMG) --build-arg MAKE_TARGET=build-pds -f Dockerfile .
# this target builds a container with backup.test binary only. Repo is hardcoded to ".../torpedo-backup".
container-backup: TORPEDO_IMG=$(DOCKER_HUB_REPO)/torpedo-backup:$(DOCKER_HUB_TAG)
container-backup:
@echo "Building backup.test container "$(TORPEDO_IMG)
sudo DOCKER_BUILDKIT=1 docker build --tag $(TORPEDO_IMG) --build-arg MAKE_TARGET=build-backup -f Dockerfile .
# this target builds a container with torpedo apiserver binary only. Repo is hardcoded to ".../taas".
container-taas: TORPEDO_IMG=$(DOCKER_HUB_REPO)/taas:$(DOCKER_HUB_TAG)
container-taas:
@echo "Building taas container "$(TORPEDO_IMG)
sudo DOCKER_BUILDKIT=1 docker build --tag $(TORPEDO_IMG) --build-arg MAKE_TARGET=build-taas -f Dockerfile-taas .
# this target builds a container with torpedo longevity binary only. Repo is hardcoded to ".../longevity".
container-longevity: TORPEDO_IMG=$(DOCKER_HUB_REPO)/torpedo-longevity:$(DOCKER_HUB_TAG)
container-longevity:
@echo "Building longevity container "$(TORPEDO_IMG)
sudo DOCKER_BUILDKIT=1 docker build --tag $(TORPEDO_IMG) --build-arg MAKE_TARGET=build-longevity -f Dockerfile .
deploy: TORPEDO_IMG=$(DOCKER_HUB_REPO)/torpedo:$(DOCKER_HUB_TAG)
deploy: container
sudo docker push $(TORPEDO_IMG)
deploy-pds: TORPEDO_IMG=$(DOCKER_HUB_REPO)/torpedo-pds:$(DOCKER_HUB_TAG)
deploy-pds: container-pds
sudo docker push $(TORPEDO_IMG)
deploy-backup: TORPEDO_IMG=$(DOCKER_HUB_REPO)/torpedo-backup:$(DOCKER_HUB_TAG)
deploy-backup: container-backup
sudo docker push $(TORPEDO_IMG)
deploy-taas: TORPEDO_IMG=$(DOCKER_HUB_REPO)/taas:$(DOCKER_HUB_TAG)
deploy-taas: container-taas
sudo docker push $(TORPEDO_IMG)
deploy-longevity: TORPEDO_IMG=$(DOCKER_HUB_REPO)/torpedo-longevity:$(DOCKER_HUB_TAG)
deploy-longevity: container-longevity
sudo docker push $(TORPEDO_IMG)
clean:
-sudo rm -rf bin
-sudo find . -type f -name "*.test" -delete
@echo "Deleting basic image"
-docker rmi -f $(DOCKER_HUB_REPO)/torpedo:$(DOCKER_HUB_TAG)
@echo "Deleting pds image"
-docker rmi -f $(DOCKER_HUB_REPO)/torpedo-pds:$(DOCKER_HUB_TAG)
@echo "Deleting backup image"
-docker rmi -f $(DOCKER_HUB_REPO)/torpedo-backup:$(DOCKER_HUB_TAG)
@echo "Deleting taas image"
-docker rmi -f $(DOCKER_HUB_REPO)/torpedo-taas:$(DOCKER_HUB_TAG)
@echo "Deleting longevity image"
-docker rmi -f $(DOCKER_HUB_REPO)/torpedo-longevity:$(DOCKER_HUB_TAG)
go clean -i $(PKGS)
sidecar: sidecar-wp-cli
sidecar-wp-cli:
docker build -t $(SIDECAR_WP_CLI_IMG) -f $(SIDECAR_DIR)/wp-cli.dockerfile $(SIDECAR_DIR)
docker push $(SIDECAR_WP_CLI_IMG)
sysbench:
docker build -t $(SYSBENCH_IMG) -f $(SIDECAR_DIR)/sysbench.dockerfile $(SIDECAR_DIR)
docker push $(SYSBENCH_IMG)
pgbench:
docker build -t $(PGBENCH_IMG) -f $(SIDECAR_DIR)/pgbench.dockerfile $(SIDECAR_DIR)
docker push $(PGBENCH_IMG)
esload:
docker build -t $(ESLOAD_IMG) $(SIDECAR_DIR)/es-stress-test
docker push $(ESLOAD_IMG)