forked from bcgov/wps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
214 lines (169 loc) · 6.21 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
# If the VIRTUAL_ENV is specified, we can assume we're in a poetry shell, otherwise
# we need to execute "poetry run"
ifdef VIRTUAL_ENV
POETRY_RUN=
else
POETRY_RUN=poetry run
endif
define run-api
# function to run api
${1} uvicorn app.main:app --host 0.0.0.0 --reload --port 8080;
endef
define build-static
# function to build static content
cd ../web; npm run build
endef
define run-env-canada-model
POSTGRES_HOST=localhost $(POETRY_RUN) python -m app.weather_models.env_canada ${1}
endef
define run-env-canada
${call run-env-canada-model,GDPS}
${call run-env-canada-model,HRDPS}
${call run-env-canada-model,RDPS}
endef
clean:
# delete python bytecode.
find . -name \*.pyc -delete
# clean out the static folder - leaving the placeholder alone.
find static ! -name 'placeholder.txt' ! -name 'static' -exec rm -rf {} +
init:
# Create virtual environment.
poetry install;
# Create static content
${call build-static}
init-mac:
# Create virtual environment.
env LDFLAGS="-I/usr/local/opt/openssl@1.1/include -L/usr/local/opt/openssl@1.1/lib" poetry install
# Create static content
${call build-static}
test:
# Run tests
# useful params for pytest:
# -s show stdout
# -n numprocesses
PYTHONPYCACHEPREFIX=python_cache $(POETRY_RUN) pytest -n 3 -x app;
# ImportMismatchError? run: make clean
test-watch:
# Use pytest-testmon and pytest-watch to trigger test runs on file changes.
# Thanks to: https://stackoverflow.com/questions/35097577/pytest-run-only-the-changed-file
# run:
# ptw --runner "pytest --testmon"
# or, shorthand:
# ptw -- --testmon
PYTHONPYCACHEPREFIX=python_cache $(POETRY_RUN) ptw -- --testmon
test-verbose:
# Run tests with verbose output
$(POETRY_RUN) pytest app -n 3 -x -vv;
test-coverage:
# run tests with coverate reports
$(POETRY_RUN) coverage run --source=app -m pytest;
$(POETRY_RUN) coverage report;
$(POETRY_RUN) coverage xml -o coverage-reports/coverage-report.xml;
# ImportMismatchError? run: make clean
lint:
# Run lint.
$(POETRY_RUN) pylint --rcfile=.pylintrc app/*.py app/**/*.py;
run-with-tests:
# Run the application in the virtual environment (after linting and testing).
# Not failing on lint or test - just output so developer knows.
-poetry run pylint --rcfile=.pylintrc app/*.py app/**/*.py;
-poetry run python -m pytest -x -n 3 app;
${call run-api,$(POETRY_RUN)}
run:
${call run-api,$(POETRY_RUN)}
run-env-canada:
${call run-env-canada}
run-env-canada-gdps:
${call run-env-canada-model,GDPS}
run-env-canada-hrdps:
${call run-env-canada-model,HRDPS}
run-env-canada-rdps:
${call run-env-canada-model,RDPS}
run-noon-forecasts:
$(POETRY_RUN) python -m app.jobs.noon_forecasts
run-hourly-actuals:
$(POETRY_RUN) python -m app.jobs.hourly_actuals
run-all-jobs:
# Run hourlies and actuals 1'st - very quick.
$(POETRY_RUN) python -m app.jobs.hourly_actuals
$(POETRY_RUN) python -m app.jobs.noon_forecasts
${call run-env-canada}
$(POETRY_RUN) python -m app.c_haines.worker
c-haines:
$(POETRY_RUN) python -m app.c_haines.worker
fetch-database-partial:
$(POETRY_RUN) python scripts/copy_db_from_pod_to_local.py
fetch-database-complete:
$(POETRY_RUN) python scripts/copy_db_from_pod_to_local.py --mode=complete
restore-partial-database-local:
# Restore a partial database to local server.
# Set environment variable PGPASSWORD=mywpspassword if you want to skip typing password for authentication.
# Set environment variable WITH_WPSREAD if you want to grant rights for wpsread user.
MODE=native ./scripts/restore_db.sh
restore-complete-database-local:
# Restore a complete database to local server.
MODE=native PARTIAL=False ./scripts/restore_db.sh
restore-partial-database-docker:
# Restore a partial database to server in docker.
# Set environment variable PGPASSWORD=mywpspassword if you want to skip typing password for authentication.
# Set environment variable WITH_WPSREAD if you want to grant rights for wpsread user.
MODE=docker ./scripts/restore_db.sh
notebook:
# Run jupyter notebooks.
POSTGRES_HOST=localhost PYTHONPATH=$(shell pwd) JUPYTER_PATH=$(shell pwd) poetry run jupyter notebook --ip 0.0.0.0
shell:
# Run shell in virtual environment shell.
poetry shell
docker-build:
# Build dev docker images.
# Having issues? try: docker volume prune
# Still having issues? try: docker system prune
docker compose build
docker-lint:
# Run linting in docker (dev instance).
${call run-lint,docker-compose run --rm api}
docker-test:
# Run tests in docker (dev instance).
# We use the dev instance, because the "production" version doesn't have
# a number of the development dependancies.
# Make sure that your docker pycache doesn't conflict with your local pycache.
docker compose run --rm api pytest -x -n 3 app
docker-test-coverage:
# Run tests with coverage in docker (dev instance).
${call run-test-coverage,docker-compose run --rm api}
docker-shell:
# Shell into the dev container.
# docker run -it --env-file app/.env --entrypoint bash wps-api_api:latest
docker compose run --rm api bash
docker-run:
# Run docker in dev mode.
docker compose up
docker-shell-db:
# Shell into the db container
docker compose exec db psql -h db -U wps
docker-redis:
# Start up a local Redis service within docker container
docker compose up redis
docker-run-env-canada:
# Run a python script to download model data from Env Canada on docker
# Needs to run "make docker-run" first
docker compose exec api python -m app.weather_models.env_canada GDPS
docker compose exec api python -m app.weather_models.env_canada HRDPS
docker compose exec api python -m app.weather_models.env_canada RDPS
docker-run-noon-forecasts:
# Run a python script to download forecast data from BC Wild Fire on docker
# Needs to run "make docker-run" first
docker compose exec api python -m app.jobs.noon_forecasts
docker-run-hourly-actuals:
# Run a python script to download hourly actuals from BC Wild Fire on docker.
# Needs to run "make docker-run" first
docker compose exec api python -m app.jobs.hourly_actuals
database-upgrade:
PYTHONPATH=. $(POETRY_RUN) alembic upgrade head
database-downgrade:
PYTHONPATH=. $(POETRY_RUN) alembic downgrade -1
docker-database-upgrade:
docker compose exec -e PYTHONPATH=. api alembic upgrade head
nats:
# Run nats with jetstream
docker run -p 4222:4222 -ti nats:latest -js