-
Notifications
You must be signed in to change notification settings - Fork 108
/
Makefile
231 lines (178 loc) · 7.61 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
NETWORK ?= stage
WRAPPER_TAG ?= default
# One of patch, minor, or major
UPGRADE_TYPE ?= patch
GIT_SHA := $(shell git rev-parse HEAD)
AD_TAG ?= $(GIT_SHA)
ABI_ARTIFACT_DIR := pkg/register/ABIs
ABI_SRC_DIR := packages/libs/src/eth-contracts/ABIs
ABI_SRCS := $(ABI_SRC_DIR)/ERC20Detailed.json $(ABI_SRC_DIR)/Registry.json $(ABI_SRC_DIR)/ServiceProviderFactory.json
ABI_ARTIFACTS := $(ABI_ARTIFACT_DIR)/ERC20Detailed.json $(ABI_ARTIFACT_DIR)/Registry.json $(ABI_ARTIFACT_DIR)/ServiceProviderFactory.json
SQL_SRCS := $(shell find pkg/core/db/sql -type f -name '*.sql') pkg/core/db/sqlc.yaml
SQL_ARTIFACTS := $(wildcard pkg/core/db/*.sql.go)
PROTO_SRCS := pkg/core/proto/protocol.proto
PROTO_ARTIFACTS := $(wildcard pkg/core/gen/proto/*.pb.go)
TEMPL_SRCS := $(shell find pkg/core/console -type f -name "*.templ")
TEMPL_ARTIFACTS := $(shell find pkg/core/console -type f -name "*_templ.go")
VERSION_LDFLAG := -X github.com/AudiusProject/audius-protocol/core/config.Version=$(GIT_SHA)
JSON_SRCS := $(wildcard pkg/core/config/genesis/*.json) $(ABI_ARTIFACTS)
JS_SRCS := $(shell find pkg/core -type f -name '*.js')
GO_SRCS := $(shell find pkg cmd -type f -name '*.go')
BUILD_SRCS := $(GO_SRCS) $(JS_SRCS) $(JSON_SRCS) go.mod go.sum
bin/audiusd-native: $(BUILD_SRCS)
@echo "Building audiusd for local platform and architecture..."
@bash scripts/build-audiusd.sh $@
bin/audiusd-x86_64-linux: $(BUILD_SRCS)
@echo "Building x86 audiusd for linux..."
@bash scripts/build-audiusd.sh $@ amd64 linux
bin/audius-ctl-native: $(BUILD_SRCS)
@echo "Building audius-ctl for local platform and architecture..."
@bash scripts/build-audius-ctl.sh $@
bin/audius-ctl-arm64-linux: $(BUILD_SRCS)
@echo "Building arm audius-ctl for linux..."
@bash scripts/build-audius-ctl.sh $@ arm64 linux
bin/audius-ctl-x86_64-linux: $(BUILD_SRCS)
@echo "Building x86 audius-ctl for linux..."
@bash scripts/build-audius-ctl.sh $@ amd64 linux
bin/audius-ctl-arm64-darwin: $(BUILD_SRCS)
@echo "Building macos arm audius-ctl..."
@bash scripts/build-audius-ctl.sh $@ arm64 darwin
bin/audius-ctl-x86_64-darwin: $(BUILD_SRCS)
@echo "Building macos x86 audius-ctl..."
@bash scripts/build-audius-ctl.sh $@ amd64 darwin
# Experimental statusbar feature
bin/audius-ctl-arm64-darwin-experimental: $(BUILD_SRCS)
@echo "Building macos arm audius-ctl..."
@GOOS=darwin GOARCH=arm64 go build -tags osx -ldflags -X main.Version="$(shell git rev-parse HEAD)" -o bin/audius-ctl-arm64-darwin-experimental ./cmd/audius-ctl
.PHONY: release-audius-ctl audius-ctl-production-build
release-audius-ctl:
bash scripts/release-audius-ctl.sh
audius-ctl-production-build: clean ignore-code-gen bin/audius-ctl-arm64-linux bin/audius-ctl-x86_64-linux bin/audius-ctl-arm64-darwin bin/audius-ctl-x86_64-darwin
.PHONY: ignore-code-gen
ignore-code-gen:
@echo "Warning: not regenerating .go files from sql, templ, proto, etc. Using existing artifacts instead."
@touch $(SQL_ARTIFACTS) $(TEMPL_ARTIFACTS) $(PROTO_ARTIFACTS) go.mod
.PHONY: build-wrapper-local build-push-wrapper
build-wrapper-local:
@echo "Building Docker image for local platform..."
docker buildx build --load -t audius/audius-d:$(WRAPPER_TAG) pkg/orchestration
build-push-wrapper:
@echo "Building and pushing Docker images for all platforms..."
docker buildx build --platform linux/amd64,linux/arm64 --push -t audius/audius-d:$(WRAPPER_TAG) pkg/orchestration
.PHONY: build-audiusd-local build-push-audiusd
build-audiusd-local:
docker build -t audius/audiusd:$(AD_TAG) -f ./cmd/audiusd/Dockerfile ./
build-push-audiusd:
DOCKER_DEFAULT_PLATFORM=linux/amd64 docker build --push -t audius/audiusd:$(AD_TAG) -f ./cmd/audiusd/Dockerfile ./
.PHONY: install uninstall
install:
@bash scripts/install-audius-ctl.sh local
uninstall:
@bash scripts/uninstall-audius-ctl.sh
.PHONY: clean
clean:
rm -f bin/*
.PHONY: install-deps
install-deps:
@brew install protobuf
@brew install crane
@brew install bufbuild/buf/buf
@go install github.com/onsi/ginkgo/v2/[email protected]
@go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
@go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
@go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
@go install github.com/cortesi/modd/cmd/modd@latest
@go install github.com/a-h/templ/cmd/templ@latest
@go install github.com/ethereum/go-ethereum/cmd/abigen@latest
@go install github.com/go-swagger/go-swagger/cmd/swagger@latest
go.sum: go.mod
go.mod: $(GO_SRCS)
@# dummy go.mod file to speed up tidy times
@[ -d node_modules ] && touch node_modules/go.mod || true
go mod tidy
@touch go.mod # in case there's nothing to tidy
.PHONY: gen
gen: regen-abi regen-templ regen-proto regen-sql regen-go
.PHONY: regen-abi
regen-abi: $(ABI_ARTIFACTS)
$(ABI_ARTIFACTS): $(ABI_SRCS)
@echo Regenerating ABI contracts
@jq '.abi' $(ABI_SRC_DIR)/ERC20Detailed.json > $(ABI_ARTIFACT_DIR)/ERC20Detailed.json
@jq '.abi' $(ABI_SRC_DIR)/Registry.json > $(ABI_ARTIFACT_DIR)/Registry.json
@jq '.abi' $(ABI_SRC_DIR)/ServiceProviderFactory.json > $(ABI_ARTIFACT_DIR)/ServiceProviderFactory.json
.PHONY: regen-templ
regen-templ: $(TEMPL_ARTIFACTS)
$(TEMPL_ARTIFACTS): $(TEMPL_SRCS)
@echo Regenerating templ code
cd pkg/core/console && go generate ./...
.PHONY: regen-proto
regen-proto: $(PROTO_ARTIFACTS)
$(PROTO_ARTIFACTS): $(PROTO_SRCS)
@echo Regenerating protobuf code
cd pkg/core && buf generate
cd pkg/core/gen/proto && swagger generate client -f protocol.swagger.json -t ../ --client-package=core_openapi
.PHONY: regen-sql
regen-sql: $(SQL_ARTIFACTS)
$(SQL_ARTIFACTS): $(SQL_SRCS)
@echo Regenerating sql code
cd pkg/core/db && sqlc generate
.PHONY: regen-go
regen-go:
cd pkg/core && go generate ./...
##############
## MEDIORUM ##
##############
.PHONY: mediorum-dev
mediorum-dev:
@if docker ps -q -f name=postgres; then \
echo "container 'postgres' is already running"; \
else \
docker run --rm --name postgres -v $$(pwd)/cmd/mediorum/.initdb:/docker-entrypoint-initdb.d -e POSTGRES_PASSWORD=example -p 5454:5432 -d postgres; \
fi
go run cmd/mediorum/main.go
##########
## CORE ##
##########
.PHONY: core-build-native
core-build-native: bin/core
bin/core: $(BUILD_SRCS)
@go build -ldflags "$(VERSION_LDFLAG)" -o bin/core ./cmd/core/main.go
.PHONY: core-build-amd64
core-build-amd64: bin/core-amd64
bin/core-amd64: $(BUILD_SRCS)
@GOOS=linux GOARCH=amd64 go build -ldflags "$(VERSION_LDFLAG)" -o bin/core-amd64 ./cmd/core/main.go
.PHONY: core-force-release-stage core-force-release-foundation core-force-release-sps
core-force-release-stage:
@bash scripts/release-core.sh $@
core-force-release-foundation:
@bash scripts/release-core.sh $@
core-force-release-sps:
@bash scripts/release-core.sh $@
.PHONY: core-dev
core-dev: gen
audius-compose up db core core-content-1 core-content-2 core-content-3 eth-ganache ingress
.PHONY: core-test
core-test: gen
cd pkg/core && go test -v ./... -timeout 60s
.PHONY: core-sandbox
core-sandbox: core-build-amd64
@scripts/add-sandbox-hosts.sh
@docker compose -f ./cmd/core/infra/docker-compose.yml --profile prod --profile stage --profile dev up --build -d
.PHONY: core-down-sandbox
core-down-sandbox:
@docker compose -f ./cmd/core/infra/docker-compose.yml --profile prod --profile stage --profile dev down
.PHONY: core-prod-sandbox
core-prod-sandbox:
@scripts/add-sandbox-hosts.sh
@docker compose -f ./cmd/core/infra/docker-compose.yml --profile prod up --build -d
.PHONY: core-stage-sandbox
core-stage-sandbox:
@scripts/add-sandbox-hosts.sh
@docker compose -f ./cmd/core/infra/docker-compose.yml --profile stage up --build -d
.PHONY: core-dev-sandbox
core-dev-sandbox:
@scripts/add-sandbox-hosts.sh
@docker compose -f ./cmd/core/infra/docker-compose.yml --profile dev up --build -d
.PHONY: core-livereload
core-livereload:
modd