-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
301 lines (239 loc) · 12.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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# Copyright (c) 2024, DjaoDjin inc.
# see LICENSE
-include $(buildTop)/share/dws/prefix.mk
APP_NAME ?= $(notdir $(abspath $(srcDir)))
APP_PORT ?= 8000
srcDir ?= .
installTop ?= $(if $(VIRTUAL_ENV),$(VIRTUAL_ENV),$(abspath $(srcDir))/.venv)
binDir ?= $(installTop)/bin
libDir ?= $(installTop)/lib
SYSCONFDIR ?= $(installTop)/etc
LOCALSTATEDIR ?= $(installTop)/var
CONFIG_DIR ?= $(SYSCONFDIR)/$(APP_NAME)
ASSETS_DIR ?= $(srcDir)/htdocs/static
# because we are not loading DB_NAME from site.conf
RUN_DIR ?= $(abspath $(srcDir))
installDirs ?= /usr/bin/install -d
installFiles ?= /usr/bin/install -p -m 644
DOCKER ?= docker
ESCHECK ?= eslint es5
NPM ?= npm
PIP ?= pip
PYTHON ?= python
SASSC ?= sassc --style=compressed --source-map-urls absolute
SQLITE ?= sqlite3
WEBPACK ?= NODE_PATH=$(libDir)/node_modules webpack --stats-error-details
#WEBPACK ?= webpack --stats verbose
#WEBPACK ?= webpack --profile --json > build.json
# Django 1.7,1.8 sync tables without migrations by default while Django 1.9
# requires a --run-syncdb argument.
# Implementation Note: We have to wait for the config files to be installed
# before running the manage.py command (else missing SECRECT_KEY).
MANAGE := DJAOPSP_SETTINGS_LOCATION=$(CONFIG_DIR) $(PYTHON) manage.py
RUNSYNCDB = $(if $(findstring --run-syncdb,$(shell cd $(srcDir) && $(MANAGE) migrate --help 2>/dev/null)),--run-syncdb,)
ifneq ($(wildcard $(CONFIG_DIR)/site.conf),)
# `make initdb` will install site.conf but only after `grep` is run
# and DB_FILENAME set to "". We use the default value in the template site.conf
# here to prevent that issue.
DB_FILENAME ?= $(shell grep ^DB_NAME $(CONFIG_DIR)/site.conf | cut -f 2 -d '"')
else
DB_FILENAME ?= $(RUN_DIR)/db.sqlite
endif
MY_EMAIL ?= $(shell cd $(srcDir) && git config user.email)
EMAIL_FIXTURE_OPT := $(if $(MY_EMAIL),--email="$(MY_EMAIL)",)
# We generate the SECRET_KEY this way so it can be overriden
# in test environments.
SECRET_KEY ?= $(shell $(PYTHON) -c 'import sys ; from random import choice ; sys.stdout.write("".join([choice("abcdefghijklmnopqrstuvwxyz0123456789!@\#$%^*-_=+") for i in range(50)]))' )
DJAODJIN_SECRET_KEY ?= $(shell $(PYTHON) -c 'import sys ; from random import choice ; sys.stdout.write("".join([choice("abcdefghijklmnopqrstuvwxyz0123456789!@\#$%^*-_=+") for i in range(50)]))' )
.PHONY: build-assets doc generateschema initdb makemessages setup-livedemo vendor-assets-prerequisites
all:
@echo "Nothing to be done for 'make'."
# We are installing the overridden vendor files along with the ones installed
# from node_modules.
# Implementation note: chart.js is a directory. chartjs-plugin-annotation.js
# is not ES5 compatible.
build-assets: $(ASSETS_DIR)/cache/app.css \
$(ASSETS_DIR)/cache/email.css \
$(ASSETS_DIR)/cache/assess.js
cd $(srcDir) && DEBUG=0 $(MANAGE) collectstatic --noinput
$(installFiles) $(srcDir)/djaopsp/static/vendor/djaodjin-dashboard.js $(ASSETS_DIR)/vendor
$(installFiles) $(srcDir)/djaopsp/static/vendor/djaodjin-menubar.js $(ASSETS_DIR)/vendor
$(installFiles) $(srcDir)/djaopsp/static/vendor/hallo.js $(ASSETS_DIR)/vendor
$(installFiles) $(srcDir)/djaopsp/static/vendor/jquery-ui.js $(ASSETS_DIR)/vendor
$(installFiles) $(srcDir)/djaopsp/static/vendor/djaoapp-i18n.js $(ASSETS_DIR)/vendor
rm -rf $(srcDir)/htdocs/static/vendor/chart.js $(srcDir)/htdocs/static/vendor/chartjs-plugin-annotation.js
cd $(srcDir) && $(ESCHECK) htdocs/static/cache/*.js htdocs/static/vendor/*.js -v
clean: clean-dbs
[ ! -f $(srcDir)/package-lock.json ] || rm $(srcDir)/package-lock.json
find $(srcDir) -name '__pycache__' -exec rm -rf {} +
find $(srcDir) -name '*~' -exec rm -rf {} +
doc: schema.yml
$(installDirs) build/docs
cd $(srcDir) && sphinx-build -b html ./docs $(PWD)/build/docs
generateschema: schema.yml
# We add a `load_test_transactions` because the command will set the current
# site and thus need the rules.App table.
initdb:
-[ -f $(DB_FILENAME) ] && rm -f $(DB_FILENAME)
$(installDirs) $(dir $(DB_FILENAME))
cd $(srcDir) && $(MANAGE) migrate $(RUNSYNCDB) --noinput
cd $(srcDir) && $(MANAGE) loadfixtures $(EMAIL_FIXTURE_OPT) \
djaopsp/fixtures/engineering-si-units.json \
djaopsp/fixtures/engineering-alt-units.json \
djaopsp/fixtures/accounts.json \
djaopsp/fixtures/content.json \
djaopsp/fixtures/practices.json \
djaopsp/fixtures/practices_custom_choices.json \
djaopsp/fixtures/matrices.json \
djaopsp/fixtures/samples.json \
djaopsp/fixtures/100-completed-notshared.json \
djaopsp/fixtures/800-data-series.json
setup-livedemo: initdb
install:: install-conf
makemessages:
cd $(srcDir) && $(MANAGE) makemessages -l fr -l es -l pt --symlinks --no-wrap
cd $(srcDir) && $(MANAGE) makemessages -d djangojs -l fr -l es -l pt --symlinks --no-wrap
ifeq ($(MY_EMAIL),)
.PHONY: package-docker
# We build a local sqlite3 database to be packaged with the Docker image
# such that the container can be started without prior configuration.
package-docker: build-assets initdb
[[ -f $(srcDir)/db.sqlite ]] || cp $(DB_FILENAME) $(srcDir)/db.sqlite
cd $(srcDir) && $(DOCKER) build $(DOCKER_OPTS) .
endif
# we remove the build directory to make sure we don't have extra files remaining
# when we excluded them in the package_theme command line. We also insures
# we are not removing important directories in the src tree by running
# the condition: `[ "$(abspath $(objDir))" != "$(abspath $(srcDir))" ]`.
package-theme: build-assets
[ "$(abspath $(objDir))" != "$(abspath $(srcDir))" ] && rm -rf $(objDir)/$(APP_NAME)
cd $(srcDir) && DEBUG=0 FEATURES_REVERT_TO_DJANGO=0 \
$(MANAGE) package_theme \
--build_dir=$(objDir) --install_dir=$(srcDir)/dist \
--exclude='_form.html' --exclude='_form_fields.html' \
--exclude='_params_start_at_field.html' \
--exclude='_params_ends_at_field.html' --exclude='_filter.html' \
--exclude='_pagination.html' --exclude='.*/'
# Once tests are completed, run 'coverage report'.
run-coverage: initdb
cd $(srcDir) && coverage run --source='.,deployutils,pages,survey,' \
manage.py runserver $(APP_PORT) --noreload
# Download prerequisites specified in package.json and install relevant files
# in the directory assets are served from.
vendor-assets-prerequisites: $(libDir)/.npm/$(APP_NAME)-packages
# --------- intermediate targets
clean-dbs:
[ ! -f $(DB_FILENAME) ] || rm $(DB_FILENAME)
# The chart.js in node_modules/chart.js/dist/chart.js does not pass
# `es-check es5`. The webpack.config.js file rules loader excludes
# `node_modules` from babel, so we install chart.js in $srcDir here.
$(libDir)/.npm/$(APP_NAME)-packages: $(srcDir)/package.json
$(installFiles) $^ $(libDir)
$(NPM) install --loglevel verbose --cache $(libDir)/.npm --tmp $(libDir)/tmp --prefix $(libDir)
$(installDirs) $(ASSETS_DIR)/fonts $(ASSETS_DIR)/vendor
$(installFiles) $(libDir)/node_modules/bootstrap/dist/js/bootstrap.min.js $(ASSETS_DIR)/vendor
cp -rf $(libDir)/node_modules/chart.js $(srcDir)/djaopsp/static/vendor
$(installFiles) $(libDir)/node_modules/chartjs-plugin-annotation/dist/chartjs-plugin-annotation.js $(srcDir)/djaopsp/static/vendor
$(installFiles) $(libDir)/node_modules/dropzone/dist/dropzone.css $(ASSETS_DIR)/vendor
$(installFiles) $(libDir)/node_modules/dropzone/dist/dropzone.js $(ASSETS_DIR)/vendor
$(installFiles) $(libDir)/node_modules/font-awesome/css/font-awesome.css $(ASSETS_DIR)/vendor
$(installFiles) $(libDir)/node_modules/font-awesome/fonts/* $(ASSETS_DIR)/fonts
$(installFiles) $(libDir)/node_modules/jquery/dist/jquery.js $(ASSETS_DIR)/vendor
$(installFiles) $(libDir)/node_modules/moment/moment.js $(ASSETS_DIR)/vendor
$(installFiles) $(libDir)/node_modules/moment-timezone/builds/moment-timezone-with-data.js $(ASSETS_DIR)/vendor
$(installFiles) $(libDir)/node_modules/@popperjs/core/dist/umd/popper.min.js* $(ASSETS_DIR)/vendor
$(installFiles) $(libDir)/node_modules/vue/dist/vue.js $(ASSETS_DIR)/vendor
$(installFiles) $(libDir)/node_modules/lodash/lodash.js $(ASSETS_DIR)/vendor
[ -e $(binDir)/eslint ] || (cd $(binDir) && ln -s ../lib/node_modules/.bin/eslint eslint)
[ -f $(binDir)/sassc ] || (cd $(binDir) && ln -s ../lib/node_modules/.bin/sass sassc)
[ -f $(binDir)/swagger-cli ] || (cd $(binDir) && ln -s ../lib/node_modules/.bin/swagger-cli swagger-cli)
[ -f $(binDir)/webpack ] || (cd $(binDir) && ln -s ../lib/node_modules/.bin/webpack webpack)
touch $@
schema.yml:
cd $(srcDir) && DEBUG=0 API_DEBUG=1 OPENAPI_SPEC_COMPLIANT=1 \
$(MANAGE) spectacular --color --file $@ --validate
cd $(srcDir) && swagger-cli validate $@
$(ASSETS_DIR)/cache/assess.js: $(srcDir)/webpack.config.js \
webpack-conf-paths.json \
$(wildcard $(srcDir)/djaopsp/static/js/*.js)
cd $(srcDir) && $(WEBPACK) -c $<
webpack-conf-paths.json: $(srcDir)/djaopsp/settings.py
cd $(srcDir) && $(MANAGE) generate_webpack_paths -o $@
$(ASSETS_DIR)/cache/app.css: \
$(wildcard $(srcDir)/djaopsp/static/scss/vendor/bootstrap/*.scss) \
$(wildcard $(srcDir)/djaopsp/static/scss/vendor/djaodjin/*.scss) \
$(wildcard $(srcDir)/djaopsp/static/scss/vendor/*.scss) \
$(wildcard $(srcDir)/djaopsp/static/scss/base/*.scss)
cd $(srcDir) && $(SASSC) djaopsp/static/scss/base/base.scss $@
$(ASSETS_DIR)/cache/email.css: \
$(wildcard $(srcDir)/djaopsp/static/scss/email/*.scss)
cd $(srcDir) && $(SASSC) djaopsp/static/scss/email/email.scss $@
$(srcDir)/djaopsp/locale/fr/LC_MESSAGES/django.mo: \
$(wildcard $(srcDir)/djaopsp/locale/es/LC_MESSAGES/*.po) \
$(wildcard $(srcDir)/djaopsp/locale/fr/LC_MESSAGES/*.po) \
$(wildcard $(srcDir)/djaopsp/locale/pt/LC_MESSAGES/*.po)
cd $(srcDir) && $(MANAGE) compilemessages
install-conf:: $(DESTDIR)$(CONFIG_DIR)/credentials \
$(DESTDIR)$(CONFIG_DIR)/site.conf \
$(DESTDIR)$(CONFIG_DIR)/gunicorn.conf \
$(DESTDIR)$(SYSCONFDIR)/sysconfig/$(APP_NAME) \
$(DESTDIR)$(SYSCONFDIR)/logrotate.d/$(APP_NAME) \
$(DESTDIR)$(SYSCONFDIR)/monit.d/$(APP_NAME) \
$(DESTDIR)$(SYSCONFDIR)/systemd/system/$(APP_NAME).service \
$(DESTDIR)$(libDir)/tmpfiles.d/$(APP_NAME).conf
$(installDirs) $(DESTDIR)$(LOCALSTATEDIR)/db
$(installDirs) $(DESTDIR)$(LOCALSTATEDIR)/log/gunicorn
[ -d $(DESTDIR)$(LOCALSTATEDIR)/run ] || $(installDirs) $(DESTDIR)$(LOCALSTATEDIR)/run
# Implementation Note:
# We use [ -f file ] before install here such that we do not blindly erase
# already present configuration files with template ones.
$(DESTDIR)$(CONFIG_DIR)/site.conf: $(srcDir)/etc/site.conf
$(installDirs) $(dir $@)
[ -f $@ ] || \
sed -e 's,%(LOCALSTATEDIR)s,$(LOCALSTATEDIR),' \
-e 's,%(SYSCONFDIR)s,$(SYSCONFDIR),' \
-e 's,%(APP_NAME)s,$(APP_NAME),' \
-e "s,%(ADMIN_EMAIL)s,$(MY_EMAIL)," \
-e 's,%(installTop)s,$(installTop),' \
-e "s,%(DB_NAME)s,$(APP_NAME)," \
-e "s,%(DB_FILENAME)s,$(DB_FILENAME)," \
-e "s,%(binDir)s,$(binDir)," $< > $@
$(DESTDIR)$(CONFIG_DIR)/credentials: $(srcDir)/etc/credentials
$(installDirs) $(dir $@)
[ -e $@ ] || sed \
-e "s,\%(SECRET_KEY)s,`$(PYTHON) -c 'import sys ; from random import choice ; sys.stdout.write("".join([choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$%^*-_=+") for i in range(50)]))'`," \
$< > $@
$(DESTDIR)$(CONFIG_DIR)/gunicorn.conf: $(srcDir)/etc/gunicorn.conf
$(installDirs) $(dir $@)
[ -e $@ ] || sed \
-e 's,%(LOCALSTATEDIR)s,$(LOCALSTATEDIR),' \
-e 's,%(APP_NAME)s,$(APP_NAME),g' \
-e 's,%(APP_PORT)s,$(APP_PORT),' $< > $@
$(DESTDIR)$(SYSCONFDIR)/systemd/system/%.service: \
$(srcDir)/etc/service.conf
$(installDirs) $(dir $@)
[ -e $@ ] || sed \
-e 's,%(srcDir)s,$(srcDir),' \
-e 's,%(APP_NAME)s,$(APP_NAME),g' \
-e 's,%(binDir)s,$(binDir),' \
-e 's,%(SYSCONFDIR)s,$(SYSCONFDIR),' \
-e 's,%(CONFIG_DIR)s,$(CONFIG_DIR),' \
-e 's,%(LOCALSTATEDIR)s,$(LOCALSTATEDIR),' $< > $@
$(DESTDIR)$(SYSCONFDIR)/logrotate.d/%: $(srcDir)/etc/logrotate.conf
$(installDirs) $(dir $@)
[ -e $@ ] || sed \
-e 's,%(APP_NAME)s,$(APP_NAME),g' \
-e 's,%(LOCALSTATEDIR)s,$(LOCALSTATEDIR),' $< > $@
$(DESTDIR)$(SYSCONFDIR)/monit.d/%: $(srcDir)/etc/monit.conf
$(installDirs) $(dir $@)
[ -e $@ ] || sed \
-e 's,%(APP_NAME)s,$(APP_NAME),g' \
-e 's,%(APP_PORT)s,$(APP_NAME),g' \
-e 's,%(LOCALSTATEDIR)s,$(LOCALSTATEDIR),' $< > $@
$(DESTDIR)$(SYSCONFDIR)/sysconfig/%: $(srcDir)/etc/sysconfig.conf
$(installDirs) $(dir $@)
[ -e $@ ] || install -p -m 644 $< $@
$(DESTDIR)$(libDir)/tmpfiles.d/$(APP_NAME).conf: $(srcDir)/etc/tmpfiles.conf
$(installDirs) $(dir $@)
[ -e $@ ] || sed \
-e 's,%(APP_NAME)s,$(APP_NAME),g' $< > $@