-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile
245 lines (207 loc) · 9 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
SHELL:= /bin/bash
DEBUG_FLAG?=false
GO_VERSION=1.22
ifeq ($(DEBUG), "true")
BINDATA_OPTS="-debug"
endif
ifdef BUILD_ID
GO_OPTS=-ldflags="-X main.ServerVersion=build-$(BUILD_ID)"
endif
# Load dotenv configuration
ifneq (,$(wildcard ./.env))
include .env
export
endif
ifndef $(PROXEUS_SPARKPOST_API_KEY)
PROXEUS_SPARKPOST_API_KEY=0
PROXEUS_INFURA_API_KEY=0
PROXEUS_BLOCKCHAIN_CONTRACT_ADDRESS=0x
endif
# Default proxeus environment
export PROXEUS_TEST_MODE?=false
export PROXEUS_ALLOW_HTTP?=true
export PROXEUS_SETTINGS_FILE?=~/.proxeus/settings/main.json
export PROXEUS_PLATFORM_DOMAIN?=http://localhost:1323
export PROXEUS_DOCUMENT_SERVICE_URL?=http://localhost:2115
export PROXEUS_BLOCKCHAIN_CONTRACT_ADDRESS?=${PROXEUS_BLOCKCHAIN_CONTRACT_ADDRESS}
export PROXEUS_INFURA_API_KEY?=${PROXEUS_INFURA_API_KEY}
export PROXEUS_SPARKPOST_API_KEY?=${PROXEUS_SPARKPOST_API_KEY}
export [email protected]
export PROXEUS_DATA_DIR?=./data
export PROXEUS_DATABASE_ENGINE?=storm
export PROXEUS_DATABASE_URI?=mongodb://localhost:27017
export PROXEUS_ENCRYPTION_SECRET_KEY?=PleAsE_chAnGe_me_32_Characters++
#########################################################
# Docker build set up
DOCKER_GATEWAY=172.17.0.1
DOCKER=sudo docker
export BUILD_WITH_DOCKER?=false
ifeq ($(shell uname), Darwin)
BUILD_WITH_DOCKER=true
endif
ifeq ($(BUILD_WITH_DOCKER), true)
DOCKER_LINUX=docker run --rm -v "$(PWD):/usr/src" -w /usr/src golang:$(GO_VERSION)
DOCKER_GATEWAY=host.docker.internal
DOCKER=docker
endif
#########################################################
# Coverage
coverage?=false
comma:=,
space:= $() $()
coverpkg=$(subst $(space),$(comma), $(filter-out %/mock %/assets, $(shell go list ./main/... ./sys/... ./storage/... ./service/...)))
startproxeus=PROXEUS_DATA_DIR=$(1)/data PROXEUS_SETTINGS_FILE=$(1)/settings/main.json PROXEUS_TEST_MODE=true artifacts/proxeus -ServiceAddress 0.0.0.0:1323 &
stopproxeus=pkill proxeus
startds=curl -s http://localhost:2115 > /dev/null || ( PROXEUS_DATA_DIR=$(1) docker-compose up -d document-service && touch $(1)/ds-started )
startnodes=curl -s http://localhost:8011 > /dev/null || (PROXEUS_PLATFORM_DOMAIN=http://$(DOCKER_GATEWAY):1323 NODE_CRYPTO_RATES_URL=http://localhost:8011 REGISTER_RETRY_INTERVAL=1 docker-compose -f docker-compose.yml -f docker-compose-extra.override.yml up -d node-crypto-forex-rates && touch $(1)/nodes-started )
startmongo=nc -z localhost 27017 2> /dev/null || (docker run -d -p 27017:27017 -p 27018:27018 -p 27019:27019 proxeus/mongo-dev-cluster && sleep 10 && touch $(1)/mongo-started)
waitforproxeus=echo "Waiting for Proxeus to start" ; curl --head -X GET --retry 120 --retry-connrefused --retry-delay 1 --silent -o /dev/null http://0.0.0.0:1323 && echo "Proxeus started" || echo "Unable to start Proxeus"
ifeq ($(coverage),true)
COVERAGE_OPTS=-coverprofile artifacts/[email protected] -coverpkg="$(coverpkg)"
startproxeus=PROXEUS_DATA_DIR=$(1)/data PROXEUS_SETTINGS_FILE=$(1)/settings/main.json PROXEUS_TEST_MODE=true go test -v -tags coverage -coverprofile artifacts/$@-$(PROXEUS_DATABASE_ENGINE).coverage -coverpkg="$(coverpkg)" ./main &
stopproxeus=pkill main.test
endif
dependencies=go curl
mocks=main/handlers/blockchain/mock/adapter_mock.go storage/mock/interfaces.go
bindata=main/handlers/assets/bindata.go test/assets/bindata.go
golocalimport=github.com/ProxeusApp/proxeus-core
.PHONY: all
all: ui server
.PHONY: init
init:
@for d in $(dependencies); do (echo "Checking $$d is installed... " && which $$d ) || ( echo "Please install $$d before continuing" && exit 1 ); done
@go version
go install github.com/go-bindata/go-bindata/...@latest
go install github.com/golang/mock/mockgen@latest
go install github.com/wadey/gocovmerge@latest
go install golang.org/x/tools/...@latest
go install golang.org/x/tools/cmd/goimports@latest
go install golang.org/x/tools/cmd/godoc@latest
.PHONY: update
update:
echo "Updating all Go packages"
go get -u all
.PHONY: ui
ui:
$(MAKE) -C ui
.PHONY: ui-dev
ui-dev:
$(MAKE) -C ui serve-main-hosted
.PHONY: generate
generate: $(bindata) $(mocks)
.PHONY: server
server: generate
go build $(GO_OPTS) -tags nocgo -o ./artifacts/proxeus ./main
.PHONY: server-docker
server-docker: generate
$(DOCKER_LINUX) go build $(GO_OPTS) -tags nocgo -o ./artifacts/proxeus-docker ./main
.PHONY: build-docker
build-docker: server-docker
# Creates a local Docker image
$(DOCKER) build -f Dockerfile -t proxeus/proxeus-core:latest -t proxeus/proxeus-core .
.PHONY: validate
validate: init
@if [[ "$$(goimports -l -local $(golocalimport) main sys storage service | grep -v bindata.go | tee /dev/tty | wc -l | xargs)" != "0" ]]; then \
echo "Format validation error. Please run make fmt"; exit 1; \
fi
@echo "Format validated"
.PHONY: license
license:
# https://github.com/pivotal/LicenseFinder
echo "Running LicenseFinder..."
license_finder
.PHONY: doc
doc: init
(echo "Checking wget is installed... " && which wget ) || ( echo "Please install wget before continuing" && exit 1)
$(eval serverurl=localhost:6060)
$(DOCKER) run --rm -e "GOPATH=/tmp/go" --name "godoc" -p 6060:6060 -v ${PWD}:/tmp/go/src/github.com/ProxeusApp/proxeus-core golang bash -c "go get golang.org/x/tools/cmd/godoc && /tmp/go/bin/godoc -http=:6060" &
# Download css & js first
wget --retry-connrefused -P artifacts/$(serverurl)/lib/godoc http://$(serverurl)/lib/godoc/style.css
wget --retry-connrefused -P artifacts/$(serverurl)/lib/godoc http://$(serverurl)/lib/godoc/jquery.js
wget --retry-connrefused -P artifacts/$(serverurl)/lib/godoc http://$(serverurl)/lib/godoc/godocs.js
# Now, only the package we're interested into. not the whole standard library
wget -r --retry-on-http-error=404 -P artifacts -np -e robots=off "http://$(serverurl)/pkg/github.com/ProxeusApp/proxeus-core/"
mkdir -p artifacts/godoc/lib/godoc
cp -r artifacts/$(serverurl)/pkg/github.com/ProxeusApp/proxeus-core/* artifacts/godoc
cp -r artifacts/$(serverurl)/lib/godoc/* artifacts/godoc/lib/godoc/
rm -R artifacts/$(serverurl)
$(DOCKER) stop godoc
zip -r artifacts/godoc.zip artifacts/godoc
rm -R artifacts/godoc
.PHONY: fmt
fmt:
goimports -w -local $(golocalimport) main sys service storage
.PHONY: test
test: generate
go test $(COVERAGE_OPTS) ./main/... ./sys/... ./storage/... ./service/...; ret=$$?; \
echo $$ret
.PHONY: test-integration
test-integration:
$(eval testdir := $(shell mktemp -d /tmp/proxeus-test-integration.XXXXX ))
mkdir -p $(testdir)
$(eval cid=$(shell $(call startmongo,$(testdir))))
go test $(COVERAGE_OPTS) -count=1 -tags integration ./storage/database/db/...; ret=$$?; \
$(if $(cid), docker rm -f $(cid);) \
rm -fr $(testdir); \
exit $$ret
.PHONY: test-api
test-api: server
$(eval testdir := $(shell mktemp -d /tmp/proxeus-test-api.XXXXX ))
mkdir -p $(testdir)
$(eval cid=$(shell [[ "x$(PROXEUS_DATABASE_ENGINE)" == "xmongo" ]] && $(call startmongo,$(testdir))))
$(call startds,$(testdir))
$(call startnodes,$(testdir))
$(call startproxeus,$(testdir))
PROXEUS_URL=http://localhost:1323 go test -count=1 ./test; ret=$$?; \
$(stopproxeus); \
[ -e $(testdir)/ds-started ] && docker-compose down; \
$(if $(cid), docker rm -f $(cid);) \
echo "Removing temp folder $(testdir)" \
rm -fr $(testdir); \
echo "WARNING: test result ignored!" \
exit # $$ret
.PHONY: test-ui
test-ui: server ui
$(eval testdir := $(shell mktemp -d /tmp/proxeus-test-ui.XXXXX ))
mkdir -p $(testdir)
$(eval cid=$(shell [[ "x$(PROXEUS_DATABASE_ENGINE)" == "xmongo" ]] && $(call startmongo,$(testdir))))
$(call startds,$(testdir))
$(call startnodes,$(testdir))
$(call startproxeus,$(testdir))
$(call waitforproxeus,$(testdir))
$(MAKE) -C test/e2e test; ret=$$?; \
$(stopproxeus); \
[ -e $(testdir)/ds-started ] && docker-compose down; \
$(if $(cid), docker rm -f $(cid);) \
rm -fr $(testdir); \
exit $$ret
.PHONY: test-storage
test-storage: generate
go test $(COVERAGE_OPTS) ./storage/...
.PHONY: coverage
coverage:
gocovmerge artifacts/*.coverage > artifacts/coverage
go tool cover -func artifacts/coverage > artifacts/coverage.txt
go tool cover -html artifacts/coverage -o artifacts/coverage.html
echo "WARNING: test result ignored!"
exit
.PHONY: clean
clean:
cd artifacts && rm -rf `ls . | grep -v 'cache'`
echo "Clearing the JS cache"
cd ui && yarn cache clean && cd ..
echo "Clearing the Go module cache"
go clean -modcache
.PHONY: run
run: server
artifacts/proxeus -DataDir $(PROXEUS_DATA_DIR)/proxeus-platform/data
main/handlers/assets/bindata.go: $(wildcard ./ui/core/dist/**)
go-bindata ${BINDATA_OPTS} -pkg assets -o ./main/handlers/assets/bindata.go -prefix ./ui/core/dist ./ui/core/dist/...
goimports -w $@
test/assets/bindata.go: $(filter-out bindata.go,$(shell find ./test/assets/ ! -name "bindata.go"))
go-bindata ${BINDATA_OPTS} -pkg assets -o ./test/assets/bindata.go ./test/assets/...
goimports -w $@
.SECONDEXPANSION: # See https://www.gnu.org/software/make/manual/make.html#Secondary-Expansion
$(mocks): $$(patsubst %_mock.go, %.go, $$(subst /mock,, $$@))
mockgen -package mock -source $< -destination $@ -self_package github.com/ProxeusApp/proxeus-core/$(shell dirname $@)
goimports -w $@