forked from DFE-Digital/publish-teacher-training-2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
131 lines (113 loc) · 5.5 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
ifndef VERBOSE
.SILENT:
endif
help:
echo "Environment setup targets:"
echo " review - configure for review app"
echo " qa"
echo " staging"
echo " production"
echo ""
echo "Commands:"
echo " deploy-plan - Print out the plan for the deploy, does not deploy."
echo ""
echo "Command Options:"
echo " APP_NAME - name of the review application being setup, only required when DEPLOY_ENV is review"
echo " IMAGE_TAG - git sha of a built image, see builds in GitHub Actions"
echo " PASSCODE - your authentication code for GOVUK PaaS, retrieve from"
echo " https://login.london.cloud.service.gov.uk/passcode"
echo ""
echo "Examples:"
echo " Create a review app"
echo " You will need to retrieve the authentication code from GOVUK PaaS"
echo " visit https://login.london.cloud.service.gov.uk/passcode. Then run"
echo " deploy-plan to test:"
echo ""
echo " make review APP_NAME=<APP_NAME> deploy-plan IMAGE_TAG=GIT_REF PASSCODE=<CF_SSO_CODE>"
echo " Delete a review app"
echo ""
echo " make review APP_NAME=<APP_NAME> destroy IMAGE_TAG=GIT_REF PASSCODE=<CF_SSO_CODE>"
echo "Examples:"
echo " Deploy an pre-built image to qa"
echo ""
echo " make qa deploy IMAGE_TAG=GIT_REF PASSCODE=<CF_SSO_CODE>"
review:
$(eval DEPLOY_ENV=review)
$(if $(APP_NAME), , $(error Missing environment variable "APP_NAME", Please specify a name for your review app))
$(eval AZ_SUBSCRIPTION=s121-findpostgraduateteachertraining-development)
$(eval backend_key=-backend-config=key=pr-$(APP_NAME).tfstate)
$(eval export TF_VAR_paas_app_environment_config=review)
$(eval export TF_VAR_paas_app_environment=review-$(APP_NAME))
$(eval export TF_VAR_paas_web_app_host_name=$(APP_NAME))
echo Review app: https://publish-teacher-training-pr-$(APP_NAME).london.cloudapps.digital in bat-qa space
.PHONY: local
local: ## Configure local dev environment
$(eval DEPLOY_ENV=local)
$(eval AZ_SUBSCRIPTION=s121-findpostgraduateteachertraining-development)
.PHONY: qa
qa: ## Set DEPLOY_ENV to qa
$(eval DEPLOY_ENV=qa)
$(eval AZ_SUBSCRIPTION=s121-findpostgraduateteachertraining-development)
$(eval space=bat-qa)
$(eval paas_env=qa)
.PHONY: staging
staging: ## Set DEPLOY_ENV to staging
$(eval DEPLOY_ENV=staging)
$(eval AZ_SUBSCRIPTION=s121-findpostgraduateteachertraining-test)
$(eval space=bat-staging)
$(eval paas_env=staging)
.PHONY: sandbox
sandbox: ## Set DEPLOY_ENV to sandbox
$(eval DEPLOY_ENV=sandbox)
$(eval AZ_SUBSCRIPTION=s121-findpostgraduateteachertraining-production)
$(eval space=bat-prod)
$(eval paas_env=sandbox)
.PHONY: production
production: ## Set DEPLOY_ENV to production
$(eval DEPLOY_ENV=production)
$(eval AZ_SUBSCRIPTION=s121-findpostgraduateteachertraining-production)
$(if $(CONFIRM_PRODUCTION), , $(error Production can only run with CONFIRM_PRODUCTION))
$(eval space=bat-prod)
$(eval paas_env=prod)
.PHONY: ci
ci: ## Run in automation
$(eval export DISABLE_PASSCODE=true)
$(eval export AUTO_APPROVE=-auto-approve)
install-fetch-config:
[ ! -f bin/fetch_config.rb ] \
&& curl -s https://raw.githubusercontent.com/DFE-Digital/bat-platform-building-blocks/master/scripts/fetch_config/fetch_config.rb -o bin/fetch_config.rb \
&& chmod +x bin/fetch_config.rb \
|| true
set-azure-account:
az account set -s ${AZ_SUBSCRIPTION}
edit-app-secrets: install-fetch-config set-azure-account
. terraform/workspace_variables/$(DEPLOY_ENV).sh && bin/fetch_config.rb -s azure-key-vault-secret:$${TF_VAR_key_vault_name}/$${TF_VAR_key_vault_app_secret_name} \
-e -d azure-key-vault-secret:$${TF_VAR_key_vault_name}/$${TF_VAR_key_vault_app_secret_name} -f yaml -c
edit-infra-secrets: install-fetch-config set-azure-account
. terraform/workspace_variables/$(DEPLOY_ENV).sh && bin/fetch_config.rb -s azure-key-vault-secret:$${TF_VAR_key_vault_name}/$${TF_VAR_key_vault_infra_secret_name} \
-e -d azure-key-vault-secret:$${TF_VAR_key_vault_name}/$${TF_VAR_key_vault_infra_secret_name} -f yaml -c
print-app-secrets: install-fetch-config set-azure-account
. terraform/workspace_variables/$(DEPLOY_ENV).sh && bin/fetch_config.rb -s azure-key-vault-secret:$${TF_VAR_key_vault_name}/$${TF_VAR_key_vault_app_secret_name} \
-f yaml
deploy-init:
$(if $(IMAGE_TAG), , $(eval export IMAGE_TAG=master))
$(if $(or $(DISABLE_PASSCODE),$(PASSCODE)), , $(error Missing environment variable "PASSCODE", retrieve from https://login.london.cloud.service.gov.uk/passcode))
$(eval export TF_VAR_paas_sso_passcode=$(PASSCODE))
$(eval export TF_VAR_paas_docker_image=dfedigital/publish-teacher-training:$(IMAGE_TAG))
$(eval export TF_VAR_paas_app_config_file=./workspace_variables/app_config.yml)
$(eval export TF_VAR_paas_app_secrets_file=./workspace_variables/app_secrets.yml)
az account set -s ${AZ_SUBSCRIPTION} && az account show
cd terraform && terraform init -reconfigure -backend-config=workspace_variables/$(DEPLOY_ENV)_backend.tfvars $(backend_key)
echo "🚀 DEPLOY_ENV is $(DEPLOY_ENV)"
deploy-plan: deploy-init
cd terraform && . workspace_variables/$(DEPLOY_ENV).sh \
&& terraform plan -var-file=workspace_variables/$(DEPLOY_ENV).tfvars
deploy: deploy-init
cd terraform && . workspace_variables/$(DEPLOY_ENV).sh \
&& terraform apply -var-file=workspace_variables/$(DEPLOY_ENV).tfvars $(AUTO_APPROVE)
destroy: deploy-init
cd terraform && . workspace_variables/$(DEPLOY_ENV).sh \
&& terraform destroy -var-file=workspace_variables/$(DEPLOY_ENV).tfvars $(AUTO_APPROVE)
console:
cf target -s ${space}
cf ssh publish-teacher-training-${paas_env} -t -c "cd /app && /usr/local/bin/bundle exec rails c"