-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
141 lines (109 loc) · 4.28 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
# Specify make-specific variables (VPATH = prerequisite search path)
VPATH=.flags
SHELL=/bin/bash
dir=$(shell cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )
project=$(shell cat $(dir)/package.json | jq .name | tr -d '"')
find_options=-type f -not -path "*/node_modules/*" -not -path "*/dist/*" -not -name "*.swp" -not -path "*/.*" -not -name "*.log"
semver=v$(shell cat package.json | grep '"version":' | awk -F '"' '{print $$4}')
commit=$(shell git rev-parse HEAD | head -c 8)
user=$(shell if [[ -n "${CI_PROJECT_NAMESPACE}" ]]; then echo "${CI_PROJECT_NAMESPACE}"; else echo "`whoami`"; fi)
registry=registry.gitlab.com/$(user)/$(project)
# Pool of images to pull cached layers from during docker build steps
cache_from=$(shell if [[ -n "${CI}" ]]; then echo "--cache-from=$(project)_server:$(commit),$(project)_server:latest,$(project)_builder:latest,$(project)_proxy:$(commit),$(project)_proxy:latest"; else echo ""; fi)
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
# Env setup
$(shell mkdir -p .flags)
########################################
# Command & Control Shortcuts
default: dev
all: dev prod
dev: server proxy
prod: dev webserver server-image
start: dev
bash ops/start.sh
start-prod: dev
export BLOG_PROD=true; bash ops/start.sh
restart: stop
bash ops/start.sh
stop:
bash ops/stop.sh
clean: stop
docker container prune -f
rm -rf .flags
rm -rf modules/**/build
rm -rf modules/**/dist
reset: stop
docker container prune -f
rm -rf .docker-compose.yml
rm -rf .blog-content.git .test-content .test-content.git
rm -rf .bash_history .config
purge: clean reset
push: push-commit
push-commit:
bash ops/push-images.sh $(commit)
bash ops/push-images.sh latest
push-semver:
bash ops/pull-images.sh $(commit)
bash ops/tag-images.sh $(semver)
bash ops/push-images.sh $(semver)
bash ops/push-images.sh latest
pull:
bash ops/pull-images.sh latest
pull-commit:
bash ops/pull-images.sh $(commit)
pull-semver:
bash ops/pull-images.sh $(semver)
build-report:
bash ops/build-report.sh
dls:
@docker service ls && echo '=====' && docker container ls -a
lint:
bash ops/lint.sh
deploy:
bash ops/deploy.sh
test-server: server
bash ops/test/server.sh test
watch-server: node-modules
bash ops/test/server.sh watch
test-client:
bash ops/test/client.sh test
watch-client:
bash ops/test/client.sh watch
########################################
# Common Prerequisites
builder: $(shell find ops/builder $(find_options))
$(log_start)
docker build --file ops/builder/Dockerfile $(cache_from) --tag $(project)_builder ops/builder
docker tag $(project)_builder $(project)_builder:$(commit)
$(log_finish) && mv -f $(totalTime) .flags/$@
node-modules: builder package.json $(shell ls modules/**/package.json)
bash ops/maketh.sh $@
########################################
# Compile/Transpile src
types: node-modules $(shell find modules/types $(find_options))
bash ops/maketh.sh $@
server: types $(shell find modules/server $(find_options))
touch modules/server/src/index.ts
bash ops/maketh.sh $@
client: types $(shell find modules/client $(find_options))
bash ops/maketh.sh $@
########################################
# Build docker images
proxy: $(shell find ops/proxy $(find_options))
$(log_start)
docker build --file ops/proxy/Dockerfile $(cache_from) --tag $(project)_proxy:latest ops/proxy
docker tag $(project)_proxy:latest $(project)_proxy:$(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/$@
server-image: server $(shell find modules/server/ops $(find_options))
$(log_start)
docker build --file modules/server/ops/Dockerfile $(cache_from) --tag $(project)_server:latest modules/server
docker tag $(project)_server:latest $(project)_server:$(commit)
$(log_finish) && mv -f $(totalTime) .flags/$@