-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
172 lines (142 loc) · 6.24 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
include .env
##############################################################################
# Docs
##############################################################################
help: FORCE # Source: https://stackoverflow.com/a/59087509
@grep -B1 -E "^[a-zA-Z0-9_-]+\:([^\=]|$$)" Makefile \
| grep -v -- -- \
| sed 'N;s/\n/###/' \
| sed -n 's/^#: \(.*\)###\(.*\):.*/\2###\1/p' \
| column -t -s '###'
##############################################################################
# This will detect the correct system, except if you're using WSL.
# For WSL, make sure to set WSL=1 in your .env file or environment.
##############################################################################
UNAME := $(shell uname -s)
DOCKER_HOST_IP = host.docker.internal
ifeq ($(UNAME),Linux)
ifeq ($(WSL),0)
DOCKER_HOST_IP = $(shell ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+')
endif
endif
#: Prints docker info
docker-info: FORCE
@echo UNAME: $(UNAME)
@echo WSL: $(WSL)
@echo DOCKER_HOST_IP: $(DOCKER_HOST_IP)
##############################################################################
# Check if binary exists
##############################################################################
DOC_INSTALL_yarn="Please install yarn using npm -g install yarn"
DOC_INSTALL_docker-compose="Please install docker-compose using make install-docker-compose"
bin-exists: FORCE
bin-exists-%: FORCE
$(eval INSTRUCTIONS := $(if $(DOC_INSTALL_$*),$(DOC_INSTALL_$*),"Please install $*"))
@command -v $* >/dev/null 2>&1 || echo $(INSTRUCTIONS)
##############################################################################
# Check node version
##############################################################################
NODE_VERSION=14.0.0
check-node-version: FORCE
@if [ $(shell node --version) != v$(NODE_VERSION) ]; then\
echo "ERROR: Databrary recommends node v$(NODE_VERSION).";\
echo "We also recommend nvm and running";\
echo " nvm install $(NODE_VERSION)";\
echo " nvm use $(NODE_VERSION)";\
fi;
##############################################################################
# Setup rules and targets for yarn installs
##############################################################################
JS_DIRS=client server
define install-js-rule
$(1)/node_modules: $(1)/package.json $(1)/yarn.lock
@cd $(1) && yarn && touch node_modules && cd ..
endef
$(foreach dir,$(JS_DIRS),$(eval $(call install-js-rule,$(dir))))
##############################################################################
# Maintenance Rules
##############################################################################
upgrade-quasar: FORCE
cd client && npx quasar upgrade && npx quasar upgrade --install && cd ..
upgrade-hasura-cli: FORCE
cd hasura && hasura update-cli && hasura scripts update-project-v2 && cd ..
##############################################################################
# Hasura
##############################################################################
#: Start hasura console for live persistence of migrations
migrate: FORCE check-node-version bin-exists-yarn hasura/node_modules
cd hasura && yarn hasura:console && cd ..
metadata: FORCE check-node-version bin-exists-yarn hasura/node_modules
cd hasura && yarn hasura:metadata:export && cd ..
##############################################################################
# Minio
##############################################################################
MINIO_IMAGE=minio-cli
MINIO_DIR=./docker-assets/$(MINIO_IMAGE)
check-image-minio-cli: FORCE
@if [ -z "$$(docker images -q $(MINIO_IMAGE):latest 2> /dev/null)" ]; then\
touch $(MINIO_DIR)/Dockerfile;\
fi
$(MINIO_DIR): $(MINIO_DIR)/Dockerfile $(MINIO_DIR)/bootstrap.sh
@docker build -t $(MINIO_IMAGE) $(MINIO_DIR)/
@touch $@
setup_minio: check-image-minio-cli $(MINIO_DIR)
@docker run\
--env=DOCKER_HOST_IP=$(DOCKER_HOST_IP)\
--env-file=./.env\
--network="host"\
-it $(MINIO_IMAGE)
##############################################################################
# Some prerequesities until we get everything dockerfied
###############################################################################
install-nvm: FORCE
ifeq ($(wildcard $(NVM_DIR)),)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
nvm install node
endif
install-make: FORCE
ifeq ($(shell dpkg -l | cut -d " " -f 3 | grep "^make"),)
sudo apt-get install makdde
endif
install-docker-compose: FORCE
ifeq ($(shell command -v docker-compose 2> /dev/null),)
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
endif
install-hasura-cli: FORCE
ifeq ($(shell command -v hasura 2> /dev/null),)
curl -L https://github.com/hasura/graphql-engine/raw/master/cli/get.sh | bash
endif
#: Install dependencies, some of which require sudo, for an ~Ubuntu machine
install-ubuntu-dependencies: install-docker-compose install-nvm install-make install-hasura-cli
###############################################################################
# Primary commands for this app
###############################################################################
start_docker: bin-exists-docker-compose
DOCKER_HOST_IP=$(DOCKER_HOST_IP) docker-compose up -d
stop_docker: bin-exists-docker-compose
docker-compose stop
#: Destroy all docker images and thus databases
cleardb: bin-exists-docker-compose
docker-compose down -v
#: Start docker in non-deamon mode
docker: bin-exists-docker-compose
DOCKER_HOST_IP=$(DOCKER_HOST_IP) docker-compose up
#: Start the Nest.js server in non-daemon mode
server: check-node-version bin-exists-yarn server/node_modules
cd server && rm -rf dist && npm run start:dev && cd ..
server_test: FORCE
cd server && npm run test && cd ..
server_debug: check-node-version bin-exists-yarn server/node_modules
cd server && npm run start:debug && cd ..
#: Start the front-end in non-daemon mode
client: check-node-version bin-exists-yarn client/node_modules
cd client && npm run dev && cd ..
fix_es_lint: FORCE
npx eslint --ext .ts . --fix
generate_funders: FORCE bin-exists-yarn server/node_modules
cd server && yarn generate:funders && cd ..
##############################################################################
all: ;
FORCE: ;
.PHONY: FORCE