2016-08-12 11:23:50 +01:00
|
|
|
.DEFAULT_GOAL := help
|
|
|
|
|
SHELL := /bin/bash
|
2018-08-09 13:46:43 +01:00
|
|
|
DATE = $(shell date +%Y-%m-%dT%H:%M:%S)
|
2016-08-12 11:23:50 +01:00
|
|
|
|
|
|
|
|
APP_VERSION_FILE = app/version.py
|
|
|
|
|
|
2016-08-26 16:18:13 +01:00
|
|
|
GIT_BRANCH ?= $(shell git symbolic-ref --short HEAD 2> /dev/null || echo "detached")
|
2017-02-01 15:44:10 +00:00
|
|
|
GIT_COMMIT ?= $(shell git rev-parse HEAD 2> /dev/null || echo "")
|
2016-08-12 11:23:50 +01:00
|
|
|
|
2016-12-08 16:50:37 +00:00
|
|
|
CF_API ?= api.cloud.service.gov.uk
|
|
|
|
|
CF_ORG ?= govuk-notify
|
|
|
|
|
CF_SPACE ?= ${DEPLOY_ENV}
|
2017-02-28 12:31:56 +00:00
|
|
|
CF_HOME ?= ${HOME}
|
2019-04-18 14:48:23 +01:00
|
|
|
CF_APP ?= notify-admin
|
2020-12-08 17:15:47 +00:00
|
|
|
CF_MANIFEST_PATH ?= /tmp/manifest.yml
|
2017-02-28 12:31:56 +00:00
|
|
|
$(eval export CF_HOME)
|
2016-12-08 16:50:37 +00:00
|
|
|
|
2018-01-09 14:14:47 +00:00
|
|
|
NOTIFY_CREDENTIALS ?= ~/.notify-credentials
|
|
|
|
|
|
2020-12-29 13:21:13 +00:00
|
|
|
VIRTUALENV_ROOT := $(shell [ -z $$VIRTUAL_ENV ] && echo $$(pwd)/venv || echo $$VIRTUAL_ENV)
|
|
|
|
|
|
2022-08-08 14:43:05 -04:00
|
|
|
NVMSH := $(shell [ -f "$(HOME)/.nvm/nvm.sh" ] && echo "$(HOME)/.nvm/nvm.sh" || echo "/usr/local/share/nvm/nvm.sh")
|
2020-03-03 12:05:56 +00:00
|
|
|
|
|
|
|
|
## DEVELOPMENT
|
|
|
|
|
|
2021-02-22 16:53:54 +00:00
|
|
|
.PHONY: bootstrap
|
2021-05-25 11:21:39 +01:00
|
|
|
bootstrap: generate-version-file ## Set up everything to run the app
|
2021-02-22 16:53:54 +00:00
|
|
|
pip3 install -r requirements_for_test.txt
|
2022-08-09 09:23:47 -04:00
|
|
|
source $(NVMSH) --no-use && nvm install && npm ci --no-audit
|
2022-08-08 14:43:05 -04:00
|
|
|
source $(NVMSH) && npm run build
|
2022-06-13 14:26:46 -07:00
|
|
|
|
2021-11-02 15:22:57 +00:00
|
|
|
.PHONY: watch-frontend
|
|
|
|
|
watch-frontend: ## Build frontend and watch for changes
|
2022-06-13 14:26:46 -07:00
|
|
|
npm run watch
|
2021-11-02 15:22:57 +00:00
|
|
|
|
2021-02-22 16:41:30 +00:00
|
|
|
.PHONY: run-flask
|
2021-05-25 11:21:39 +01:00
|
|
|
run-flask: ## Run flask
|
2022-06-13 14:31:51 -07:00
|
|
|
flask run -p 6012 --host=0.0.0.0
|
2021-02-22 16:41:30 +00:00
|
|
|
|
2022-05-06 15:34:54 +01:00
|
|
|
.PHONY: npm-audit
|
|
|
|
|
npm-audit: ## Check for vulnerabilities in NPM packages
|
2022-08-08 14:43:05 -04:00
|
|
|
source $(NVMSH) && npm run audit
|
2022-05-06 15:34:54 +01:00
|
|
|
|
2016-08-12 11:23:50 +01:00
|
|
|
.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}'
|
|
|
|
|
|
2020-12-29 13:21:13 +00:00
|
|
|
.PHONY: virtualenv
|
|
|
|
|
virtualenv:
|
|
|
|
|
[ -z $$VIRTUAL_ENV ] && [ ! -d venv ] && python3 -m venv venv || true
|
|
|
|
|
|
|
|
|
|
.PHONY: upgrade-pip
|
|
|
|
|
upgrade-pip: virtualenv
|
|
|
|
|
${VIRTUALENV_ROOT}/bin/pip install --upgrade pip
|
|
|
|
|
|
2016-08-12 11:23:50 +01:00
|
|
|
.PHONY: generate-version-file
|
|
|
|
|
generate-version-file: ## Generates the app version file
|
2020-04-21 17:00:38 +01:00
|
|
|
@echo -e "__git_commit__ = \"${GIT_COMMIT}\"\n__time__ = \"${DATE}\"" > ${APP_VERSION_FILE}
|
2016-08-12 11:23:50 +01:00
|
|
|
|
|
|
|
|
.PHONY: test
|
2019-12-24 15:24:07 +00:00
|
|
|
test: ## Run tests
|
2021-05-24 15:33:35 +01:00
|
|
|
flake8 .
|
|
|
|
|
isort --check-only ./app ./tests
|
2022-08-08 14:43:05 -04:00
|
|
|
source $(NVMSH) && npm test
|
2021-05-24 15:33:35 +01:00
|
|
|
py.test -n auto --maxfail=10 tests/
|
2016-08-12 11:23:50 +01:00
|
|
|
|
2020-01-13 10:26:11 +00:00
|
|
|
.PHONY: fix-imports
|
2021-05-25 11:21:39 +01:00
|
|
|
fix-imports: ## Fix imports using isort
|
2021-10-04 14:58:29 +01:00
|
|
|
isort ./app ./tests
|
2020-01-13 10:26:11 +00:00
|
|
|
|
2018-07-10 15:16:14 +01:00
|
|
|
.PHONY: freeze-requirements
|
2021-01-08 16:40:51 +00:00
|
|
|
freeze-requirements: ## create static requirements.txt
|
2021-04-08 11:09:39 +01:00
|
|
|
${VIRTUALENV_ROOT}/bin/pip install --upgrade pip-tools
|
2020-12-29 13:21:13 +00:00
|
|
|
${VIRTUALENV_ROOT}/bin/pip-compile requirements.in
|
2018-07-10 15:16:14 +01:00
|
|
|
|
2022-08-25 20:36:13 +00:00
|
|
|
.PHONY: pip-audit
|
|
|
|
|
pip-audit:
|
|
|
|
|
pip install --upgrade pip-audit
|
|
|
|
|
pip-audit -r requirements.txt -r requirements_for_test.txt -l --ignore-vuln PYSEC-2022-237
|
|
|
|
|
|
|
|
|
|
.PHONY: audit
|
|
|
|
|
audit: npm-audit pip-audit
|
|
|
|
|
|
2016-12-08 16:50:37 +00:00
|
|
|
.PHONY: clean
|
2016-08-12 11:23:50 +01:00
|
|
|
clean:
|
2020-12-08 17:15:47 +00:00
|
|
|
rm -rf node_modules cache target ${CF_MANIFEST_PATH}
|
2016-12-08 16:50:37 +00:00
|
|
|
|
2020-03-03 12:05:56 +00:00
|
|
|
|
|
|
|
|
## DEPLOYMENT
|
|
|
|
|
|
|
|
|
|
.PHONY: check-env-vars
|
|
|
|
|
check-env-vars: ## Check mandatory environment variables
|
|
|
|
|
$(if ${DEPLOY_ENV},,$(error Must specify DEPLOY_ENV))
|
|
|
|
|
$(if ${DNS_NAME},,$(error Must specify DNS_NAME))
|
|
|
|
|
|
|
|
|
|
.PHONY: preview
|
|
|
|
|
preview: ## Set environment to preview
|
|
|
|
|
$(eval export DEPLOY_ENV=preview)
|
|
|
|
|
$(eval export DNS_NAME="notify.works")
|
|
|
|
|
@true
|
|
|
|
|
|
|
|
|
|
.PHONY: staging
|
|
|
|
|
staging: ## Set environment to staging
|
|
|
|
|
$(eval export DEPLOY_ENV=staging)
|
|
|
|
|
$(eval export DNS_NAME="staging-notify.works")
|
|
|
|
|
@true
|
|
|
|
|
|
|
|
|
|
.PHONY: production
|
|
|
|
|
production: ## Set environment to production
|
|
|
|
|
$(eval export DEPLOY_ENV=production)
|
|
|
|
|
$(eval export DNS_NAME="notifications.service.gov.uk")
|
|
|
|
|
@true
|
|
|
|
|
|
2016-12-08 16:50:37 +00:00
|
|
|
.PHONY: cf-login
|
|
|
|
|
cf-login: ## Log in to Cloud Foundry
|
|
|
|
|
$(if ${CF_USERNAME},,$(error Must specify CF_USERNAME))
|
|
|
|
|
$(if ${CF_PASSWORD},,$(error Must specify CF_PASSWORD))
|
|
|
|
|
$(if ${CF_SPACE},,$(error Must specify CF_SPACE))
|
|
|
|
|
@echo "Logging in to Cloud Foundry on ${CF_API}"
|
|
|
|
|
@cf login -a "${CF_API}" -u ${CF_USERNAME} -p "${CF_PASSWORD}" -o "${CF_ORG}" -s "${CF_SPACE}"
|
|
|
|
|
|
2018-01-09 14:14:47 +00:00
|
|
|
.PHONY: generate-manifest
|
|
|
|
|
generate-manifest:
|
2019-04-12 11:05:45 +01:00
|
|
|
$(if ${CF_APP},,$(error Must specify CF_APP))
|
2018-01-09 14:14:47 +00:00
|
|
|
$(if ${CF_SPACE},,$(error Must specify CF_SPACE))
|
|
|
|
|
$(if $(shell which gpg2), $(eval export GPG=gpg2), $(eval export GPG=gpg))
|
|
|
|
|
$(if ${GPG_PASSPHRASE_TXT}, $(eval export DECRYPT_CMD=echo -n $$$${GPG_PASSPHRASE_TXT} | ${GPG} --quiet --batch --passphrase-fd 0 --pinentry-mode loopback -d), $(eval export DECRYPT_CMD=${GPG} --quiet --batch -d))
|
|
|
|
|
|
2019-04-12 11:05:45 +01:00
|
|
|
@jinja2 --strict manifest.yml.j2 \
|
|
|
|
|
-D environment=${CF_SPACE} \
|
|
|
|
|
-D CF_APP=${CF_APP} \
|
|
|
|
|
--format=yaml \
|
|
|
|
|
<(${DECRYPT_CMD} ${NOTIFY_CREDENTIALS}/credentials/${CF_SPACE}/paas/environment-variables.gpg) 2>&1
|
2018-01-09 14:14:47 +00:00
|
|
|
|
2020-03-03 12:05:15 +00:00
|
|
|
.PHONY: upload-static ## Upload the static files to be served from S3
|
|
|
|
|
upload-static:
|
2022-06-23 14:08:29 -07:00
|
|
|
aws s3 cp --region us-west-2 --recursive --cache-control max-age=315360000,immutable ./app/static s3://${DNS_NAME}-static
|
2020-03-03 12:05:15 +00:00
|
|
|
|
2016-12-08 16:50:37 +00:00
|
|
|
.PHONY: cf-deploy
|
2018-12-18 15:48:14 +00:00
|
|
|
cf-deploy: ## Deploys the app to Cloud Foundry
|
2017-02-14 16:17:30 +00:00
|
|
|
$(if ${CF_SPACE},,$(error Must specify CF_SPACE))
|
|
|
|
|
@cf app --guid notify-admin || exit 1
|
2019-05-09 16:11:26 +01:00
|
|
|
# cancel any existing deploys to ensure we can apply manifest (if a deploy is in progress you'll see ScaleDisabledDuringDeployment)
|
2020-12-08 17:15:47 +00:00
|
|
|
cf cancel-deployment ${CF_APP} || true
|
2019-05-09 16:11:26 +01:00
|
|
|
|
2020-12-08 17:15:47 +00:00
|
|
|
# generate manifest (including secrets) and write it to CF_MANIFEST_PATH (in /tmp/)
|
|
|
|
|
make -s CF_APP=${CF_APP} generate-manifest > ${CF_MANIFEST_PATH}
|
|
|
|
|
# reads manifest from CF_MANIFEST_PATH
|
|
|
|
|
CF_STARTUP_TIMEOUT=10 cf push ${CF_APP} --strategy=rolling -f ${CF_MANIFEST_PATH}
|
|
|
|
|
# delete old manifest file
|
|
|
|
|
rm -f ${CF_MANIFEST_PATH}
|
2017-02-14 16:17:30 +00:00
|
|
|
|
Add config to deploy a prototype version of admin
Sometimes we want to make changes to the admin app for doing user
research that we don’t want all users to see (because we’re not sure if
they’re the right changes to be making).
Previously this meant doing the research using a team member’s computer,
with the app running locally. This was bad for three reasons:
- requires the time of someone who has the code running locally
- requires the participant to use an unfamiliar computer
- means the participant doesn’t have access to their own Notify account
(or an account that we’ve set up for doing user research with)
The dream* would be to have two versions of the frontend app running
side by side in production. This commit makes the dream real – the two
versions of admin are:
- the normal admin app, accessible on
`www.notifications.service.gov.uk`
- a prototype version meant to be pushed to from a developer’s local
machine**, on a `cloudapps.digital` subdomain
Both of these apps share the same backing services, eg config, API
instance, queues, etc, etc. Which means that the prototype version can
be logged into with the same username and password, and the user will
see their service and all their templates when they do so.
Ideally this wouldn’t mean creating a separate base manifest. However
it’s a feature of Cloud Foundry that you can override the application
name. Which means a separate base manifest and a bit of duplication. 😞
* actually the real dream would be to have a version of admin deployed
for each branch of the admin app, but this might get a bit resource
intensive.
** by running `CF_SPACE=preview make preview cf-deploy-prototype`, where
`preview` is the name of the space you want to deploy to
2017-05-05 08:41:55 +01:00
|
|
|
.PHONY: cf-deploy-prototype
|
2019-04-12 11:05:45 +01:00
|
|
|
cf-deploy-prototype: cf-target ## Deploys the first prototype to Cloud Foundry
|
2020-12-08 17:15:47 +00:00
|
|
|
make -s CF_APP=notify-admin-prototype generate-manifest > ${CF_MANIFEST_PATH}
|
|
|
|
|
cf push notify-admin-prototype --strategy=rolling -f ${CF_MANIFEST_PATH}
|
|
|
|
|
rm -f ${CF_MANIFEST_PATH}
|
Add config to deploy a prototype version of admin
Sometimes we want to make changes to the admin app for doing user
research that we don’t want all users to see (because we’re not sure if
they’re the right changes to be making).
Previously this meant doing the research using a team member’s computer,
with the app running locally. This was bad for three reasons:
- requires the time of someone who has the code running locally
- requires the participant to use an unfamiliar computer
- means the participant doesn’t have access to their own Notify account
(or an account that we’ve set up for doing user research with)
The dream* would be to have two versions of the frontend app running
side by side in production. This commit makes the dream real – the two
versions of admin are:
- the normal admin app, accessible on
`www.notifications.service.gov.uk`
- a prototype version meant to be pushed to from a developer’s local
machine**, on a `cloudapps.digital` subdomain
Both of these apps share the same backing services, eg config, API
instance, queues, etc, etc. Which means that the prototype version can
be logged into with the same username and password, and the user will
see their service and all their templates when they do so.
Ideally this wouldn’t mean creating a separate base manifest. However
it’s a feature of Cloud Foundry that you can override the application
name. Which means a separate base manifest and a bit of duplication. 😞
* actually the real dream would be to have a version of admin deployed
for each branch of the admin app, but this might get a bit resource
intensive.
** by running `CF_SPACE=preview make preview cf-deploy-prototype`, where
`preview` is the name of the space you want to deploy to
2017-05-05 08:41:55 +01:00
|
|
|
|
2018-02-07 17:28:04 +00:00
|
|
|
.PHONY: cf-deploy-prototype-2
|
2019-04-12 11:05:45 +01:00
|
|
|
cf-deploy-prototype-2: cf-target ## Deploys the second prototype to Cloud Foundry
|
2020-12-08 17:15:47 +00:00
|
|
|
make -s CF_APP=notify-admin-prototype-2 generate-manifest > ${CF_MANIFEST_PATH}
|
|
|
|
|
cf push notify-admin-prototype-2 --strategy=rolling -f ${CF_MANIFEST_PATH}
|
|
|
|
|
rm -f ${CF_MANIFEST_PATH}
|
2018-02-07 17:28:04 +00:00
|
|
|
|
2017-02-14 16:17:30 +00:00
|
|
|
.PHONY: cf-rollback
|
2019-05-09 16:11:26 +01:00
|
|
|
cf-rollback: cf-target ## Rollbacks the app to the previous release
|
2020-12-08 17:15:47 +00:00
|
|
|
cf cancel-deployment ${CF_APP}
|
|
|
|
|
rm -f ${CF_MANIFEST_PATH}
|
2016-12-08 16:50:37 +00:00
|
|
|
|
2018-01-03 17:17:26 +00:00
|
|
|
.PHONY: cf-target
|
|
|
|
|
cf-target: check-env-vars
|
|
|
|
|
@cf target -o ${CF_ORG} -s ${CF_SPACE}
|
|
|
|
|
|
|
|
|
|
.PHONY: cf-failwhale-deployed
|
|
|
|
|
cf-failwhale-deployed:
|
|
|
|
|
@cf app notify-admin-failwhale --guid || (echo "notify-admin-failwhale is not deployed on ${CF_SPACE}" && exit 1)
|
|
|
|
|
|
|
|
|
|
.PHONY: enable-failwhale
|
|
|
|
|
enable-failwhale: cf-target cf-failwhale-deployed ## Enable the failwhale app and disable admin
|
|
|
|
|
@cf map-route notify-admin-failwhale ${DNS_NAME} --hostname www
|
|
|
|
|
@cf unmap-route notify-admin ${DNS_NAME} --hostname www
|
|
|
|
|
@echo "Failwhale is enabled"
|
|
|
|
|
|
|
|
|
|
.PHONY: disable-failwhale
|
|
|
|
|
disable-failwhale: cf-target cf-failwhale-deployed ## Disable the failwhale app and enable admin
|
|
|
|
|
@cf map-route notify-admin ${DNS_NAME} --hostname www
|
|
|
|
|
@cf unmap-route notify-admin-failwhale ${DNS_NAME} --hostname www
|
|
|
|
|
@echo "Failwhale is disabled"
|