This repository has been archived by the owner on Jun 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathMakefile
262 lines (208 loc) · 12.4 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
259
260
261
262
BINARY=dp
CB_VERSION = $(shell echo \${VERSION})
ifeq ($(CB_VERSION),)
CB_VERSION ?= $(shell git describe --tags --abbrev=0)-snapshot
endif
PLUGIN_ENABLED ?= false
BUILD_TIME=$(shell date +%FT%T)
LDFLAGS=-ldflags "-X github.com/hortonworks/cb-cli/dataplane/common.Version=${CB_VERSION} -X github.com/hortonworks/cb-cli/dataplane/common.BuildTime=${BUILD_TIME} -X github.com/hortonworks/cb-cli/plugin.Enabled=${PLUGIN_ENABLED}"
LDFLAGS_NOVER=-ldflags "-X github.com/hortonworks/cb-cli/dataplane/common.Version=snapshot -X github.com/hortonworks/cb-cli/dataplane/common.BuildTime=${BUILD_TIME} -X github.com/hortonworks/cb-cli/plugin.Enabled=${PLUGIN_ENABLED}"
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./.git/*")
CB_IP = $(shell echo \${IP})
ifeq ($(CB_IP),)
CB_IP = localhost
endif
CB_PORT = $(shell echo \${PORT})
ifeq ($(CB_PORT),)
CB_PORT = 9091
endif
SDX_IP = $(shell echo \${IP})
ifeq ($(SDX_IP),)
SDX_IP = localhost
endif
SDX_PORT = $(shell echo \${PORT})
ifeq ($(SDX_PORT),)
SDX_PORT = 8086
endif
FREEIPA_IP = $(shell echo \${IP})
ifeq ($(FREEIPA_IP),)
FREEIPA_IP = localhost
endif
FREEIPA_PORT = $(shell echo \${PORT})
ifeq ($(FREEIPA_PORT),)
FREEIPA_PORT = 8090
endif
REDBEAMS_IP = $(shell echo \${IP})
ifeq ($(REDBEAMS_IP),)
REDBEAMS_IP = localhost
endif
REDBEAMS_PORT = $(shell echo \${PORT})
ifeq ($(REDBEAMS_PORT),)
REDBEAMS_PORT = 8087
endif
ifeq ($(ENVIRONMENT_IP),)
ENVIRONMENT_IP = localhost
endif
ENVIRONMENT_PORT = $(shell echo \${PORT})
ifeq ($(ENVIRONMENT_PORT),)
ENVIRONMENT_PORT = 8088
endif
deps: deps-errcheck
go get -u golang.org/x/tools/cmd/goimports
curl -o $(GOPATH)/bin/swagger -L'#' https://github.com/go-swagger/go-swagger/releases/download/v0.19.0/swagger_$(shell echo `uname`|tr '[:upper:]' '[:lower:]')_amd64
chmod +x $(GOPATH)/bin/swagger
deps-errcheck:
# go get -u github.com/kisielk/errcheck
formatcheck:
([ -z "$(shell gofmt -d $(GOFILES_NOVENDOR))" ]) || (echo "Source is unformatted, please execute make format"; exit 1)
versioncheck:
./checkversion.sh
format:
@gofmt -w ${GOFILES_NOVENDOR}
vet:
GO111MODULE=on go vet -mod=vendor ./...
test:
GO111MODULE=on go test -mod=vendor -timeout 30s -race ./...
errcheck:
# Module support is not on master yet: https://github.com/kisielk/errcheck/issues/152#issuecomment-415945206
# errcheck -ignoretests -exclude errcheck_excludes.txt ./...
coverage:
go test github.com/hortonworks/cb-cli/dataplane/... -cover
coverage-html:
go test github.com/hortonworks/cb-cli/dataplane/... -coverprofile fmt
@go tool cover -html=fmt
@rm -f fmt
build: versioncheck errcheck formatcheck vet test build-darwin build-darwin-arm64 build-linux
build-version: errcheck format vet test build-darwin-version build-darwin-arm64-version build-linux-version
build-docker:
@#USER_NS='-u $(shell id -u $(whoami)):$(shell id -g $(whoami))'
docker run --rm ${USER_NS} -v "${PWD}":/go/src/github.com/hortonworks/cb-cli -w /go/src/github.com/hortonworks/cb-cli -e VERSION=${CB_VERSION} -e GO111MODULE=on docker-private.infra.cloudera.com/cloudera_thirdparty/golang:1.20.1 make build
build-darwin:
GOOS=darwin GO111MODULE=on CGO_ENABLED=0 go build -mod=vendor -a ${LDFLAGS_NOVER} -o build/Darwin/${BINARY} main.go
build-darwin-arm64:
GOOS=darwin GOARCH=arm64 GO111MODULE=on CGO_ENABLED=0 go build -mod=vendor -a ${LDFLAGS_NOVER} -o build/Darwin-arm64/${BINARY} main.go
dev-debug-darwin:
GOOS=darwin GO111MODULE=on CGO_ENABLED=0 go build -a ${LDFLAGS_NOVER} -o /usr/local/bin/${BINARY} main.go
dev-debug-darwin-arm64:
GOOS=darwin GOARCH=arm64 GO111MODULE=on CGO_ENABLED=0 go build -a ${LDFLAGS_NOVER} -o /usr/local/bin/${BINARY} main.go
build-linux:
GOOS=linux GO111MODULE=on CGO_ENABLED=0 go build -mod=vendor -a ${LDFLAGS_NOVER} -o build/Linux/${BINARY} main.go
dev-debug-linux:
GOOS=linux GO111MODULE=on CGO_ENABLED=0 go build -a ${LDFLAGS_NOVER} -o ~/.local/bin/${BINARY} main.go
build-windows:
GOOS=windows GO111MODULE=on CGO_ENABLED=0 go build -mod=vendor -a ${LDFLAGS_NOVER} -o build/Windows/${BINARY}.exe main.go
build-darwin-version:
GOOS=darwin GO111MODULE=on CGO_ENABLED=0 go build -a ${LDFLAGS} -o build/Darwin/${BINARY} main.go
build-darwin-arm64-version:
GOOS=darwin GOARCH=arm64 GO111MODULE=on CGO_ENABLED=0 go build -a ${LDFLAGS} -o build/Darwin-arm64/${BINARY} main.go
build-linux-version:
GOOS=linux GO111MODULE=on CGO_ENABLED=0 go build -a ${LDFLAGS} -o build/Linux/${BINARY} main.go
build-windows-version:
GOOS=windows GO111MODULE=on CGO_ENABLED=0 go build -a ${LDFLAGS} -o build/Windows/${BINARY}.exe main.go
install: build ## Installs OS specific binary into: /usr/local/bin and ~/.local/bin
install build/$(shell uname -s)/$(BINARY) /usr/local/bin || true
install build/$(shell uname -s)/$(BINARY) ~/.local/bin || true
_init-swagger-generation:
rm -rf dataplane/api/client dataplane/api/model
rm -f build/swagger.json
curl -sL http://$(CB_IP):$(CB_PORT)/cb/api/swagger.json -o build/swagger.json
_init-swagger-generation-sdx:
rm -rf dataplane/api-sdx/client dataplane/api-sdx/model
rm -f build/swagger.json
curl -sL http://$(SDX_IP):$(SDX_PORT)/dl/api/swagger.json -o build/swagger.json
_init-swagger-generation-freeipa:
rm -rf dataplane/api-freeipa/client dataplane/api-freeipa/model
rm -f build/swagger.json
curl -sL http://$(FREEIPA_IP):$(FREEIPA_PORT)/freeipa/api/swagger.json -o build/swagger.json
_init-swagger-generation-redbeams:
rm -rf dataplane/api-redbeams/client dataplane/api-redbeams/model
rm -f build/swagger.json
curl -sL http://$(REDBEAMS_IP):$(REDBEAMS_PORT)/redbeams/api/swagger.json -o build/swagger.json
_init-swagger-generation-environment:
rm -rf dataplane/api-environment/client dataplane/api-environment/model
rm -f build/swagger.json
curl -sL http://$(ENVIRONMENT_IP):$(ENVIRONMENT_PORT)/environmentservice/api/swagger.json -o build/swagger.json
generate-swagger: _init-swagger-generation
swagger generate client -f build/swagger.json -c client -m model -t dataplane/api
generate-swagger-sdx:
rm -rf dataplane/api-sdx/client dataplane/api-sdx/model
swagger generate client -f http://$(SDX_IP):$(SDX_PORT)/dl/api/swagger.json -c client -m model -t dataplane/api-sdx
generate-swagger-freeipa:
rm -rf dataplane/api-freeipa/client dataplane/api-freeipa/model
swagger generate client -f http://$(FREEIPA_IP):$(FREEIPA_PORT)/freeipa/api/swagger.json -c client -m model -t dataplane/api-freeipa
generate-swagger-redbeams:
rm -rf dataplane/api-redbeams/client dataplane/api-redbeams/model
swagger generate client -f http://$(REDBEAMS_IP):$(REDBEAMS_PORT)/redbeams/api/swagger.json -c client -m model -t dataplane/api-redbeams
generate-swagger-environment:
rm -rf dataplane/api-environment/client dataplane/api-environment/model
mkdir -p dataplane/api-environment/client
mkdir -p dataplane/api-environment/model
swagger generate client -f http://$(ENVIRONMENT_IP):$(ENVIRONMENT_PORT)/environmentservice/api/swagger.json -c client -m model -t dataplane/api-environment
# The following commands are needed because 'EnvironmentNetworkAzureV1Params.NoOutboundLoadBalancer=false' param cannot be sent in env creation request
sed -i.bak '/NoOutboundLoadBalancer bool/s/bool/*bool/g' dataplane/api-environment/model/environment_network_azure_v1_params.go
rm -rf dataplane/api-environment/model/environment_network_azure_v1_params.go.bak
generate-swagger-all: generate-swagger generate-swagger-sdx generate-swagger-freeipa generate-swagger-redbeams generate-swagger-environment format
generate-swagger-docker-all: generate-swagger-docker generate-swagger-sdx-docker generate-swagger-freeipa-docker generate-swagger-redbeams-docker generate-swagger-environment-docker format
generate-swagger-docker: _init-swagger-generation
@docker run --rm -it -v "${GOPATH}":"${GOPATH}" -v ${PWD}/build/swagger.json:${PWD}/build/swagger.json -w "${PWD}" -e GOPATH --net=host quay.io/goswagger/swagger:v0.19.0 \
generate client -f ${PWD}/build/swagger.json -c client -m model -t dataplane/api
generate-swagger-sdx-docker: _init-swagger-generation-sdx
@docker run --rm -it -v "${GOPATH}":"${GOPATH}" -v ${PWD}/build/swagger.json:${PWD}/build/swagger.json -w "${PWD}" -e GOPATH --net=host quay.io/goswagger/swagger:v0.19.0 \
generate client -f ${PWD}/build/swagger.json -c client -m model -t dataplane/api-sdx
generate-swagger-freeipa-docker: _init-swagger-generation-freeipa
@docker run --rm -it -v "${GOPATH}":"${GOPATH}" -v ${PWD}/build/swagger.json:${PWD}/build/swagger.json -w "${PWD}" -e GOPATH --net=host quay.io/goswagger/swagger:v0.19.0 \
generate client -f ${PWD}/build/swagger.json -c client -m model -t dataplane/api-freeipa
generate-swagger-redbeams-docker: _init-swagger-generation-redbeams
@docker run --rm -it -v "${GOPATH}":"${GOPATH}" -v ${PWD}/build/swagger.json:${PWD}/build/swagger.json -w "${PWD}" -e GOPATH --net=host quay.io/goswagger/swagger:v0.19.0 \
generate client -f ${PWD}/build/swagger.json -c client -m model -t dataplane/api-redbeams
generate-swagger-environment-docker: _init-swagger-generation-environment
mkdir -p dataplane/api-environment/client
mkdir -p dataplane/api-environment/model
@docker run --rm -it -v "${GOPATH}":"${GOPATH}" -v ${PWD}/build/swagger.json:${PWD}/build/swagger.json -w "${PWD}" -e GOPATH --net=host quay.io/goswagger/swagger:v0.19.0 \
generate client -f ${PWD}/build/swagger.json -c client -m model -t dataplane/api-environment
# The following commands are needed because 'EnvironmentNetworkAzureV1Params.NoOutboundLoadBalancer=false' param cannot be sent in env creation request
sed -i.bak '/NoOutboundLoadBalancer bool/s/bool/*bool/g' dataplane/api-environment/model/environment_network_azure_v1_params.go
rm -rf dataplane/api-environment/model/environment_network_azure_v1_params.go.bak
release: build
rm -rf release
mkdir release
git config --global --add safe.directory /go/src/github.com/hortonworks/cb-cli
git tag v${CB_VERSION}
git push https://${GITHUB_ACCESS_TOKEN}@github.com/hortonworks/cb-cli.git v${CB_VERSION}
tar -zcvf release/dp-cli_${CB_VERSION}_Darwin_x86_64.tgz -C build/Darwin "${BINARY}"
tar -zcvf release/dp-cli_${CB_VERSION}_Darwin_arm64.tgz -C build/Darwin-arm64 "${BINARY}"
tar -zcvf release/dp-cli_${CB_VERSION}_Linux_x86_64.tgz -C build/Linux "${BINARY}"
# tar -zcvf release/dp-cli_${CB_VERSION}_Windows_x86_64.tgz -C build/Windows "${BINARY}.exe"
release-version: build-version
rm -rf release
mkdir release
git config --global --add safe.directory /go/src/github.com/hortonworks/cb-cli
git tag v${CB_VERSION}
git push https://${GITHUB_ACCESS_TOKEN}@github.com/hortonworks/cb-cli.git v${CB_VERSION}
tar -zcvf release/dp-cli_${CB_VERSION}_Darwin_x86_64.tgz -C build/Darwin "${BINARY}"
tar -zcvf release/dp-cli_${CB_VERSION}_Darwin_arm64.tgz -C build/Darwin-arm64 "${BINARY}"
tar -zcvf release/dp-cli_${CB_VERSION}_Linux_x86_64.tgz -C build/Linux "${BINARY}"
# tar -zcvf release/dp-cli_${CB_VERSION}_Windows_x86_64.tgz -C build/Windows "${BINARY}.exe"
release-docker:
@USER_NS='-u $(shell id -u $(whoami)):$(shell id -g $(whoami))'
docker run --rm ${USER_NS} -v "${PWD}":/go/src/github.com/hortonworks/cb-cli -w /go/src/github.com/hortonworks/cb-cli -e VERSION=${CB_VERSION} -e GITHUB_ACCESS_TOKEN=${GITHUB_TOKEN} -e GO111MODULE=on docker-private.infra.cloudera.com/cloudera_thirdparty/golang:1.20.1 bash -c "make release"
release-docker-version:
@USER_NS='-u $(shell id -u $(whoami)):$(shell id -g $(whoami))'
docker run --rm ${USER_NS} -v "${PWD}":/go/src/github.com/hortonworks/cb-cli -w /go/src/github.com/hortonworks/cb-cli -e VERSION=${CB_VERSION} -e GITHUB_ACCESS_TOKEN=${GITHUB_TOKEN} -e GO111MODULE=on docker-private.infra.cloudera.com/cloudera_thirdparty/golang:1.20.1 bash -c "make release-version"
upload_s3:
ls -1 release | xargs -I@ aws s3 cp release/@ s3://dp-cli/@ --acl public-read
linux-test: build-linux
docker run --rm -it -v ${PWD}/build/Linux/:/usr/sbin/ --name "${BINARY}" alpine sh
# Build DP-CLI locally
# Start a new DataPlane Mock with new Swagger JSON and renewed Mock IP
# For custom version apply like: 'GIT_FIRST_PARENT=2.8.0-dev.374 make integration-test'
# Execute just one scenario you can start this with: 'CLI_TEST_FILES=spec/integration/credential.rb make integration-test'
integration-test: build-docker
make -C tests all
mod-tidy:
@docker run --rm -v "${PWD}":/go/src/github.com/hortonworks/cb-cli -w /go/src/github.com/hortonworks/cb-cli -e GO111MODULE=on docker-private.infra.cloudera.com/cloudera_thirdparty/golang:1.20.1 make _mod-tidy
_mod-tidy:
go mod tidy -v
go mod vendor
.DEFAULT_GOAL := build
.PHONY: build release