generated from NHSDigital/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
110 lines (95 loc) · 5.02 KB
/
Makefile
File metadata and controls
110 lines (95 loc) · 5.02 KB
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
# This file is for you! Edit it to implement your own hooks (make targets) into
# the project as automated steps to be executed on locally and in the CD pipeline.
include scripts/init.mk
# ==============================================================================
# Example CI/CD targets are: dependencies, build, publish, deploy, clean, etc.
dependencies: # Install dependencies needed to build and test the project @Pipeline
python3 -m venv .venv
source .venv/bin/activate && pip install --upgrade pip && pip install -r dependencies.txt -r dev_dependencies.txt
build: # Build the project artefact @Pipeline
python3 -m venv .venv
rm -rf package
rm -f src/lambda_function.zip || true
mkdir package
source .venv/bin/activate && \
pip install -r dependencies.txt --target ./package && \
pip install \
--platform manylinux2014_x86_64 \
--implementation cp \
--python-version 3.13 \
--only-binary=:all: \
--upgrade pydantic \
--target ./package
pushd package
zip -r ../src/lambda_function.zip . -x __pycache__ > /dev/null
popd
pushd src/lambda_function
zip -r ../lambda_function.zip . -x __pycache__ > /dev/null
popd
publish: # Publish the project artefact @Pipeline
@echo "Publishing lambda_function.zip to S3 artifact bucket..."
@BUCKET_NAME="$${REPO_NAME}-$${ENVIRONMENT}-triage-artifact"; \
echo "Target S3 bucket: $$BUCKET_NAME"; \
aws s3 cp src/lambda_function.zip s3://$$BUCKET_NAME/lambda_function.zip
@echo "Successfully published lambda_function.zip"
deploy-local: build # Deploy the project artefact to the target environment @Pipeline
echo "Deploying to localstack"
echo "Pre-requisites: Docker is running; Localstack is running"
(cd src; ./deploy.sh localstack)
deploy: build
echo "Deploying to AWS"
echo "Pre-requisites: AWS credentials are configured"
(cd src; ./deploy.sh)
update-local: build
echo "Updating local lambdas"
(cd src; ./update.sh)
clean-local:
docker ps | grep triageapilambda | awk '{print $$1}' | xargs --no-run-if-empty docker rm -f
clean-slate: clean-local
rm -rf .venv
rm -f .coverage coverage_report.txt src/lambda_function.zip
find . | grep -E "/__pycache__" | xargs rm -rf
localstack restart || localstack start -d
make dependencies
SKIP_DEPS=true make test-coverage test-lint
clean:: # Clean-up project resources (main) @Operations
echo "Deleting LambdaS3ReadAccess role policy..."
aws iam delete-role-policy --role-name triageApiLambda-ex-role --policy-name LambdaS3ReadAccess || echo "LambdaS3ReadAccess role policy not found"
echo "Deleting AWSLambdaBasicExecutionRole role policy..."
aws iam detach-role-policy --role-name triageApiLambda-ex-role --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole || echo "AWSLambdaBasicExecutionRole role policy not found"
echo "Deleting AWSXRayDaemonWriteAccess role policy..."
aws iam detach-role-policy --role-name triageApiLambda-ex-role --policy-arn arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess || echo "AWSXRayDaemonWriteAccess role policy not found"
echo "Deleting AWSLambdaDynamoDBExecutionRole role policy..."
aws iam detach-role-policy --role-name triageApiLambda-ex-role --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole || echo "AWSLambdaDynamoDBExecutionRole role policy not found"
echo "Deleting DynamoDBLambdaAccess role policy..."
aws iam delete-role-policy --role-name triageApiLambda-ex-role --policy-name DynamoDBLambdaAccess || echo "DynamoDBLambdaAccess role policy not found"
echo "Deleting triageApiLambda-ex-role role..."
aws iam delete-role --role-name triageApiLambda-ex-role || echo "Role not found"
echo "Deleting triageApiLambda-apig function..."
aws lambda delete-function --function-name triageApiLambda-apig || echo "Function not found"
echo "Deleting triageApiLambda-s3 function..."
aws lambda delete-function --function-name triageApiLambda-s3 || echo "Function not found"
echo "Deleting pathways-data-bucket bucket..."
aws s3 rm 's3://pathways-data-bucket' --recursive || echo "Bucket not found"
aws s3api delete-bucket --bucket pathways-data-bucket || echo "Bucket not found"
echo "Deleting StartingCoords table..."
aws dynamodb delete-table --table-name StartingCoords --no-cli-pager || echo "Table not found"
aws dynamodb wait table-not-exists --table-name StartingCoords
echo "Deleting TriageNodes table..."
aws dynamodb delete-table --table-name TriageNodes --no-cli-pager || echo "Table not found"
aws dynamodb wait table-not-exists --table-name TriageNodes
echo "Deleting BodyMaps table..."
aws dynamodb delete-table --table-name BodyMaps --no-cli-pager || echo "Table not found"
aws dynamodb wait table-not-exists --table-name BodyMaps
chmod +x ./src/delete-apis.sh
(cd src; ./delete-apis.sh)
config:: # Configure development environment (main) @Configuration
# TODO: Use only 'make' targets that are specific to this project, e.g. you may not need to install Node.js
make _install-dependencies
# ==============================================================================
${VERBOSE}.SILENT: \
build \
clean \
config \
dependencies \
deploy \