-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
175 lines (140 loc) · 4.88 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
.DEFAULT_GOAL := help
SHELL := /bin/bash
DATE = $(shell date +%Y-%m-%d:%H:%M:%S)
APP_VERSION_FILE = app/version.py
GIT_BRANCH ?= $(shell git symbolic-ref --short HEAD 2> /dev/null || echo "detached")
GIT_COMMIT ?= $(shell git rev-parse HEAD)
CF_API ?= api.cloud.service.gov.uk
CF_ORG ?= govuk-notify
CF_SPACE ?= ${DEPLOY_ENV}
CF_HOME ?= ${HOME}
$(eval export CF_HOME)
CF_MANIFEST_PATH ?= /tmp/manifest.yml
NOTIFY_CREDENTIALS ?= ~/.notify-credentials
VIRTUALENV_ROOT := $(shell [ -z $$VIRTUAL_ENV ] && echo $$(pwd)/venv || echo $$VIRTUAL_ENV)
PYTHON_EXECUTABLE_PREFIX := $(shell test -d "$${VIRTUALENV_ROOT}" && echo "$${VIRTUALENV_ROOT}/bin/" || echo "")
NVM_VERSION := 0.39.7
NODE_VERSION := 16.14.0
write-source-file:
@if [ -f ~/.zshrc ]; then \
if [[ $$(cat ~/.zshrc | grep "export NVM") ]]; then \
cat ~/.zshrc | grep "export NVM" | sed "s/export//" > ~/.nvm-source; \
else \
cat ~/.bashrc | grep "export NVM" | sed "s/export//" > ~/.nvm-source; \
fi \
else \
cat ~/.bashrc | grep "export NVM" | sed "s/export//" > ~/.nvm-source; \
fi
read-source-file: write-source-file
@if [ ! -f ~/.nvm-source ]; then \
echo "Source file could not be read"; \
exit 1; \
fi
@for line in $$(cat ~/.nvm-source); do \
export $$line; \
done; \
echo '. "$$NVM_DIR/nvm.sh"' >> ~/.nvm-source;
@if [[ "$(NVM_DIR)" == "" || ! -f "$(NVM_DIR)/nvm.sh" ]]; then \
mkdir -p $(HOME)/.nvm; \
export NVM_DIR=$(HOME)/.nvm; \
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v$(NVM_VERSION)/install.sh | bash; \
echo ""; \
$(MAKE) write-source-file; \
for line in $$(cat ~/.nvm-source); do \
export $$line; \
done; \
echo '. "$$NVM_DIR/nvm.sh"' >> ~/.nvm-source; \
fi
@current_nvm_version=$$(. ~/.nvm-source && nvm --version); \
echo "NVM Versions (current/expected): $$current_nvm_version/$(NVM_VERSION)";
upgrade-node:
@TEMPDIR=/tmp/node-upgrade; \
if [[ -d $(NVM_DIR)/versions ]]; then \
rm -rf $$TEMPDIR; \
mkdir $$TEMPDIR; \
cp -rf $(NVM_DIR)/versions $$TEMPDIR; \
echo "Node versions temporarily backed up to: $$TEMPDIR"; \
fi; \
rm -rf $(NVM_DIR); \
$(MAKE) read-source-file; \
if [[ -d $$TEMPDIR/versions ]]; then \
cp -rf $$TEMPDIR/versions $(NVM_DIR); \
echo "Restored node versions from: $$TEMPDIR"; \
fi;
.PHONY: install-nvm
install-nvm:
@echo ""
@echo "[Install Node Version Manager]"
@echo ""
@if [[ "$(NVM_VERSION)" == "" ]]; then \
echo "NVM_VERSION cannot be empty."; \
exit 1; \
fi
@$(MAKE) read-source-file
@current_nvm_version=$$(. ~/.nvm-source && nvm --version); \
if [[ "$(NVM_VERSION)" != "$$current_nvm_version" ]]; then \
$(MAKE) upgrade-node; \
fi
.PHONY: install-node
install-node: install-nvm
@echo ""
@echo "[Install Node]"
@echo ""
@. ~/.nvm-source && nvm install $(NODE_VERSION) \
&& nvm use $(NODE_VERSION) \
&& nvm alias default $(NODE_VERSION);
## DEVELOPMENT
.PHONY: legacy-bootstrap
legacy-bootstrap: generate-version-file ## Bootstrap, apply migrations and run the app
pip3 install -r requirements_local_utils.txt
createdb emergency_alerts || true
(. environment.sh && flask db upgrade) || true
.PHONY: bootstrap
bootstrap: generate-version-file install-node ## Set up everything to run the app
pip3 install -r requirements_local_utils.txt
.PHONY: bootstrap-for-tests
bootstrap-for-tests: generate-version-file install-node ## Set up everything to run the tests
pip3 install -r requirements_github_utils.txt
.PHONY: run-flask
run-flask: ## Run flask
. environment.sh && flask run -p 6011
.PHONY: run-celery
run-celery: ## Run celery
. environment.sh && celery \
-A run_celery.notify_celery worker \
--uid=$(shell id -u easuser) \
--pidfile=/tmp/celery.pid \
--prefetch-multiplier=1 \
--loglevel=WARNING \
--autoscale=8,1 \
--hostname=0.0.0.0
.PHONY: run-celery-beat
run-celery-beat: ## Run celery beat
. environment.sh && celery \
-A run_celery.notify_celery beat \
--loglevel=WARNING
.PHONY: help
help:
@cat $(MAKEFILE_LIST) | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: generate-version-file
generate-version-file: ## Generates the app version file
@echo -e "__git_commit__ = \"${GIT_COMMIT}\"\n__time__ = \"${DATE}\"" > ${APP_VERSION_FILE}
.PHONY: test
test: ## Run tests
flake8 .
isort --check-only ./app ./tests
black --check .
pytest -n auto --maxfail=10
.PHONY: pytests
pytests: ## Run python tests only
pytest -n auto --maxfail=5
.PHONY: freeze-requirements
freeze-requirements: ## Pin all requirements including sub dependencies into requirements.txt
pip install --upgrade pip-tools
pip-compile requirements.in
.PHONY: bump-utils
bump-utils: # Bump emergency-alerts-utils package to latest version
${PYTHON_EXECUTABLE_PREFIX}python -c "from emergency_alerts_utils.version_tools import upgrade_version; upgrade_version()"
.PHONY: clean
clean:
rm -rf node_modules cache target venv .coverage build tests/.cache ${CF_MANIFEST_PATH}