-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
247 lines (194 loc) · 7.59 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
########################################
# Setup Env
# Specify make-specific variables (VPATH = prerequisite search path)
VPATH=.flags
SHELL=/bin/bash
root=$(shell cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )
project=$(shell cat $(root)/package.json | jq .name | tr -d '"')
find_options=-type f -not -path "**/node_modules/**" -not -path "**/.*" -not -path "**/dist/**" -not -name "*.pdf"
cwd=$(shell pwd)
commit=$(shell git rev-parse HEAD | head -c 8)
semver=v$(shell cat package.json | grep '"version":' | awk -F '"' '{print $$4}')
# Setup docker run time
# If on Linux, give the container our uid & gid so we know what to reset permissions to
# On Mac, the docker-VM takes care of this for us so pass root's id (ie noop)
my_id=$(shell id -u):$(shell id -g)
id=$(shell if [[ "`uname`" == "Darwin" ]]; then echo 0:0; else echo $(my_id); fi)
interactive=$(shell if [[ -t 0 && -t 2 ]]; then echo "--interactive"; else echo ""; fi)
docker_run=docker run --env=CI=${CI} --name=$(project)_builder $(interactive) --tty --rm --volume=$(cwd):/root $(project)_builder $(id)
# Pool of images to pull cached layers from during docker build steps
image_cache=$(shell if [[ -n "${CI}" || "${CI_SERVER}" == "yes" ]]; then echo "--cache-from=$(project)_builder:latest,$(project)_proxy:latest,$(project)_server:latest,$(project)_webserver:latest"; else echo ""; fi)
# Helper functions
startTime=.flags/.startTime
totalTime=.flags/.totalTime
log_start=@echo "=============";echo "[Makefile] => Start building $@"; date "+%s" > $(startTime)
log_finish=@echo $$((`date "+%s"` - `cat $(startTime)`)) > $(totalTime); rm $(startTime); echo "[Makefile] => Finished building $@ in `cat $(totalTime)` seconds";echo "=============";echo
# Create output folders
$(shell mkdir -p .flags)
########################################
# Command & Control Aliases
default: dev
dev: proxy package
prod: proxy server-image webserver
all: dev prod
start: dev
bash ops/start.sh
start-prod:
VM_PROD=true bash ops/start.sh
start-storybook: react
bash ops/start-storybook.sh
stop:
bash ops/stop.sh
restart: dev stop
bash ops/start.sh
restart-prod: stop
VM_PROD=true bash ops/start.sh
restart-storybook:
docker container stop $(project)_storybook
bash ops/start-storybook.sh
clean: stop
rm -rf modules/*/build
rm -rf modules/*/dist
rm -rf modules/*/node_modules
rm -rf modules/*/.rollup.cache
rm -rf .flags/*
docker container prune -f
reset-images:
rm -f .flags/proxy .flags/server-image .flags/webserver
purge: clean
rm -rf package-lock.json
push-commit:
bash ops/push-images.sh latest
bash ops/push-images.sh $(commit)
push-semver:
bash ops/tag-images.sh $(semver)
bash ops/push-images.sh $(semver)
pull-latest:
bash ops/pull-images.sh latest
pull-commit:
bash ops/pull-images.sh $(commit)
pull-semver:
bash ops/pull-images.sh $(semver)
dls:
@docker service ls && echo '=====' && docker container ls -a
lint:
bash ops/lint.sh
test-utils: utils
bash ops/test-unit.sh utils test
watch-utils: types
bash ops/test-unit.sh utils watch
test-transactions: transactions
bash ops/test-unit.sh transactions test
watch-transactions: utils
bash ops/test-unit.sh transactions watch
test-core: core
bash ops/test-unit.sh core test
watch-core: transactions
bash ops/test-unit.sh core watch
test-prices: prices
bash ops/test-unit.sh prices test
watch-prices: core
bash ops/test-unit.sh prices watch
test-taxes: taxes
bash ops/test-unit.sh taxes test
watch-taxes: prices
bash ops/test-unit.sh taxes watch
test-react: react
bash ops/test-ui.sh react test
watch-react: taxes
bash ops/test-ui.sh react watch
run-example: package
bash ops/test-unit.sh package test
test-all: package
bash ops/test-unit.sh utils test
@sleep 1
bash ops/test-unit.sh transactions test
@sleep 1
bash ops/test-unit.sh core test
@sleep 1
bash ops/test-unit.sh prices test
@sleep 1
bash ops/test-unit.sh taxes test
@sleep 1
bash ops/test-unit.sh package test
@sleep 1
bash ops/lint.sh
publish: package
bash ops/npm-publish.sh
deploy:
bash ops/deploy.sh
########################################
# Common Prerequisites
builder: $(shell find ops/builder $(find_options))
$(log_start)
docker build --file ops/builder/Dockerfile $(image_cache) --tag $(project)_builder:latest ops/builder
docker tag $(project)_builder:latest $(project)_builder:$(commit)
$(log_finish) && mv -f $(totalTime) .flags/$@
node-modules: builder package.json $(shell find modules/*/package.json $(find_options))
$(log_start)
$(docker_run) "lerna bootstrap --hoist"
$(log_finish) && mv -f $(totalTime) .flags/$@
########################################
# Typescript -> Javascript
types: node-modules $(shell find modules/types $(find_options))
$(log_start)
$(docker_run) "cd modules/types && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
utils: types $(shell find modules/utils $(find_options))
$(log_start)
$(docker_run) "cd modules/utils && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
transactions: utils types $(shell find modules/transactions $(find_options))
$(log_start)
$(docker_run) "cd modules/transactions && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
core: transactions utils types $(shell find modules/core $(find_options))
$(log_start)
$(docker_run) "cd modules/core && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
prices: core $(shell find modules/prices $(find_options))
$(log_start)
$(docker_run) "cd modules/prices && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
taxes: prices core transactions utils types $(shell find modules/taxes $(find_options))
$(log_start)
$(docker_run) "cd modules/taxes && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
react: taxes prices core transactions utils types $(shell find modules/react/src $(find_options))
$(log_start)
$(docker_run) "cd modules/react && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
package: react prices core transactions utils types $(shell find modules/package $(find_options))
$(log_start)
$(docker_run) "cd modules/package && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
client: package modules/client/.env $(shell find modules/client $(find_options))
$(log_start)
$(docker_run) "cd modules/client && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
server: package $(shell find modules/server $(find_options))
$(log_start)
$(docker_run) "cd modules/server && npm run build && touch src/index.ts"
$(log_finish) && mv -f $(totalTime) .flags/$@
########################################
# Build docker images
proxy: $(shell find ops/proxy $(find_options))
$(log_start)
docker build --file ops/proxy/Dockerfile $(image_cache) --tag $(project)_proxy ops/proxy
docker tag $(project)_proxy $(project)_proxy:$(commit)
$(log_finish) && mv -f $(totalTime) .flags/$@
server-image: server $(shell find modules/server/ops $(find_options))
$(log_start)
docker build --file modules/server/ops/Dockerfile $(image_cache) --tag $(project) modules/server
docker tag $(project) $(project):$(commit)
$(log_finish) && mv -f $(totalTime) .flags/$@
webserver: client $(shell find modules/client/ops $(find_options))
$(log_start)
docker build --file modules/client/ops/Dockerfile $(cache_from) --tag $(project)_webserver:latest modules/client
docker tag $(project)_webserver:latest $(project)_webserver:$(commit)
$(log_finish) && mv -f $(totalTime) .flags/$@
########################################
# Extra rules
ssh-action: $(shell find ops/ssh-action $(find_options))
docker build --file ops/ssh-action/Dockerfile --tag $(project)_ssh_action ops/ssh-action
docker tag $(project)_ssh_action $(project)_ssh_action:$(commit)