forked from alphagov/document-download-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
127 lines (101 loc) · 4.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
SHELL := /bin/bash
GIT_COMMIT ?= $(shell git rev-parse HEAD)
CF_API ?= api.cloud.service.gov.uk
NOTIFY_CREDENTIALS ?= ~/.notify-credentials
CF_APP = document-download-api
## DEVELOPMENT
.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: run
run: ## Run the app locally
FLASK_APP=application.py FLASK_ENV=development flask run -p 7000
.PHONY: test
test: test-requirements ## Run all tests
py.test tests/
flake8 .
.PHONY: freeze-requirements
freeze-requirements: ## Pin dependencies
rm -rf venv-freeze
virtualenv -p python3 venv-freeze
$$(pwd)/venv-freeze/bin/pip install -r requirements-app.txt
echo '# This file is autogenerated. Do not edit it manually.' > requirements.txt
cat requirements-app.txt >> requirements.txt
echo '' >> requirements.txt
$$(pwd)/venv-freeze/bin/pip freeze -r <(sed '/^--/d' requirements-app.txt) | sed -n '/The following requirements were added by pip freeze/,$$p' >> requirements.txt
rm -rf venv-freeze
.PHONY: test-requirements
test-requirements:
@diff requirements-app.txt requirements.txt | grep '<' \
&& { echo "requirements.txt doesn't match requirements-app.txt."; \
echo "Run 'make freeze-requirements' to update."; exit 1; } \
|| { echo "requirements.txt is up to date"; exit 0; }
.PHONY: docker-build
docker-build: ## Build with docker
docker build --pull \
--build-arg HTTP_PROXY="${HTTP_PROXY}" \
--build-arg HTTPS_PROXY="${HTTP_PROXY}" \
--build-arg NO_PROXY="${NO_PROXY}" \
-t govuk/document-download-api:${GIT_COMMIT} \
.
.PHONY: test-with-docker
test-with-docker: docker-build ## Run all tests with docker
docker run --rm \
-e CIRCLECI=1 \
-e CI_BUILD_NUMBER=${BUILD_NUMBER} \
-e CI_BUILD_URL=${BUILD_URL} \
-e CI_NAME=${CI_NAME} \
-e CI_BRANCH=${GIT_BRANCH} \
-e CI_PULL_REQUEST=${CI_PULL_REQUEST} \
-e http_proxy="${http_proxy}" \
-e https_proxy="${https_proxy}" \
-e NO_PROXY="${NO_PROXY}" \
govuk/document-download-api:${GIT_COMMIT} \
make test
## DEPLOYMENT
.PHONY: preview
preview:
$(eval export CF_SPACE=preview)
$(eval export DNS_NAME=documents.notify.works)
cf target -s ${CF_SPACE}
.PHONY: staging
staging:
$(eval export CF_SPACE=staging)
$(eval export DNS_NAME=documents.staging-notify.works)
cf target -s ${CF_SPACE}
.PHONY: production
production:
$(eval export CF_SPACE=production)
$(eval export DNS_NAME=documents.service.gov.uk)
cf target -s ${CF_SPACE}
.PHONY: generate-manifest
generate-manifest: ## Generate manifest for the 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} --format=yaml \
<(${DECRYPT_CMD} ${NOTIFY_CREDENTIALS}/credentials/${CF_SPACE}/document-download/paas-environment.gpg) 2>&1
.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}"
.PHONY: cf-deploy
cf-deploy: ## 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 v3-cancel-zdt-push ${CF_APP} || true
cf v3-apply-manifest ${CF_APP} -f <(make -s generate-manifest)
cf v3-zdt-push ${CF_APP} --wait-for-deploy-complete
.PHONY: cf-rollback
cf-rollback: ## Rollbacks the app to the previous release
cf v3-cancel-zdt-push ${CF_APP}
.PHONY: cf-create-cdn-route
cf-create-cdn-route:
$(if ${CF_SPACE},,$(error Must specify CF_SPACE))
$(if ${DNS_NAME},,$(error Must specify DNS_NAME))
cf create-service cdn-route cdn-route documents-cdn-route -c '{"domain": "${DNS_NAME}"}'