forked from openlibhums/janeway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
148 lines (136 loc) · 5.31 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
ifndef DB_VENDOR
DB_VENDOR=postgres
endif
# Exposed ports
JANEWAY_PORT ?= 8000
PGADMIN_PORT ?= 8001
SNAKEVIZ_PORT ?= 8002
unexport NO_DEPS
DB_NAME ?= janeway
DB_NAME ?= janeway
DB_HOST=janeway-postgres
DB_PORT=5432
DB_USER=janeway-web
DB_PASSWORD=janeway-web
DB_VOLUME=db/postgres-data
CLI_COMMAND=psql --username=$(DB_USER) $(DB_NAME)
ifeq ($(DB_VENDOR), mariadb)
DB_HOST=janeway-mariadb
DB_PORT=3306
DB_USER=janeway-web
DB_PASSWORD=janeway-web
CLI_COMMAND=mysql -u $(DB_USER) -p$(DB_PASSWORD)
DB_VOLUME=db/mariadb-data
endif
ifeq ($(DB_VENDOR), mysql)
DB_HOST=janeway-mysql
DB_PORT=3306
DB_USER=janeway-web
DB_PASSWORD=janeway-web
CLI_COMMAND=mysql -u $(DB_USER) -p$(DB_PASSWORD)
DB_VOLUME=db/mysql-data
endif
ifeq ($(DB_VENDOR), sqlite)
unexport DB_HOST
NO_DEPS=--no-deps
CLI_COMMAND=sqlite db/janeway.sqlite3
DB_VOLUME=db/janeway.sqlite3
endif
ifdef VERBOSE
_VERBOSE=--verbose
endif
# Email
ifdef DEBUG_SMTP
JANEWAY_EMAIL_BACKEND=django.core.mail.backends.smtp.EmailBackend
JANEWAY_EMAIL_HOST=janeway-debug-smtp
JANEWAY_EMAIL_PORT=1025
JANEWAY_EMAIL_USE_TLS=
endif
LOCALES_DIR = ./src/core/locales
export DB_VENDOR
export DB_HOST
export DB_PORT
export DB_NAME
export DB_USER
export DB_PASSWORD
export JANEWAY_PORT
export PGADMIN_PORT
export JANEWAY_EMAIL_BACKEND
export JANEWAY_EMAIL_HOST
export JANEWAY_EMAIL_PORT
export JANEWAY_EMAIL_USE_TLS
COMPOSE_CMD ?= docker compose
SUFFIX ?= $(shell date +%s)
SUFFIX := ${SUFFIX}
DATE := `date +"%y-%m-%d"`
.PHONY: janeway
all: help
run: janeway
help: ## Show this help.
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
janeway: ## Run Janeway web server in attached mode. If NO_DEPS is not set, runs all dependant services detached.
$(COMPOSE_CMD) run --rm start_dependencies
$(COMPOSE_CMD) $(_VERBOSE) run $(NO_DEPS) --rm --service-ports janeway-web $(entrypoint)
command: ## Run Janeway in a container and pass through a django command passed as the CMD environment variable (e.g make command CMD="migrate -v core 0024")
$(COMPOSE_CMD) run $(NO_DEPS) --rm janeway-web $(CMD)
install: ## Run the install_janeway command inside a container
touch db/janeway.sqlite3
mkdir -p db/postgres-data
$(COMPOSE_CMD) run --rm start_dependencies
bash -c "make command CMD=install_janeway"
rebuild: ## Rebuild the Janeway docker image.
docker pull birkbeckctp/janeway-base:latest
$(COMPOSE_CMD) build --no-cache janeway-web
shell: ## Runs the janeway-web service and starts an interactive bash process instead of the webserver
$(COMPOSE_CMD) run --service-ports --entrypoint=/bin/bash --rm janeway-web
attach: ## Runs an interactive shell within the currently running janeway-web container.
docker exec -ti `docker ps -q --filter 'name=janeway-web'` /bin/bash
db-client: ## runs the database CLI client interactively within the database container as per the value of DB_VENDOR
docker exec -ti `docker ps -q --filter 'name=janeway-$(DB_VENDOR)'` $(CLI_COMMAND)
db-save-backup: # Archives the current db as a tarball. Returns the output file name
@sudo tar -zcf $(DB_VENDOR)-$(DATE)-$(SUFFIX).tar.gz $(DB_VOLUME)
@echo "$(DB_VENDOR)-$(DATE)-$(SUFFIX).tar.gz"
@sudo chown -R `id -un`:`id -gn` $(DB_VENDOR)-$(DATE)-$(SUFFIX).tar.gz
db-load-backup: #Loads a previosuly captured backup in the db directory (e.g.: make db-load_backup DB=postgres-21-02-03-3948681d1b6dc2.tar.gz)
@BACKUP=$(BACKUP);echo "Loading $${BACKUP:?Please set to the name of the backup file}"
@tar -zxf $(BACKUP) -C /tmp/
@docker kill `docker ps -q --filter 'name=janeway-*'` 2>&1 | true
@sudo rm -rf $(DB_VOLUME)
@sudo mv /tmp/$(DB_VOLUME) db/
uninstall: ## Removes all janeway related docker containers, docker images and database volumes
@bash -c "rm -rf db/*"
@bash -c "docker rm -f `docker ps --filter 'name=janeway*' -aq` >/dev/null 2>&1 | true"
@bash -c "docker rmi `docker images -q janeway*` >/dev/null 2>&1 | true"
@echo " Janeway has been uninstalled"
check: ## Runs janeway's test suit
bash -c "DB_VENDOR=sqlite make command CMD=test"
migrate: ## Runs Django's migrate command
bash -c "make command CMD=migrate"
makemigrations: ## Runs Django's makemigrations command
bash -c "make command CMD=makemigrations"
makemessages:
#$(foreach file, $(wildcard $(LOCALES_DIR)/*), make command CMD="makemessages --locale=$(file) --ignore=src/plugins/*";)
#@for f in $(shell ls ${LOCALES_DIR}); make command CMD='makemessages --locale=$${f} --ignore=src/plugins/*';)
bash -c "make command CMD='makemessages \
--locale=de \
--locale=cy \
--locale=fr \
--locale=it \
--locale=nl \
--locale=en-us \
--ignore=src/plugins/* \
'"
build_assets: ## Runs Janeway's build_assets command
bash -c "make command CMD=build_assets"
basebuild: ## Builds the base docker image
bash -c "docker build --no-cache -t birkbeckctp/janeway-base:latest -f dockerfiles/Dockerfile.base ."
snakeviz:
$(COMPOSE_CMD) run --publish $(SNAKEVIZ_PORT):$(SNAKEVIZ_PORT) $(NO_DEPS) --rm --entrypoint=snakeviz janeway-web $(FILE) --server -H 0.0.0.0 -p $(SNAKEVIZ_PORT)
ci: ## Runs Janeway's CI job in a container
docker build -t janeway_jenkins_build_${BUILD_TAG}_ci -f jenkins/Dockerfile.jenkins .
echo "Running Unit Tests and Coverage"
docker run \
-v `pwd`/jenkins:/vol/janeway/jenkins \
-v `pwd`/logs:/vol/janeway/logs \
-e JANEWAY_SETTINGS_MODULE=core.jenkins_settings \
--rm janeway_jenkins_build_${BUILD_TAG}_ci test