forked from degenfolio/degenfolio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
155 lines (121 loc) · 5.07 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
########################################
# 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/**"
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 --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 [[ "${CI_SERVER}" == "yes" ]]; then echo "--cache-from=$(project)_builder:latest,$(project)_proxy: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: adapters
dev: proxy adapters
prod: proxy server webserver
all: dev prod
start: dev
bash ops/start.sh
start-prod:
DEGENFOLIO_PROD=true bash ops/start.sh
stop:
bash ops/stop.sh
restart: dev stop
bash ops/start.sh
restart-prod: stop
DEGENFOLIO_PROD=true bash ops/start.sh
clean: stop
rm -rf build
rm -rf .flags/*
docker container prune -f
reset-images:
rm .flags/proxy .flags/webserver
purge: clean
rm -rf modules/*/node_modules
rm package-lock.json
push: push-commit
push-commit:
bash ops/push-images.sh $(commit)
push-semver:
bash ops/pull-images.sh $(commit)
bash ops/tag-images.sh $(semver)
bash ops/push-images.sh $(semver)
pull: pull-latest
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-adapters: adapters
bash ops/test-unit.sh adapters test
watch-adapters: adapters
bash ops/test-unit.sh adapters watch
########################################
# Real Build Rules
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
adapters: node-modules $(shell find modules/adapters/src $(find_options))
$(log_start)
$(docker_run) "cd modules/adapters && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
client-bundle: adapters $(shell find modules/client/src $(find_options))
$(log_start)
$(docker_run) "cd modules/client && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
server-bundle: adapters $(shell find modules/server/src $(find_options))
$(log_start)
$(docker_run) "cd modules/server && npm run build && touch src/entry.ts"
$(log_finish) && mv -f $(totalTime) .flags/$@
########################################
# Docker Images
webserver: client-bundle $(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/$@
server: server-bundle $(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/$@
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/$@
ssh-action: $(shell find ops/ssh-action $(find_options))
$(log_start)
docker build --file ops/ssh-action/Dockerfile --tag $(project)_ssh_action ops/ssh-action
docker tag $(project)_ssh_action $(project)_ssh_action:$(commit)
$(log_finish) && mv -f $(totalTime) .flags/$@