forked from storyprotocol/project-nova
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
143 lines (112 loc) · 5.19 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
LASTEST_COMMIT = $(shell git rev-parse --short HEAD)
TAG ?= ${USER}-local-${LASTEST_COMMIT}
ENV ?= staging
REGION ?= us-east-2
ifeq ($(ENV), prod)
REGION = us-east-1
endif
ECR ?= 243963068353.dkr.ecr.${REGION}.amazonaws.com
BUILDER_IMAGE ?= builder
ECR_BUILDER_IMAGE ?= ${ECR}/${BUILDER_IMAGE}
DOCKER_BUILD=docker build --cache-from
DEVELOPMENT_DB_URI = postgresql://postgres:@api-database:5432/postgres?sslmode=disable
help:
@echo ' ecr-auth: - Authenticate ECR'
@echo ' builder: - Build and push builder image'
@echo ' buildserver: - Build api server locally'
@echo ' runserver: - Run api server locally'
@echo ' server: - Build and then run api server locally'
@echo ' buildstreamer: - Build streamer locally'
@echo ' runstreamer: - Run streamer locally'
@echo ' runweb3gateway: - Build and then run web3-gateway locally'
@echo ' streamer: - Build and then run streamer locally'
@echo ''
@echo ' db_new: - Create new DB migration script for api server'
@echo ' db_up: - Apply new DB migration script to local Postgres DB for testing'
@echo ' db_down: - Drop the latest DB migration sql script to local Postgres DB for testing'
@echo ' db_drop: - Tear down local Postgres DB tables'
@echo ' db_shell: - Open local Postgres DB console'
@echo ''
@echo ' build-{service}: - Build specific service'
@echo ' push-{service}: - Push the current local image for the service to ECR'
@echo ' deploy-{service}: - Deploy the specific service using the latest image in the ECR, need to specific environment with ENV'
@echo ' For example: ENV=dev make deploy-bastion'
@echo ' restart-{service} - Restart specific service deployment'
@echo ' lint: - Run linter'
@echo ' abigen: - Create golang abi client for smart contracts based on the input json file.'
@echo ' For example: make abigen package=erc721. package corresponding to the input json name and output package name'
@echo ' s3-download: - S3 download based on the project and chapter and env passed in.'
@echo ' For example: make s3 dowload project=project-nova chapter=1:1:1 env=staging'
@echo ' s3-upload: - S3 upload based on the project and chapter and env passed in.'
@echo ' build-proto: - generate codes based on protobuf definition'
ecr-auth:
aws ecr get-login-password --region ${REGION} | docker login --username AWS --password-stdin ${ECR}
buildserver:
cd api && CGO_ENABLED=0 go build --ldflags "-extldflags '-static -s'" -o build/server cmd/api/main.go
runserver:
cd api && ./build/server --config=config/local.yaml,config/secrets.yaml
.PHONY: server
server:
make buildserver && make runserver
buildstreamer:
cd api && CGO_ENABLED=0 go build --ldflags "-extldflags '-static -s'" -o build/streamer cmd/streamer/main.go
runstreamer:
cd api && ./build/streamer --config=config/streamer/local.yaml,config/streamer/secrets.yaml
runweb3gateway:
cd web3-gateway && make run-server-local
.PHONY: streamer
streamer:
make buildstreamer && make runstreamer
preparedb:
docker compose up -d bastion api-database
.PHONY: db_new
db_new:
migrate create -ext sql -dir api/migrations -seq "migration_step_please_change_name"
.PHONY: db_up
db_up: preparedb
docker exec project-nova-bastion-1 migrate -database ${DEVELOPMENT_DB_URI} -path /build/api/migrations -verbose up
.PHONY: db_down
db_down: preparedb
docker exec project-nova-bastion-1 migrate -database ${DEVELOPMENT_DB_URI} -path /build/api/migrations -verbose down 1
.PHONY: db_drop
db_drop: preparedb
docker exec -e DATABASE_URI=${DEVELOPMENT_DB_URI} project-nova-bastion-1 sh /build/script/dropdb.sh
PHONY: db_shell
db_shell: preparedb
docker exec -it project-nova-bastion-1 psql ${DEVELOPMENT_DB_URI}
.PHONY: builder
builder: ecr-auth
${DOCKER_BUILD} ${BUILDER_IMAGE} -t ${BUILDER_IMAGE}:${TAG} -t ${ECR_BUILDER_IMAGE}:${TAG} dockerfile/builder/
docker push ${ECR_BUILDER_IMAGE}:${TAG}
${DOCKER_BUILD} ${BUILDER_IMAGE} -t ${BUILDER_IMAGE}:latest -t ${ECR_BUILDER_IMAGE}:latest dockerfile/builder/
docker push ${ECR_BUILDER_IMAGE}:latest
build-%:
docker-compose build $*
push-%: ecr-auth
@echo "pushing to ${ENV}"
docker tag $* ${ECR}/$*:${TAG}
docker tag $* ${ECR}/$*:latest
docker push ${ECR}/$*:${TAG}
docker push ${ECR}/$*:latest
deploy-%:
cd $*; ENV=${ENV} make deploy
deploy-streamer:
cd api; ENV=${ENV} make deploy-streamer
restart-%:
kubectl rollout restart deployment $* -n edge
lint:
golangci-lint run
.PHONY: abigen
abigen:
mkdir -p ./pkg/abi/${package}; abigen --abi=./resource/abi/${package}.json --pkg=${package} --out=./pkg/abi/${package}/${package}.go
.PHONY: s3-upload
s3-upload:
aws s3 cp api/resource/content/${project}/${chapter}/content.json s3://${project}-content-${env}/${chapter}/content.json
.PHONY: s3-download
s3-download:
aws s3 cp s3://${project}-content-${env}/${chapter}/content.json api/resource/content/${project}/${chapter}/content.json
.PHONY: build-proto
build-proto:
protoc -I. \
--go_out=plugins=grpc,paths=source_relative:. \
./proto/v1/web3_gateway/*.proto