-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
174 lines (158 loc) · 8.28 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
ifneq (${GIT_USE},)
ifeq ($(shell git tag --contains HEAD),)
VERSION := $(shell git rev-parse --short HEAD)
else
VERSION := $(shell git tag --contains HEAD)
endif
endif
ifneq ($(goproxy),)
re_build_arg := --build-arg goproxy="$(goproxy)"
endif
ifeq ($(shell uname -s),Darwin)
SED_COMMAND := gsed
else
SED_COMMAND := sed
endif
BUILDNAME := intmax2-node
BUILDTIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
GOLDFLAGS += -X intmax2-node/configs/buildvars.Version=$(VERSION)
GOLDFLAGS += -X intmax2-node/configs/buildvars.BuildTime=$(BUILDTIME)
GOLDFLAGS += -X intmax2-node/configs/buildvars.BuildName=$(BUILDNAME)
GOFLAGS = -ldflags "$(GOLDFLAGS)"
.DEFAULT_GOAL := default
.PHONY: default
default: gen lint build
.PHONY: build
build:
go build -v -o $(BUILDNAME) $(GOFLAGS) ./cmd/
.PHONY: gen
gen: format-proto
buf generate -v --debug --timeout=2m --template api/proto/block_builder_service/buf.gen.yaml api/proto/block_builder_service
buf generate -v --debug --timeout=2m --template api/proto/block_builder_service/buf.gen.tagger.yaml api/proto/block_builder_service
buf generate -v --debug --timeout=2m --template api/proto/store_vault_service/buf.gen.yaml api/proto/store_vault_service
buf generate -v --debug --timeout=2m --template api/proto/store_vault_service/buf.gen.tagger.yaml api/proto/store_vault_service
buf generate -v --debug --timeout=2m --template api/proto/withdrawal_service/buf.gen.yaml api/proto/withdrawal_service
buf generate -v --debug --timeout=2m --template api/proto/withdrawal_service/buf.gen.tagger.yaml api/proto/withdrawal_service
go generate -v ./...
cp -rf docs/swagger/block_builder third_party/OpenAPI/block_builder_service
cp -rf third_party/OpenAPI/_default/* third_party/OpenAPI/block_builder_service
cp -rf docs/swagger/store_vault third_party/OpenAPI/store_vault_service
cp -rf third_party/OpenAPI/_default/* third_party/OpenAPI/store_vault_service
cp -rf docs/swagger/withdrawal third_party/OpenAPI/withdrawal_service
cp -rf third_party/OpenAPI/_default/* third_party/OpenAPI/withdrawal_service
# node
ifneq (${SWAGGER_USE},)
ifneq (${SWAGGER_BUILD_MODE},)
$(SED_COMMAND) -i "s/SWAGGER_VERSION/$(VERSION)/g" third_party/OpenAPI/block_builder_service/block_builder/apidocs.swagger.json
else
$(SED_COMMAND) -i "s/SWAGGER_VERSION/v0.0.0/g" third_party/OpenAPI/block_builder_service/block_builder/apidocs.swagger.json
endif
ifneq (${SWAGGER_HOST_URL},)
$(SED_COMMAND) -i "s/SWAGGER_HOST_URL/${SWAGGER_HOST_URL}/g" third_party/OpenAPI/block_builder_service/block_builder/apidocs.swagger.json
else
$(SED_COMMAND) -i "s/SWAGGER_HOST_URL//g" third_party/OpenAPI/block_builder_service/block_builder/apidocs.swagger.json
endif
ifneq (${SWAGGER_BASE_PATH},)
$(SED_COMMAND) -i "s/SWAGGER_BASE_PATH/${SWAGGER_BASE_PATH}/g" third_party/OpenAPI/block_builder_service/block_builder/apidocs.swagger.json
else
$(SED_COMMAND) -i "s/SWAGGER_BASE_PATH/\//g" third_party/OpenAPI/block_builder_service/block_builder/apidocs.swagger.json
endif
endif
# store vault
ifneq (${SWAGGER_USE},)
ifneq (${SWAGGER_BUILD_MODE},)
$(SED_COMMAND) -i "s/SWAGGER_VERSION/$(VERSION)/g" third_party/OpenAPI/store_vault_service/store_vault/apidocs.swagger.json
else
$(SED_COMMAND) -i "s/SWAGGER_VERSION/v0.0.0/g" third_party/OpenAPI/store_vault_service/store_vault/apidocs.swagger.json
endif
ifneq (${SWAGGER_HOST_URL},)
$(SED_COMMAND) -i "s/SWAGGER_HOST_URL/${SWAGGER_HOST_URL}/g" third_party/OpenAPI/store_vault_service/store_vault/apidocs.swagger.json
else
$(SED_COMMAND) -i "s/SWAGGER_HOST_URL//g" third_party/OpenAPI/store_vault_service/store_vault/apidocs.swagger.json
endif
ifneq (${SWAGGER_BASE_PATH},)
$(SED_COMMAND) -i "s/SWAGGER_BASE_PATH/${SWAGGER_BASE_PATH}/g" third_party/OpenAPI/store_vault_service/store_vault/apidocs.swagger.json
else
$(SED_COMMAND) -i "s/SWAGGER_BASE_PATH/\//g" third_party/OpenAPI/store_vault_service/store_vault/apidocs.swagger.json
endif
endif
# withdrawal
ifneq (${SWAGGER_USE},)
ifneq (${SWAGGER_BUILD_MODE},)
$(SED_COMMAND) -i "s/SWAGGER_VERSION/$(VERSION)/g" third_party/OpenAPI/withdrawal_service/withdrawal/apidocs.swagger.json
else
$(SED_COMMAND) -i "s/SWAGGER_VERSION/v0.0.0/g" third_party/OpenAPI/withdrawal_service/withdrawal/apidocs.swagger.json
endif
ifneq (${SWAGGER_HOST_URL},)
$(SED_COMMAND) -i "s/SWAGGER_HOST_URL/${SWAGGER_HOST_URL}/g" third_party/OpenAPI/withdrawal_service/withdrawal/apidocs.swagger.json
else
$(SED_COMMAND) -i "s/SWAGGER_HOST_URL//g" third_party/OpenAPI/withdrawal_service/withdrawal/apidocs.swagger.json
endif
ifneq (${SWAGGER_BASE_PATH},)
$(SED_COMMAND) -i "s/SWAGGER_BASE_PATH/${SWAGGER_BASE_PATH}/g" third_party/OpenAPI/withdrawal_service/withdrawal/apidocs.swagger.json
else
$(SED_COMMAND) -i "s/SWAGGER_BASE_PATH/\//g" third_party/OpenAPI/withdrawal_service/withdrawal/apidocs.swagger.json
endif
endif
.PHONY: format-proto
format-proto: ## format all protos
clang-format -i api/proto/block_builder_service/block_builder/v1/block_builder.proto
clang-format -i api/proto/store_vault_service/store_vault/v1/store_vault.proto
clang-format -i api/proto/withdrawal_service/withdrawal/v1/withdrawal.proto
.PHONY: tools
tools:
go install -v go.uber.org/mock/[email protected]
go install -v github.com/golangci/golangci-lint/cmd/[email protected]
go install -v github.com/bufbuild/buf/cmd/[email protected]
go install -v github.com/grpc-ecosystem/grpc-gateway/v2/[email protected]
go install -v github.com/grpc-ecosystem/grpc-gateway/v2/[email protected]
go install -v google.golang.org/grpc/cmd/[email protected]
go install -v google.golang.org/protobuf/cmd/[email protected]
go install -v github.com/srikrsna/[email protected]
.PHONY: run
run: gen ## starting application and dependency services
# translate `SWAGGER_USE=true GIT_USE=true HTTP_PORT=8080 GRPC_PORT=10000 CMD_RUN="run" make run` => ./intmax2-node run
# translate `SWAGGER_USE=true GIT_USE=true HTTP_PORT=8081 GRPC_PORT=10001 CMD_RUN="store-vault-server run" make run` => ./intmax2-node store-vault-server run
# translate `SWAGGER_USE=true GIT_USE=true HTTP_PORT=8082 GRPC_PORT=10002 CMD_RUN="withdrawal-server" make run` => ./intmax2-node withdrawal-server
go run $(GOFLAGS) ./cmd ${CMD_RUN}
.PHONY: up
up: ## starting application and dependency services
cp -f build/env.docker.block-builder-service.example build/env.docker.block-builder-service
cp -f build/env.docker.store-vault-server.example build/env.docker.store-vault-server
cp -f build/env.docker.withdrawal-server.example build/env.docker.withdrawal-server
docker compose -f build/docker-compose.yml up
.PHONY: build-up
build-up: down ## rebuilding containers and starting application and dependency services
cp -f build/env.docker.block-builder-service.example build/env.docker.block-builder-service
cp -f build/env.docker.store-vault-server.example build/env.docker.store-vault-server
cp -f build/env.docker.withdrawal-server.example build/env.docker.withdrawal-server
docker compose -f build/docker-compose.yml build $(re_build_arg)
docker compose -f build/docker-compose.yml up
.PHONY: start-build-up
start-build-up: down ## rebuilding containers and starting application and dependency services
cp -f build/env.docker.block-builder-service.example build/env.docker.block-builder-service
cp -f build/env.docker.store-vault-server.example build/env.docker.store-vault-server
cp -f build/env.docker.withdrawal-server.example build/env.docker.withdrawal-server
docker compose -f build/docker-compose.yml up -d intmax2-node-postgres
docker compose -f build/docker-compose.yml up -d intmax2-node-ot-collector
.PHONY: down
down:
cp -f build/env.docker.block-builder-service.example build/env.docker.block-builder-service
cp -f build/env.docker.store-vault-server.example build/env.docker.store-vault-server
cp -f build/env.docker.withdrawal-server.example build/env.docker.withdrawal-server
docker compose -f build/docker-compose.yml down
rm -f build/env.docker.block-builder-service
rm -f build/env.docker.store-vault-server
rm -f build/env.docker.withdrawal-server
.PHONY: clean-all
clean-all: down
rm -f build/env.docker.block-builder-service
rm -f build/env.docker.store-vault-server
rm -f build/env.docker.withdrawal-server
rm -rf build/sql_dbs/intmax2-node-postgres
.PHONY: lint
lint:
buf lint api/proto/block_builder_service
buf lint api/proto/store_vault_service
buf lint api/proto/withdrawal_service
golangci-lint run --timeout=20m --fix ./...