forked from WalletConnect/walletconnect-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
171 lines (138 loc) · 5.62 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
### 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
## Environment variables used by the compose files
export PROJECT=$(project)
export $(shell sed 's/=.*//' setup)
### Makefile internal coordination
log_end=@echo "MAKE: Done with $@"; echo
flags=.makeFlags
VPATH=$(flags):build
$(shell mkdir -p $(flags))
.PHONY: help clean clean-all reset build
dockerizedNix=docker run --name builder --rm -v nix-store:/nix -v $(shell pwd):/src -w /src nixos/nix nix-shell -p bash --run
dockerLoad=docker load -i build/$@ \
| awk '{print $$NF}' \
| tee build/$@-img
copyResult=cp -r -f -L result build/$@ && rm -rf result
buildRelay=nix-build --attr relay.docker --argstr githash $(GITHASH) && $(copyResult)
WAKU_VERSION_TAG ?= v0.5.1
WAKU_SHA256 ?= 0k55hw1wqcyrpf9cxchhxdb92p75mmskkpvfn1paivl1r38pyb4a
buildWakuCommand:=nix-build ./ops/waku-docker.nix --argstr wakuVersionTag $(WAKU_VERSION_TAG) --argstr nixNimRepoSha256 $(WAKU_SHA256)
buildWaku=$(buildWakuCommand) && $(copyResult)
# 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}'
dirs:
mkdir -p build
mkdir -p $(flags)
pull: ## pulls docker images
docker pull $(redisImage)
ifeq (, $(shell which nix))
docker pull nixos/nix
endif
touch $(flags)/$@
$(log_end)
setup: ## configures domain and certbot email
@read -p 'Relay URL domain [localhost]: ' relay; \
echo "export RELAY_URL="$${relay:-localhost} > setup
@read -p 'Email for SSL certificate (default [email protected]): ' email; \
echo "export CERTBOT_EMAIL="$${email:[email protected]} >> setup
@read -p 'Paste your cloudflare API token: ' cf; \
echo "export CLOUDFLARE_TOKEN="$${cf} >> setup
$(log_end)
bootstrap-lerna: ## setups lerna for the monorepo management
npm i --include=dev
npm run bootstrap
touch $(flags)/$@
$(log_end)
build-lerna: bootstrap-lerna ## builds the npm packages in "./packages"
npm run build
touch $(flags)/$@
$(log_end)
build-relay: ## builds the relay using system npm
npm install --also=dev --prefix servers/relay
npm run build --prefix servers/relay
$(log_end)
nix-volume:
ifneq (, $(shell which nix))
docker volume create nix-store
endif
$(log_end)
build-img-relay: dirs nix-volume ## builds relay docker image inside of docker
ifeq (, $(shell which nix))
$(dockerizedNix) "$(buildRelay)"
else
$(buildRelay)
endif
$(dockerLoad)
$(log_end)
build-img-waku: dirs nix-volume ## builds waky docker image inside of docker
ifeq (, $(shell which nix))
$(dockerizedNix) "$(buildWaku)"
else
$(buildWaku)
endif
$(dockerLoad)
$(log_end)
build-images: build-img-relay build-img-waku
build: dirs build-images bootstrap-lerna build-relay build-react-app build-react-wallet ## builds all the packages and the containers for the relay
$(log_end)
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.com
TEST_RELAY_URL=wss://staging.walletconnect.com npm run test --prefix packages/client
test-production: build-lerna ## tests client against relay.walletconnect.com
TEST_RELAY_URL=wss://relay.walletconnect.com 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. Also needs waku nodes running locally
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
$(log_end)
predeploy: dirs pull build-images
touch $(flags)/$@
dev: predeploy ## runs relay on watch mode and shows logs
RELAY_MODE=any REPLICAS=1 MONITORING=false NODE_ENV=development $(MAKE) deploy
@echo "MAKE: Done with $@"
@echo
$(log_end)
ci: ## runs tests in github actions
printf "export RELAY_URL=localhost\nexport [email protected]\nexport CLOUDFLARE_TOKEN=\n" > setup
$(MAKE) dev
sleep 15
docker service logs --tail 100 $(project)_relay
TEST_RELAY_URL=ws://localhost:5000 $(MAKE) test-client
TEST_RELAY_URL=ws://localhost:5000 $(MAKE) test-relay
deploy: setup predeploy ## Deploys the docker swarm for the relay
bash ops/deploy.sh
$(log_end)
deploy-no-monitoring: setup predeploy ## same as deploy but without the monitoring
MONITORING=false bash ops/deploy.sh
$(log_end)
redeploy: setup clean predeploy ## redeploys the prodution containers and rebuilds them
docker service update --force --image $(relayImage) $(project)_relay
relay-logs: ## follows the relay container logs.
docker service logs -f --raw --tail 100 $(project)_relay
cachix: clean dirs ## pushes docker images to cachix
cachix push walletconnect $(shell $(buildRelay))
cachix push walletconnect $(shell $(buildWaku))
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
$(log_end)
reset: ## removes all build artifacts
rm -f setup
rm -rf build
$(log_end)
clean: ## removes all build outputs
rm -rf .makeFlags build result*
$(log_end)