-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMakefile
124 lines (98 loc) · 4.62 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
ifndef VERBOSE
.SILENT:
endif
help:
echo "Secrets:"
echo " This makefile gives the user the ability to safely display and edit azure secrets which are used by this project. "
echo ""
echo "Commands:"
echo " edit-app-secrets - Edit Application specific Secrets."
echo " print-app-secrets - Display Application specific Secrets."
echo ""
echo "Parameters:"
echo "All commands take the parameter development|review|test|production"
echo ""
echo "Examples:"
echo ""
echo "To edit the Application secrets for Development"
echo " make development edit-app-secrets"
echo ""
APPLICATION_SECRETS=CONTENT-KEYS
PAGESPEED_SECRETS=PAGE-SPEED-KEYS
INFRA_SECRETS=INFRA-KEYS
DOCKER_IMAGE=get-into-teaching-app
.PHONY: development
development:
$(eval export DEPLOY_ENV=dev)
$(eval export KEY_VAULT=s146d01-kv)
$(eval export AZ_SUBSCRIPTION=s146-getintoteachingwebsite-development)
.PHONY: local
local:
$(eval export KEY_VAULT=s146d01-local2-kv)
$(eval export AZ_SUBSCRIPTION=s146-getintoteachingwebsite-development)
.PHONY: review
review:
$(if $(PR_NUMBER), , $(error Missing environment variable "PR_NUMBER", Please specify a pr number for your review app))
$(eval export PR_NAME=review-get-into-teaching-app-${PR_NUMBER})
$(eval export DEPLOY_ENV=review)
$(eval export KEY_VAULT=s146d01-kv)
$(eval export AZ_SUBSCRIPTION=s146-getintoteachingwebsite-development)
$(eval BACKEND_KEY=-backend-config=key=${PR_NAME}.tfstate)
$(eval export TF_VAR_paas_app_application_name=${PR_NAME})
$(eval export TF_VAR_paas_app_route_name=${PR_NAME})
.PHONY: test
test:
$(eval export DEPLOY_ENV=staging)
$(eval export KEY_VAULT=s146t01-kv)
$(eval export AZ_SUBSCRIPTION=s146-getintoteachingwebsite-test)
.PHONY: production
production:
$(eval export DEPLOY_ENV=production)
$(eval export KEY_VAULT=s146p01-kv)
$(eval export AZ_SUBSCRIPTION=s146-getintoteachingwebsite-production)
set-azure-account:
az account set -s ${AZ_SUBSCRIPTION}
clean:
[ ! -f fetch_config.rb ] \
rm -f fetch_config.rb \
|| true
install-fetch-config:
[ ! -f fetch_config.rb ] \
&& echo "Installing fetch_config.rb" \
&& curl -s https://raw.githubusercontent.com/DFE-Digital/bat-platform-building-blocks/master/scripts/fetch_config/fetch_config.rb -o fetch_config.rb \
&& chmod +x fetch_config.rb \
|| true
edit-app-secrets: install-fetch-config set-azure-account
./fetch_config.rb -s azure-key-vault-secret:${KEY_VAULT}/${APPLICATION_SECRETS} -e -d azure-key-vault-secret:${KEY_VAULT}/${APPLICATION_SECRETS} -f yaml -c
print-app-secrets: install-fetch-config set-azure-account
./fetch_config.rb -s azure-key-vault-secret:${KEY_VAULT}/${APPLICATION_SECRETS} -f yaml
edit-ps-secrets: install-fetch-config set-azure-account
./fetch_config.rb -s azure-key-vault-secret:${KEY_VAULT}/${PAGESPEED_SECRETS} -e -d azure-key-vault-secret:${KEY_VAULT}/${PAGESPEED_SECRETS} -f yaml -c
print-ps-secrets: install-fetch-config set-azure-account
./fetch_config.rb -s azure-key-vault-secret:${KEY_VAULT}/${PAGESPEED_SECRETS} -f yaml
edit-infra-secrets: install-fetch-config set-azure-account
./fetch_config.rb -s azure-key-vault-secret:${KEY_VAULT}/${INFRA_SECRETS} -e -d azure-key-vault-secret:${KEY_VAULT}/${INFRA_SECRETS} -f yaml -c
print-infra-secrets: install-fetch-config set-azure-account
./fetch_config.rb -s azure-key-vault-secret:${KEY_VAULT}/${INFRA_SECRETS} -f yaml
setup-local-env: install-fetch-config set-azure-account
./fetch_config.rb -s yaml-file:.env.development.yml -s azure-key-vault-secret:s146d01-local2-kv/${APPLICATION_SECRETS} -f shell-env-var > .env.development
docker:
docker build . -t ${DOCKER_IMAGE}
specs:
docker run -t --rm -e RAILS_ENV=test ${DOCKER_IMAGE} rspec spec/features/funding_widget_spec.rb
.PHONY: ci
ci:
$(eval AUTO_APPROVE=-auto-approve)
terraform-init: set-azure-account
$(if $(or $(IMAGE_TAG), $(NO_IMAGE_TAG_DEFAULT)), , $(eval export IMAGE_TAG=master))
$(if $(IMAGE_TAG), , $(error Missing environment variable "IMAGE_TAG"))
$(eval export TF_VAR_paas_app_docker_image=ghcr.io/dfe-digital/get-into-teaching-frontend:$(IMAGE_TAG))
terraform -chdir=terraform/paas init -reconfigure -backend-config=${DEPLOY_ENV}.bk.vars ${BACKEND_KEY}
terraform-plan: terraform-init
terraform -chdir=terraform/paas plan -var-file=${DEPLOY_ENV}.env.tfvars
terraform: terraform-init
terraform -chdir=terraform/paas apply -var-file=${DEPLOY_ENV}.env.tfvars ${AUTO_APPROVE}
terraform-destroy: terraform-init
terraform -chdir=terraform/paas destroy -var-file=${DEPLOY_ENV}.env.tfvars ${AUTO_APPROVE}
delete-state-file:
az storage blob delete --container-name pass-tfstate --delete-snapshots include --account-name s146d01sgtfstate -n ${PR_NAME}.tfstate