forked from inosca/ebau
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
289 lines (229 loc) · 10.3 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
SHELL:=/bin/sh
include .env
# http://clarkgrubb.com/makefile-style-guide#phony-targets
.DEFAULT_GOAL := help
GIT_USER=$(shell git config user.email)
DB_CONTAINER=$(shell docker-compose ps -q db)
APPLICATION_ENV=$(shell docker-compose exec django bash -c 'echo $APPLICATION_ENV')
define set_app
sed 's/^\(APPLICATION=\).*$//\1$(1)/' -i .env django/.env
sed 's/^\(COMPOSE_FILE=\).*$//\1compose\/$(1).yml:compose\/$(1)-dev.yml/' -i .env django/.env
endef
define set_profile
sed 's/^\(COMPOSE_PROFILES=\).*$//\1$(1)/' -i .env django/.env
sed 's/^\(DJANGO_CLAMD_ENABLED=\).*$//\1$(2)/' -i .env django/.env
endef
.PHONY: help
help: ## Show the help messages
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort -k 1,1 | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: start-dev-env
start-dev-env: ## Interactive initial setup of dev-environment
./tools/start-dev-env
.env:
touch .env
.PHONY: js-watch
js-watch:
npm run watch --prefix ./kt_uri/configuration/public
.PHONY: css
css: ## Create the css files from the sass files
@cd camac/configuration/public/css/; make css
.PHONY: css-watch
css-watch: ## Watch the sass files and create the css when they change
@cd camac/configuration/public/css/; make watch
.PHONY: dumpconfig
dumpconfig: ## Dump the current camac and caluma configuration
docker-compose exec django python manage.py camac_dump_config
@yarn prettier --log-level silent --write "django/${APPLICATION}/config/*.json"
.PHONY: dumpdata
dumpdata: ## Dump the current camac and caluma data
docker-compose exec django /app/manage.py camac_dump_data
@yarn prettier --log-level silent --write "django/${APPLICATION}/data/*.json"
.PHONY: loadconfig-camac
loadconfig-camac: ## Load the camac configuration
@echo "\e[31m⚠️ Loading CAMAC config. This can take a moment, especially if migrations are running.\e[0m"
@echo "\e[31m While this is in progress, do not use the web-interface yet!\e[0m"
@docker-compose exec django ./wait-for-it.sh -t 300 127.0.0.1:80 -- python manage.py camac_load --user $(GIT_USER)
.PHONY: loadconfig-dms
loadconfig-dms: ## Load the DMS configuration
@if docker-compose config|grep -q document-merge-service; then \
docker-compose exec document-merge-service poetry run python manage.py loaddata /tmp/document-merge-service/dump.json; \
fi
.PHONY: dumpconfig-dms
dumpconfig-dms: ## Dump the DMS configuration
@if docker-compose config|grep -q document-merge-service; then \
docker-compose exec -u root document-merge-service bash -c "poetry run python manage.py dumpdata api.Template > /tmp/document-merge-service/dump.json" ; \
yarn prettier --log-level silent --write "document-merge-service/${APPLICATION}/dump.json"; \
fi
.PHONY: loadconfig-keycloak
loadconfig-keycloak: ## Load the keycloak configuration
@if ${APPLICATION_ENV} == "development"; then \
docker-compose exec keycloak /opt/keycloak/bin/kc.sh import --override true --file /opt/keycloak/data/import/test-config.json >/dev/null 2>&1 || true; \
fi
.PHONY: dumpconfig-keycloak
dumpconfig-keycloak: ## Dump the keycloak configuration
docker-compose exec keycloak /opt/keycloak/bin/kc.sh export --file /opt/keycloak/data/import/test-config.json; \
yarn prettier --log-level silent --write "keycloak/config/${APPLICATION}-test-config.json"; \
.PHONY: loadconfig
loadconfig: loadconfig-camac loadconfig-dms loadconfig-keycloak ## Load all configuration
@echo "\e[32mConfiguration has been loaded successfully. Go ahead and login.🚀\e[0m"
.PHONY: dbshell
dbshell: ## Start a psql shell
@docker-compose exec db psql -Ucamac ${APPLICATION}
.PHONY: ember-dev
ember-dev: ## Set ember.development to true in application.ini
@sed -re 's/ember\.development.*/ember.development = true/' -i php/${APPLICATION}/configs/application.ini
######### Changes from eBau Bern #########
.PHONY: mergeconfig
mergeconfig: ## Merge config.json
git mergetool --tool=jsondiff
.PHONY: migrate
migrate: ## Migrate schema
docker-compose exec django /app/manage.py migrate
make sequencenamespace
.PHONY: format
format:
@yarn --cwd=ember-camac-ng install
@yarn --cwd=ember-camac-ng lint:js --fix
@yarn --cwd=ember-caluma-portal install
@yarn --cwd=ember-caluma-portal lint:js --fix
@yarn --cwd=ember install
@yarn --cwd=ember lint:js --fix
@black --config django/pyproject.toml django
@yarn prettier --write *.yml
@yarn prettier --write compose/*.yml
.PHONY: makemigrations
makemigrations: ## Create schema migrations
docker-compose exec django /app/manage.py makemigrations
.PHONY: flush
flush:
@docker-compose exec django /app/manage.py flush --no-input
# Directory for DB snapshots
.PHONY: _db_snapshots_dir
_db_snapshots_dir:
@mkdir -p db_snapshots
.PHONY: db_snapshot
db_snapshot: _db_snapshots_dir ## Make a snapshot of the current state of the database
@docker-compose exec db pg_dump -Ucamac -c > db_snapshots/$(shell date -Iseconds).sql
.PHONY: db_restore
db_restore: _db_snapshots_dir ## Restore latest DB snapshot created with `make db_snapshot`
@echo "restoring from $(SNAPSHOT)"
@docker-compose exec -T db psql -Ucamac < $(SNAPSHOT) > /dev/null
.PHONY: sequencenamespace
sequencenamespace: ## Set the Sequence namespace for a given user. GIT_USER is detected from your git repository.
@docker-compose exec django make sequencenamespace GIT_USER=$(GIT_USER)
.PHONY: test
test: ## Run backend tests
@docker-compose exec django make test
.PHONY: kt_uri
kt_uri: ## Set APPLICATION to kt_uri
$(call set_app,kt_uri)
.PHONY: kt_schwyz
kt_schwyz: ## Set APPLICATION to kt_schwyz
$(call set_app,kt_schwyz)
.PHONY: kt_bern
kt_bern: ## Set APPLICATION to kt_bern
$(call set_app,kt_bern)
.PHONY: kt_gr
kt_gr: ## Set APPLICATION to kt_gr
$(call set_app,kt_gr)
.PHONY: demo
demo: ## Set APPLICATION to demo
$(call set_app,demo)
.PHONY: profile-full
profile-full: ## Set docker compose profile to "full"
$(call set_profile,full,true)
.PHONY: profile-slim
profile-slim: ## Unset docker compose profile
$(call set_profile,"",false)
.PHONY: build-keycloak-themes
build-keycloak-themes: ## Build the .jar file for the keycloak themes
@cd keycloak/themes/; ./mvnw install
.PHONY: clean
clean: ## Remove temporary files / build artefacts etc
@find . -name node_modules -type d | xargs rm -rf
@find . -name .pytest_cache -type d | xargs rm -rf
@find . -name __pycache__ -type d | xargs rm -rf
@rm -rf ./django/staticfiles ./django/coverage
@rm -rf ./ember/tmp ./ember-caluma-portal/tmp ./ember-camac-ng/tmp
@rm -rf ./ember/build ./ember-caluma-portal/build ./ember-camac-ng/build
.PHONY: release
release: ## Draft a new release
@if [ -z $(version) ]; then echo "Please pass a version: make release version=x.x.x"; exit 1; fi
@echo $(version) > VERSION.txt
@sed -i -e 's/"version": ".*",/"version": "$(version)",/g' ember-camac-ng/package.json
@sed -i -e 's/"version": ".*",/"version": "$(version)",/g' ember-caluma-portal/package.json
@sed -i -e 's/__version__ = ".*"/__version__ = "$(version)"/g' django/camac/camac_metadata.py
.PHONY: release-folder
release-folder: ## Add a template for a release folder
@if [ -z $(version) ]; then echo "Please pass a version: make release-folder version=x.x.x"; exit 1; fi
@mkdir -p "releases/$(version)"
@echo "# Neu\n-\n# Korrekturen\n-" >> "releases/$(version)/CHANGELOG.md"
@echo "# Änderungen\n## Ansible (Rolle / Variablen)\n-\n## DB\n-\n## Apache\n-" >> "releases/$(version)/MANUAL.md"
.PHONY: django-shell
django-shell:
@docker-compose exec django python manage.py shell
.PHONY: user-admin
user-admin: ## Add most recent user to admin group
@docker-compose exec db psql -Ucamac ${APPLICATION} -c 'insert into "USER_GROUP" ("DEFAULT_GROUP", "GROUP_ID", "USER_ID") values (1, 1, (select "USER_ID" from "USER" order by "USER_ID" desc limit 1));'
.PHONY: debug-django
debug-django: ## start a api container with service ports for debugging
@docker-compose stop django
@echo "Run './manage.py runserver 0:80' to start the debugging server"
@docker-compose run --user root --use-aliases --service-ports django bash
.PHONY: load-be-dump
load-be-dump: SHELL:=/bin/bash
load-be-dump:
@if [ ! -f latest.dmp ]; then \
echo "Enter credentials for https://cloud.adfinis.com:"; \
read -p "Username: " user; \
read -p "Password: " -s pass; \
echo "\n"; \
curl -s -u $$user:$$pass --output latest.dmp https://cloud.adfinis.com/remote.php/webdav/partner/KantonBE/db_dumps/ebau.apps.be.ch/latest.dmp > /dev/null; \
fi
@docker cp latest.dmp $(DB_CONTAINER):/tmp
@echo "Importing dump into DB..."
@docker-compose restart db > /dev/null 2>&1
@docker-compose exec db dropdb -U camac ${APPLICATION}
@docker-compose exec db createdb -U camac ${APPLICATION}
@docker-compose exec db pg_restore -d ${APPLICATION} -U camac -c --no-privileges --no-owner --if-exists /tmp/latest.dmp
@echo "Running migrations and loading new config..."
@docker-compose stop keycloak
@docker-compose rm -f keycloak
@docker-compose restart > /dev/null 2>&1
@make loadconfig > /dev/null 2>&1
@rm latest.dmp
create-be-dump:
@docker cp db/clean-dump.sql $(DB_CONTAINER):/tmp/clean-dump.sql
@docker-compose exec db psql -U camac ${APPLICATION} -f /tmp/clean-dump.sql
@docker-compose exec db pg_dump -U camac -d ${APPLICATION} -Fc -f /tmp/latest.dmp
@docker cp $(DB_CONTAINER):/tmp/latest.dmp .
@docker-compose exec db rm /tmp/latest.dmp
@echo "Please upload latest.dmp here: https://cloud.adfinis.com/apps/files/?dir=/partner/KantonBE/db_dumps/ebau.apps.be.ch"
update-lockfile:
@yarn upgrade && rm -rf node_modules ember-*/node-modules && yarn
link-ember-caluma:
@yarn link \
@projectcaluma/ember-core \
@projectcaluma/ember-form \
@projectcaluma/ember-form-builder \
@projectcaluma/ember-workflow \
@projectcaluma/ember-distribution
unlink-ember-caluma:
@yarn unlink \
@projectcaluma/ember-core \
@projectcaluma/ember-form \
@projectcaluma/ember-form-builder \
@projectcaluma/ember-workflow \
@projectcaluma/ember-distribution
@yarn --force
.PHONY: watch-templatefiles
watch-templatefiles: # Upload DMS templates to minio on change
@if command -v inotifywait >/dev/null; then \
while inotifywait -e close_write document-merge-service/${APPLICATION}/templatefiles; do make update-templatefiles; done; \
else \
echo "Please install inotify-tools to use this target"; \
exit 1; \
fi
.PHONY: update-templatefiles
update-templatefiles: # Upload DMS templates to minio
@docker compose run --rm --no-deps mc -u