-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
170 lines (138 loc) · 7.85 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
prefix := /var/www/workflow
PYTHON_VERSION:=3.12
# these are defined here because I couldn't figure out how to evaluate the commands
# during target execution rather then when make parses the file
# this is found by `find /opt/conda/ -name manage.py | grep reporting`
MANAGE_PY_WEBMON=/opt/conda/lib/python$(PYTHON_VERSION)/site-packages/reporting/manage.py
# this is found by `find /opt/conda -name db_init.json`
REPORT_DB_INIT=/opt/conda/lib/python$(PYTHON_VERSION)/site-packages/reporting/fixtures/db_init.json
# command to run docker compose. change this to be what you have installed
# this can be overriden on the command line
# DOCKER_COMPOSE="docker compose" make startdev
DOCKER_COMPOSE ?= "docker compose"
help:
# this nifty perl one-liner collects all comments headed by the double "#" symbols next to each target and recycles them as comments
@perl -nle'print $& if m{^[/a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-25s\033[0m %s\n", $$1, $$2}'
all: wheel/all SNSdata.tar.gz ssl ## creates: all python wheels; fake SNS data; SSL self-signed certificates
create/conda: ## create conda environment "webmon" with file conda_environment.yml
conda env create --name webmon --file conda_environment.yml
conda env update --name webmon --file conda_development.yml
create/mamba: ## create conda environment "webmon" with file conda_environment.yml using mamba
conda env create --name webmon python=$(PYTHON_VERSION)
conda install --name base -c conda-forge mamba
mamba env update --name webmon --file conda_environment.yml
mamba env update --name webmon --file conda_development.yml
docker/pruneall: ## stop and force remove all containers, images and volumes
docker system prune --force --all --volumes
docs: ## create HTML docs under docs/_build/html/. Requires activation of "webmon" conda environment
@cd docs && make html SPHINXOPTS="-W --keep-going -n" && echo -e "##########\n DOCS point your browser to file://$$(pwd)/_build/html/index.html\n##########"
check: ## Check python dependencies
########################################################################
# #
# Make sure to check your DB settings in workflow/database/settings.py #
# and reporting/reporting_app/settings.py #
# #
########################################################################
# Check dependencies
which python
echo CONDA_PREFIX=${CONDA_PREFIX}
@python -c "import django" || echo "\nERROR: Django is not installed: www.djangoproject.com\n"
@python -c "import psycopg" || echo "\nWARNING: psycopg is not installed: http://initd.org/psycopg\n"
@python -c "import stomp" || echo "\nERROR: stomp.py is not installed: http://code.google.com/p/stomppy\n"
wheel/dasmon: ## create or update python wheel for service "dasmon". Clean up build/ first
cd src/dasmon_app && if [ -d "build" ]; then chmod u+rwx -R build && rm -rf build/;fi
cd src/dasmon_app && python -m build --no-isolation --wheel
# verify it is correct
cd src/dasmon_app && check-wheel-contents dist/django_nscd_dasmon-*.whl
wheel/webmon: ## create or update python wheel for service "webmon". Clean up build/ first
cd src/webmon_app && if [ -d "build" ]; then chmod u+rwx -R build && rm -rf build/;fi
cd src/webmon_app && python -m build --no-isolation --wheel
# verify it is correct - ignoring duplicate file check
cd src/webmon_app && check-wheel-contents dist/django_nscd_webmon-*.whl
wheel/workflow: ## create or update python wheel for service "workflow". Clean up build/ first
cd src/workflow_app && if [ -d "build" ]; then chmod u+rwx -R build && rm -rf build/;fi
cd src/workflow_app && python -m build --no-isolation --wheel
# verify it is correct
cd src/workflow_app && check-wheel-contents dist/django_nscd_workflow-*.whl
wheel/all: wheel/clean wheel/dasmon wheel/webmon wheel/workflow ## create python wheels for all services. Clean up build/ first
wheel/clean: ## delete all the python wheels
cd src/dasmon_app && rm -rf build/ dist/
cd src/webmon_app && rm -rf build/ dist/
cd src/workflow_app && rm -rf build/ dist/
install/workflow: check
# Install the workflow manager, which defines the database schema
pip install django_nscd_workflow*.whl
# verify the install worked
python -c "import workflow;print('WORKFLOW VERSION', workflow.__version__)"
install/dasmonlistener: install/workflow install/webmon
# Install DASMON listener
pip install django_nscd_dasmon*.whl
# verify the install worked
python -c "import dasmon_listener;print('DASMON VERSION', dasmon_listener.__version__)"
install/webmon: install/workflow
# Install the main web application
pip install django_nscd_webmon*.whl
# verify the install worked
python -c "import reporting;print('WEBMON VERSION', reporting.__version__)"
configure/webmon: install/webmon
# Collect the static files and install them
python $(MANAGE_PY_WEBMON) collectstatic --noinput
# Create the database tables. The database itself must have been
# created on the server already
python $(MANAGE_PY_WEBMON) makemigrations --noinput
python $(MANAGE_PY_WEBMON) migrate --fake-initial --noinput
python $(MANAGE_PY_WEBMON) migrate --run-syncdb --noinput
# Prepare web monitor cache: RUN THIS ONCE BY HAND
python $(MANAGE_PY_WEBMON) createcachetable webcache
python $(MANAGE_PY_WEBMON) ensure_adminuser --username=${DATABASE_USER} --email='[email protected]' --password=${DATABASE_PASS}
# add the stored sql proceedures
python $(MANAGE_PY_WEBMON) add_stored_procs
@echo "\n\nReady to go\n"
configure/load_initial_data: install/webmon
# use fixtures to load initial data
python $(MANAGE_PY_WEBMON) loaddata $(REPORT_DB_INIT)
SNSdata.tar.gz: ## install SNS data for testing and limited info display
# this doesn't have explicit dependencies on the data
# it needs to be removed when the directory changes
tar czf SNSdata.tar.gz -C tests/data/ .
ssl: nginx/nginx.crt nginx/nginx.key ## self-signed ssl certificates for livedata server
ssl/clean: ## delete the self-signed ssl certificates for livedata server
rm -f nginx/nginx.crt nginx/nginx.key
nginx/nginx.crt nginx/nginx.key:
openssl req -x509 -out nginx/nginx.crt -keyout nginx/nginx.key -newkey rsa:2048 -nodes -sha256 --config nginx/san.cnf
localdev/up: ## create images and start containers for local development. Doesn't update python wheels, though.
docker compose --file docker-compose.yml up --build
localdev/dbup: ## dbdumpfile=database_dump_file.sql DATABASE_PASS=$(dotenv get DATABASE_PASS) make localdev/dbup
if ! test -f "${dbdumpfile}"; then echo "dbdumpfile does not exists" && false; fi
if test -z "${DATABASE_PASS}"; then echo "DATABASE_PASS undefined" && false; fi
docker compose --file docker-compose.yml stop
docker compose --file docker-compose.yml down --volumes
sleep 2s
docker compose --file docker-compose.yml up --detach db
sleep 10s # give time for the database service to be ready
docker exec -i data_workflow-db-1 /bin/bash -c "pg_restore -d workflow -U workflow" < ${dbdumpfile} | true # continue even if returned errors
docker exec -i data_workflow-db-1 /bin/bash -c "psql -d workflow -U workflow -c \"ALTER ROLE workflow WITH PASSWORD '${DATABASE_PASS}';\""
LOAD_INITIAL_DATA="false" docker compose --file docker-compose.yml up --build
clean: wheel/clean ssl/clean ## deletes: all python wheels; fake SNS data; SSL self-signed certificates
rm -f SNSdata.tar.gz
# targets that don't create actual files
.PHONY: check
.PHONY: create/conda
.PHONY: create/mamba
.PHONY: configure/webmon
.PHONY: docker/pruneall
.PHONY: docs
.PHONE: help
.PHONY: install/dasmonlistener
.PHONY: install/webmon
.PHONY: install/workflow
.PHONY: SNSdata.tar.gz
.PHONY: ssl
.PHONY: ssl/clean
.PHONY: localdev/up
.PHONY: localdev/dbup
.PHONY: wheel/dasmon
.PHONY: wheel/webmon
.PHONY: wheel/workflow
.PHONY: wheel/all
.PHONY: wheel/clean