This repository has been archived by the owner on Apr 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathmakefile
265 lines (211 loc) · 10.5 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
.PHONY: build test help
.DEFAULT_GOAL := help
NODE_ENV ?= development
ADMIN_NAME ?= sheldon
ADMIN_EMAIL ?= sheldon@newapp.com
ADMIN_PASSWORD ?= password
CLIENT_NAME ?= leonard
CLIENT_EMAIL ?= leonard@newapp.com
CLIENT_PASSWORD ?= password
PM2_HOME ?= .pm2
help:
grep -P '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
# Initialization ===============================================================
copy-conf: ## Initialize the configuration files by copying the *''-dist" versions (does not override existing config)
-cp -n ./config/${NODE_ENV}-dist.js ./config/${NODE_ENV}.js
ifeq ($(NODE_ENV), development)
-cp -n ./config/test-dist.js ./config/test.js
endif
install-npm-dependencies:
echo "Installing Node dependencies for environment $(NODE_ENV)"
npm install $(if $(filter production staging,$(NODE_ENV)),--production,)
ifeq ($(NODE_ENV), development)
make install-selenium
endif
install-selenium:
echo "Installing Selenium server"
./node_modules/.bin/selenium-standalone install --version=2.50.1 --drivers.chrome.version=2.24
install: copy-conf install-npm-dependencies install-selenium ## Install npm dependencies for the api, admin, and frontend apps
# Deployment ===================================================================
clear-build-admin: ## Remove precedent build files for admin
rm -rf ./build/admin/*
clear-build-frontend: ## Remove precedent build files for frontend
rm -rf ./build/frontend/*
build-admin: clear-build-admin ## Build admin application
echo "Building frontend application"
./node_modules/.bin/webpack \
--config ./src/admin/webpack.config.babel.js \
$(if $(filter production staging,$(NODE_ENV)),-p,-d) \
--progress
build-frontend: clear-build-frontend ## Build frontend application
echo "Building frontend application"
./node_modules/.bin/webpack \
--config ./src/frontend/webpack.config.babel.js \
$(if $(filter production staging,$(NODE_ENV)),-p,-d) \
--progress
build: build-frontend build-admin ## Build all front applications defined with webpack
clean: ## Remove only files ignored by Git
git clean --force -d -X
install-aws: ## Install the aws cli
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
unzip awscli-bundle.zip
sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
rm -rf ./awscli-bundle/ awscli-bundle.zip
aws configure
setup-server: ## Setup the server before deployment (specify NODE_ENV for correct fabricrc file loading)
fab --config=.fabricrc-$(NODE_ENV) setup_api check
deploy-api: ## Deploy the API (specify NODE_ENV for correct fabricrc file loading)
fab --config=.fabricrc-$(NODE_ENV) deploy_api
deploy-frontends: ## Deploy the frontend (specify NODE_ENV for correct fabricrc file loading)
fab --config=.fabricrc-$(NODE_ENV) deploy_static
deploy: deploy-api deploy-frontends ## Deploy the apps (specify NODE_ENV for correct fabricrc file loading)
# Development ==================================================================
run-dev: ## Run all applications in development environment (using webpack-dev-server)
PM2_HOME=$(PM2_HOME) node_modules/.bin/pm2 start ./config/pm2_servers/dev.json
echo "All apps started and running"
echo " API: http://localhost:3000"
echo " Frontend App: http://localhost:8080"
echo " Admin app: http://localhost:8081"
echo "Type 'make stop-dev' to stop the apps"
restart-dev: ## Restart all applications in development environment
PM2_HOME=$(PM2_HOME) node_modules/.bin/pm2 restart bpm_frontend-dev
PM2_HOME=$(PM2_HOME) node_modules/.bin/pm2 restart bpm_api-dev
echo "All apps restarted"
stop-dev: ## Stop all applications in development environment
PM2_HOME=$(PM2_HOME) node_modules/.bin/pm2 delete ./config/pm2_servers/dev.json
echo "All apps stopped"
restart-admin-dev: ## Restart the admin in development environment
PM2_HOME=$(PM2_HOME) node_modules/.bin/pm2 restart bpm_admin-dev
echo "Webpack dev restarted"
restart-api-dev: ## Restart the API in development environment
PM2_HOME=$(PM2_HOME) node_modules/.bin/pm2 restart bpm_api-dev
echo "API dev restarted"
restart-frontend-dev: ## Restart the frontend in development environment
PM2_HOME=$(PM2_HOME) node_modules/.bin/pm2 restart bpm_frontend-dev
echo "Webpack dev restarted"
run-api: ## Starts the API (you may define the NODE_ENV)
node ./src/api/index.js
servers-monitoring: ## Get an overview of your processes with PM2
PM2_HOME=$(PM2_HOME) node_modules/.bin/pm2 monit
servers-list: ## List the processes managed by PM2
PM2_HOME=$(PM2_HOME) node_modules/.bin/pm2 list
servers-stop-all: ## Stop all processes with PM2
PM2_HOME=$(PM2_HOME) node_modules/.bin/pm2 stop all
servers-clear-all: ## Delete all processes and flush the logs in PM2
PM2_HOME=$(PM2_HOME) node_modules/.bin/pm2 stop all
PM2_HOME=$(PM2_HOME) node_modules/.bin/pm2 delete all
PM2_HOME=$(PM2_HOME) node_modules/.bin/pm2 flush
log-admin-dev: ## Display the logs of the frontend applications with PM2
PM2_HOME=$(PM2_HOME) node_modules/.bin/pm2 logs bpm_admin-dev
log-api-dev: ## Display the logs of the API with PM2
PM2_HOME=$(PM2_HOME) node_modules/.bin/pm2 logs bpm_api-dev
log-frontend-dev: ## Display the logs of the frontend applications with PM2
PM2_HOME=$(PM2_HOME) node_modules/.bin/pm2 logs bpm_frontend-dev
log-admin-test: ## Display the logs of the admin with PM2 in test environment
PM2_HOME=$(PM2_HOME) node_modules/.bin/pm2 logs bpm_frontend-test
log-api-test: ## Display the logs of the API with PM2 in test environment
PM2_HOME=$(PM2_HOME) node_modules/.bin/pm2 logs bpm_api-test
log-frontend-test: ## Display the logs of the frontend with PM2 in test environment
PM2_HOME=$(PM2_HOME) node_modules/.bin/pm2 logs bpm_frontend-test
# Tests ========================================================================
run-debug-functionnal: reset-test-database ## Run all applications in test environment
NODE_ENV=test ${MAKE} build-admin
NODE_ENV=test ${MAKE} build-frontend
NODE_ENV=test ${MAKE} load-fixtures
PM2_HOME=$(PM2_HOME) node_modules/.bin/pm2 start ./config/pm2_servers/test.json
echo "All apps for tests started and running"
echo " API: http://localhost:3010"
echo " Frontend App: http://localhost:9080"
echo " Admin app: http://localhost:9081"
echo "Type 'make stop-debug-functionnal' to stop the apps"
stop-debug-functionnal: ## Stop all applications in development environment
PM2_HOME=$(PM2_HOME) node_modules/.bin/pm2 delete ./config/pm2_servers/test.json
echo "All apps stopped"
test-admin-unit: ## Run the admin application unit tests with mocha
NODE_ENV=test ./node_modules/.bin/mocha \
--require=async-to-gen/register \
--require='./src/admin/js/test.spec.js' \
--compilers="css:./src/common/e2e/lib/webpack-null-compiler,js:babel-core/register" \
"./src/admin/js/**/*.spec.js"
test-admin-functional: ## Run the frontend applications functional tests
NODE_ENV=test ${MAKE} build-admin
NODE_ENV=test ${MAKE} reset-test-database
NODE_ENV=test ${MAKE} load-fixtures
NODE_ENV=test SELENIUM_BROWSER_BINARY_PATH="./node_modules/selenium-standalone/.selenium/chromedriver/2.24-x64-chromedriver" \
./node_modules/.bin/mocha \
--require=reify \
--require=async-to-gen/register \
--recursive \
./src/admin/e2e
test-api-unit: ## Run the API unit tests with mocha
NODE_ENV=test NODE_PORT=3010 ./node_modules/.bin/mocha \
--require=reify \
--require=async-to-gen/register \
"./src/api/{,!(e2e)/**/}*.spec*.js"
test-api-functional: reset-test-database ## Run the API functional tests with mocha
NODE_ENV=test NODE_PORT=3010 ./node_modules/.bin/mocha \
--require=reify \
--require=async-to-gen/register \
--recursive \
./src/api/e2e
test-common-unit: ## Run the common directory unit tests with mocha
NODE_ENV=test ./node_modules/.bin/mocha \
--compilers="css:./src/common/e2e/lib/webpack-null-compiler,js:babel-core/register" \
"./src/common/{,**/}*.spec.js"
test-frontend-unit: ## Run the frontend application unit tests with mocha
NODE_ENV=test ./node_modules/.bin/mocha \
--require=async-to-gen/register \
--require='./src/frontend/js/test.spec.js' \
--compilers="css:./src/common/e2e/lib/webpack-null-compiler,js:babel-core/register" \
"./src/frontend/js/**/*.spec.js"
test-frontend-functional: ## Run the frontend applications functional tests
NODE_ENV=test ${MAKE} build-frontend
NODE_ENV=test ${MAKE} reset-test-database
NODE_ENV=test ${MAKE} load-fixtures
NODE_ENV=test SELENIUM_BROWSER_BINARY_PATH="./node_modules/selenium-standalone/.selenium/chromedriver/2.24-x64-chromedriver" \
./node_modules/.bin/mocha \
--require=reify \
--require=async-to-gen/register \
--recursive \
./src/frontend/e2e
test: ## Run all tests
-cp -n ./config/test-dist.js ./config/test.js
make test-common-unit
make test-frontend-unit
make test-admin-unit
make test-api-unit
make test-admin-functional
make test-api-functional
make test-frontend-functional
reset-test-database: ## Reset the test database and run all migrations
NODE_ENV=test ./node_modules/.bin/db-migrate \
--migrations-dir=./src/migrations \
--config=config/database.js \
-e api \
reset
NODE_ENV=test ./node_modules/.bin/db-migrate \
--migrations-dir=./src/migrations \
--config=config/database.js \
-e api \
up
# Migrations ===================================================================
migrate: ## Migrate the database defined in the configuration (you may define the NODE_ENV)
./node_modules/.bin/db-migrate \
--migrations-dir=./src/migrations \
--config=config/database.js \
-e api \
up
create-migration: ## Create a new migration (you may define the NODE_ENV to select a specific configuration)
./node_modules/.bin/db-migrate \
--migrations-dir=./src/migrations \
--config=config/database.js \
-e api \
create migration
load-fixtures: ## Load fixtures in the database (you may define the NODE_ENV to select a specific configuration)
./node_modules/.bin/babel-node ./bin/loadFixtures.js
# Binaries =====================================================================
create-admin: ## Create a new admin user in the database (you may define the NODE_ENV to select a specific configuration)
./node_modules/babel-cli/bin/babel-node.js ./bin/createAdmin.js ${ADMIN_NAME} ${ADMIN_EMAIL} ${ADMIN_PASSWORD}
create-client: ## Create a new user in the database (you may define the NODE_ENV to select a specific configuration)
# TODO: ensure we create a simple user and not an admin
./node_modules/babel-cli/bin/babel-node.js ./bin/createAdmin.js ${CLIENT_NAME} ${CLIENT_EMAIL} ${CLIENT_PASSWORD}