This repository has been archived by the owner on Dec 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
100 lines (79 loc) · 3.12 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
.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)
NOTIFY_CREDENTIALS ?= ~/.notify-credentials
CF_APP = "notify-ftp"
CF_ORG = "govuk-notify"
CF_MANIFEST_PATH ?= /tmp/manifest.yml
.PHONY: bootstrap
bootstrap: generate-version-file ## Install dependencies, etc.
pip install -r requirements_for_test.txt
.PHONY: run-celery
run-celery: ## Runs celery worker
. environment.sh && celery \
-A run_celery.notify_celery worker \
--pidfile="/tmp/celery-ftp.pid" \
--loglevel=INFO \
--concurrency=1
.PHONY: test
test: ## Run unit tests
flake8 .
isort --check-only ./app ./tests
pytest
.PHONY: shell
shell: ## Start a local shell with an app context
python -i -m run_celery
.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: generate-manifest
generate-manifest: ## Generates cf manifest
$(if ${CF_APP},,$(error Must specify CF_APP))
$(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))
@jinja2 --strict manifest.yml.j2 \
-D environment=${CF_SPACE} \
-D CF_APP=${CF_APP} \
--format=yaml \
<(${DECRYPT_CMD} ${NOTIFY_CREDENTIALS}/credentials/${CF_SPACE}/paas/ftp-environment-variables.gpg) 2>&1
.PHONY: cf-target
cf-target:
$(if ${CF_SPACE},,$(error Must specify CF_SPACE))
@cf target -o ${CF_ORG} -s ${CF_SPACE}
.PHONY: cf-deploy
cf-deploy: cf-target ## Deploys the app to Cloud Foundry
$(if ${CF_SPACE},,$(error Must specify CF_SPACE))
@cf app --guid ${CF_APP} || exit 1
# cancel any existing deploys to ensure we can apply manifest (if a deploy is in progress you'll see ScaleDisabledDuringDeployment)
cf cancel-deployment ${CF_APP} || true
# 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 push ${CF_APP} --strategy=rolling -f ${CF_MANIFEST_PATH}
# delete old manifest file
rm ${CF_MANIFEST_PATH}
.PHONY: preview
preview: ## Set environment to preview
$(eval export CF_SPACE=preview)
@true
.PHONY: staging
staging: ## Set environment to staging
$(eval export CF_SPACE=staging)
@true
.PHONY: production
production: ## Set environment to production
$(eval export CF_SPACE=production)
@true
.PHONY: clean
clean:
rm -rf cache target venv .coverage build tests/.cache wheelhouse ${CF_MANIFEST_PATH}
freeze-requirements: ## create static requirements.txt
pip install --upgrade pip-tools
pip-compile requirements.in