-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
215 lines (172 loc) · 8.27 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
.EXPORT_ALL_VARIABLES:
.NOTPARALLEL:
.PHONY: *
MAKEFLAGS := --no-print-directory
SHELL := /bin/bash
DIST_PATH ?= ./dist
TEST_ARGS ?= --cov --cov-report=term-missing
SMOKE_TEST_ARGS ?=
FEATURE_TEST_ARGS ?= ./tests/features --format progress2
TF_WORKSPACE_NAME ?= $(shell terraform -chdir=terraform/infrastructure workspace show)
ENV ?= dev
APP_ALIAS ?= default
HOST ?= $(TF_WORKSPACE_NAME).api.record-locator.$(ENV).national.nhs.uk
ENV_TYPE ?= $(ENV)
export PATH := $(PATH):$(PWD)/.venv/bin
export USE_SHARED_RESOURCES := $(shell poetry run python scripts/are_resources_shared_for_stack.py $(TF_WORKSPACE_NAME))
default: build
help: ## Show this help message
@echo "Usage: make [target]"
@echo
@echo "where [target] can be:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-30s\033[0m %s\n", $$1, $$2}'
asdf-install: ## Install the required tools via ASDF
@cat .tool-versions | while read tool_version; do \
tool="$${tool_version% *}"; \
asdf plugin add "$${tool}"; \
done
asdf install
configure: asdf-install check-warn ## Configure this project repo, including install dependencies
cp scripts/commit-msg.py .git/hooks/prepare-commit-msg && chmod ug+x .git/hooks/*
poetry install
poetry run pre-commit install
check: ## Check the build environment is setup correctly
@./scripts/check-build-environment.sh
check-warn:
@SHOULD_WARN_ONLY=true ./scripts/check-build-environment.sh
check-deploy: ## check the deploy environment is setup correctly
@./scripts/check-deploy-environment.sh
check-deploy-warn:
@SHOULD_WARN_ONLY=true ./scripts/check-deploy-environment.sh
build: check-warn build-api-packages build-layers build-dependency-layer ## Build the project
build-dependency-layer:
@echo "Building Lambda dependency layer"
@mkdir -p $(DIST_PATH)
./scripts/build-lambda-dependency-layer.sh $(DIST_PATH)
build-layers: ./layer/*
@echo "Building Lambda layers"
@mkdir -p $(DIST_PATH)
for layer in $^; do \
[ ! -d "$$layer" ] && continue; \
./scripts/build-lambda-layer.sh $${layer} $(DIST_PATH); \
done
build-api-packages: ./api/consumer/* ./api/producer/*
@echo "Building API packages"
@mkdir -p $(DIST_PATH)
for api in $^; do \
[ ! -d "$$api" ] && continue; \
./scripts/build-lambda-package.sh $${api} $(DIST_PATH); \
done
test: check-warn ## Run the unit tests
@echo "Running unit tests"
pytest --ignore=tests/smoke $(TEST_ARGS)
test-features-integration: check-warn ## Run the BDD feature tests in the integration environment
@echo "Running feature tests in the integration environment ${TF_WORKSPACE_NAME}"
behave --define="integration_test=true" \
--define="env=$(TF_WORKSPACE_NAME)" \
--define="account_name=$(ENV)" \
--define="use_shared_resources=${USE_SHARED_RESOURCES}" \
$(FEATURE_TEST_ARGS)
integration-test-with-custom_tag:
@echo "Running feature tests in the integration environment ${TF_WORKSPACE_NAME}"
behave --define="integration_test=true" --tags=@custom_tag \
--define="env=$(TF_WORKSPACE_NAME)" \
--define="account_name=$(ENV)" \
--define="use_shared_resources=${USE_SHARED_RESOURCES}" \
$(FEATURE_TEST_ARGS)
test-features-integration-report: check-warn ## Run the BDD feature tests in the integration environment and generate allure report therafter
@echo "Cleaning previous Allure results and reports"
rm -rf ./allure-results
rm -rf ./allure-report
@echo "Running feature tests in the integration environment"
behave --define="integration_test=true" \
--define="env=$(TF_WORKSPACE_NAME)" \
--define="account_name=$(ENV)" \
--define="use_shared_resources=${USE_SHARED_RESOURCES}" \
$(FEATURE_TEST_ARGS)
@echo "Generating Allure report"
allure generate ./allure-results -o ./allure-report --clean
@echo "Opening Allure report"
allure open ./allure-report
test-smoke-internal: check-warn ## Run the smoke tests against the internal environment
@echo "Running smoke tests against the internal environment ${TF_WORKSPACE_NAME}"
TEST_ENVIRONMENT_NAME=$(ENV) \
TEST_STACK_NAME=$(TF_WORKSPACE_NAME) \
TEST_STACK_DOMAIN=$(shell terraform -chdir=terraform/infrastructure output -raw domain 2>/dev/null) \
TEST_CONNECT_MODE="internal" \
pytest ./tests/smoke/scenarios/* $(SMOKE_TEST_ARGS)
test-smoke-public: check-warn ## Run the smoke tests for the external access points
@echo "Running smoke tests for the public endpoints ${ENV}"
TEST_ENVIRONMENT_NAME=$(ENV) \
TEST_STACK_NAME=$(TF_WORKSPACE_NAME) \
TEST_CONNECT_MODE="public" \
pytest ./tests/smoke/scenarios/* $(SMOKE_TEST_ARGS)
test-performance-prepare:
mkdir -p $(DIST_PATH)
PYTHONPATH=. poetry run python tests/performance/environment.py setup $(TF_WORKSPACE_NAME)
test-performance: check-warn test-performance-baseline test-performance-stress ## Run the performance tests
test-performance-baseline:
@echo "Running consumer performance baseline test"
k6 run --out csv=$(DIST_PATH)/consumer-baseline.csv tests/performance/consumer/baseline.js -e HOST=$(HOST) -e ENV_TYPE=$(ENV_TYPE)
test-performance-stress:
@echo "Running consumer performance stress test"
k6 run --out csv=$(DIST_PATH)/consumer-stress.csv tests/performance/consumer/stress.js -e HOST=$(HOST) -e ENV_TYPE=$(ENV_TYPE)
test-performance-soak:
@echo "Running consumer performance soak test"
k6 run --out csv=$(DIST_PATH)/consumer-soak.csv tests/performance/consumer/soak.js -e HOST=$(HOST) -e ENV_TYPE=$(ENV_TYPE)
test-performance-output: ## Process outputs from the performance tests
@echo "Processing performance test outputs"
poetry run python tests/performance/process_results.py baseline $(DIST_PATH)/consumer-baseline.csv
poetry run python tests/performance/process_results.py stress $(DIST_PATH)/consumer-stress.csv
test-performance-cleanup:
PYTHONPATH=. poetry run python tests/performance/environment.py cleanup $(TF_WORKSPACE_NAME)
lint: check-warn ## Lint the project
SKIP="no-commit-to-branch" pre-commit run --all-files
clean: ## Remove all generated and temporary files
[ -n "$(DIST_PATH)" ] && \
rm -rf $(DIST_PATH)/*.zip && \
rmdir $(DIST_PATH) 2>/dev/null || true
get-access-token: check-warn ## Get an access token for an environment
@poetry run python tests/utilities/get_access_token.py $(ENV) $(APP_ALIAS)
get-s3-perms: check-warn ## Get s3 permissions for an environment
poetry run python scripts/get_s3_permissions.py ${USE_SHARED_RESOURCES} $(ENV) $(TF_WORKSPACE_NAME) "$(DIST_PATH)"
@echo "Creating new Lambda NRLF permissions layer zip"
./scripts/add-perms-to-lambda.sh $(DIST_PATH)
set-smoketest-perms: check-warn ## Set the permissions for the smoke tests
@echo "Setting permissions for smoke tests of env=$(ENV) stack=$(TF_WORKSPACE_NAME)...."
poetry run python scripts/set_smoketest_permissions.py $(ENV) $(TF_WORKSPACE_NAME) $(ENV)
truststore-build-all: check-warn ## Build all truststore resources
@./scripts/truststore.sh build-all
truststore-build-ca: check-warn ## Build a CA (Certificate Authority)
@./scripts/truststore.sh build-ca "$(CA_NAME)" "$(CA_SUBJECT)"
truststore-build-cert: check-warn ## Build a certificate
@./scripts/truststore.sh build-cert "$(CA_NAME)" "$(CERT_NAME)" "$(CERT_SUBJECT)"
truststore-pull-server: check-warn ## Pull a server certificate
@./scripts/truststore.sh pull-server "$(ENV)"
truststore-pull-client: check-warn ## Pull a client certificate
@./scripts/truststore.sh pull-client "$(ENV)"
truststore-pull-ca: check-warn ## Pull a CA certificate
@./scripts/truststore.sh pull-ca "$(ENV)"
swagger-merge: check-warn ## Generate Swagger Documentation
@./scripts/swagger.sh merge "$(TYPE)"
generate-models: check-warn ## Generate Pydantic Models
@echo "Generating producer models"
mkdir -p ./layer/nrlf/producer/fhir/r4
poetry run datamodel-codegen \
--input ./api/producer/swagger.yaml \
--input-file-type openapi \
--output ./layer/nrlf/producer/fhir/r4/model.py \
--output-model-type "pydantic_v2.BaseModel"
poetry run datamodel-codegen \
--strict-types {str,bytes,int,float,bool} \
--input ./api/producer/swagger.yaml \
--input-file-type openapi \
--output ./layer/nrlf/producer/fhir/r4/strict_model.py \
--output-model-type "pydantic_v2.BaseModel"
@echo "Generating consumer model"
mkdir -p ./layer/nrlf/consumer/fhir/r4
poetry run datamodel-codegen \
--input ./api/consumer/swagger.yaml \
--input-file-type openapi \
--output ./layer/nrlf/consumer/fhir/r4/model.py \
--output-model-type "pydantic_v2.BaseModel"