forked from WalletConnect/walletconnect-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
190 lines (158 loc) · 5.76 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
### Deploy configs
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
GITHASH=$(shell git rev-parse --short HEAD)
REMOTE=$(shell git remote show origin -n | grep Push | cut -f6 -d' ')
REMOTE_HASH=$(shell git ls-remote $(REMOTE) $(BRANCH) | head -n1 | cut -f1)
project=walletconnect
redisImage='redis:6-alpine'
standAloneRedis='xredis'
nginxImage='$(project)/nginx:$(BRANCH)'
relayImage='$(project)/relay:$(BRANCH)'
relayIndex=0
### Makefile internal coordination
flags=.makeFlags
VPATH=$(flags)
$(shell mkdir -p $(flags))
.PHONY: help clean clean-all reset
# Shamelessly stolen from https://www.freecodecamp.org/news/self-documenting-makefile
help: ## Show this help
@egrep -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
pull: ## downloads docker images
docker pull $(redisImage)
@touch $(flags)/$@
@echo "MAKE: Done with $@"
@echo
config: ## configures domain and certbot email
@read -p 'Relay URL domain: ' relay; \
echo "RELAY_URL="$$relay > config
@read -p 'Email for SSL certificate (default noreply@gmail.com): ' email; \
echo "CERTBOT_EMAIL="$$email >> config
@read -p 'Is your DNS configured with cloudflare proxy? [y/N]: ' cf; \
echo "CLOUDFLARE="$${cf:-false} >> config
@touch $(flags)/$@
@echo "MAKE: Done with $@"
@echo
bootstrap-lerna: ## setups lerna for the monorepo management
npm i
npx lerna link
npx lerna bootstrap
@touch $(flags)/$@
@echo "MAKE: Done with $@"
@echo
build-react-app: ## builds the example react-app
npm install --prefix examples/react-app
npm run build --prefix examples/react-app
@touch $(flags)/$@
@echo "MAKE: Done with $@"
@echo
build-react-wallet: ## builds the example react-wallet
npm install --prefix examples/react-wallet
npm run build --prefix examples/react-wallet
@touch $(flags)/$@
@echo "MAKE: Done with $@"
@echo
build-lerna: bootstrap-lerna ## builds the npm packages in "./packages"
npx lerna run build
@touch $(flags)/$@
@echo "MAKE: Done with $@"
@echo
build-container: ## builds relay docker image
docker build \
--build-arg githash=$(GITHASH) \
-t $(relayImage) \
-f ops/relay.Dockerfile .
@echo "MAKE: Done with $@"
@echo
build-relay: ## builds the relay system local npm
npm install --prefix servers/relay
npm run build --prefix servers/relay
@touch $(flags)/$@
@echo "MAKE: Done with $@"
@echo
build-nginx: ## builds nginx docker image
docker build \
-t $(nginxImage) \
--build-arg BRANCH=$(BRANCH) \
-f ops/nginx/nginx.Dockerfile ./ops/nginx
@touch $(flags)/$@
@echo "MAKE: Done with $@"
@echo
build: pull build-container build-nginx build-lerna ## builds all the packages and the containers for the relay
@touch $(flags)/$@
@echo "MAKE: Done with $@"
@echo
test-client: build-lerna ## runs "./packages/client" tests against the locally running relay. Make sure you run 'make dev' before.
npm run test --prefix packages/client
test-staging: build-lerna ## tests client against staging.walletconnect.org
TEST_RELAY_URL=wss://staging.walletconnect.org npm run test --prefix packages/client
test-production: build-lerna ## tests client against relay.walletconnect.org
TEST_RELAY_URL=wss://relay.walletconnect.org npm run test --prefix packages/client
test-relay: build-relay## runs "./servers/relay" tests against the locally running relay. Make sure you run 'make dev' before.
npm run test --prefix servers/relay
start-redis: ## starts redis docker container for local development
docker run --rm --name $(standAloneRedis) -d -p 6379:6379 $(redisImage) || true
@echo "MAKE: Done with $@"
@echo
dev: build-relay start-redis ## runs relay on watch mode and shows logs
npm run dev --prefix servers/relay
@echo "MAKE: Done with $@"
@echo
ci: ## runs tests in github actions
printf "RELAY_URL=\nCERTBOT_EMAIL=\nCLOUDFLARE=false\n" > config
APP_PORT=5555 NODE_ENV=development $(MAKE) deploy
sleep 20
docker service logs --tail 100 $(project)_nginx
docker service logs --tail 100 $(project)_relay0
TEST_RELAY_URL=wss://localhost $(MAKE) test-client
TEST_RELAY_URL=wss://localhost $(MAKE) test-relay
cloudflare: config ## setups cloudflare API token secret
bash ops/cloudflare-secret.sh $(project)
@touch $(flags)/$@
@echo "MAKE: Done with $@"
@echo
predeploy: config cloudflare pull build-container build-nginx
deploy: predeploy ## deploys production stack with './config' file contents
RELAY_IMAGE=$(relayImage) \
NGINX_IMAGE=$(nginxImage) \
PROJECT=$(project) \
bash ops/deploy.sh
@echo "MAKE: Done with $@"
@echo
deploy-monitoring: predeploy ## same as deploy but also has monitoring stack
RELAY_IMAGE=$(relayImage) \
NGINX_IMAGE=$(nginxImage) \
PROJECT=$(project) \
MONITORING=true \
bash ops/deploy.sh
@echo "MAKE: Done with $@"
@echo
redeploy: clean predeploy ## redeploys the prodution containers and rebuilds them
docker service update --force --image $(nginxImage) $(project)_nginx
docker service update --force --image $(relayImage) $(project)_relay0
relay-logs: ## follows the relay0 container logs. Doesn't work with 'make dev'
docker service logs -f --raw --tail 100 $(project)_relay0
rm-redis: ## stops the redis container
docker stop $(standAloneRedis) || true
down: stop ## alias of stop
stop: rm-redis ## stops the whole docker stack
docker stack rm $(project)
while [ -n "`docker network ls --quiet --filter label=com.docker.stack.namespace=$(project)`" ]; do echo -n '.' && sleep 1; done
@echo
@echo "MAKE: Done with $@"
@echo
reset: ## removes config and lerna bootstrap
$(MAKE) clean-all
rm -f config
@echo "MAKE: Done with $@"
@echo
clean: ## removes all build outputs
rm -rf .makeFlags/build*
npm run clean --prefix servers/relay
npx lerna run clean
@echo "MAKE: Done with $@"
@echo
clean-all: clean ## cleans lerna bootstrap
npx lerna clean -y
rm -rf .makeFlags
@echo "MAKE: Done with $@"
@echo