|
1 | 1 | # This file is for you! Edit it to implement your own hooks (make targets) into |
2 | 2 | # the project as automated steps to be executed on locally and in the CD pipeline. |
3 | | - |
| 3 | +# ============================================================================== |
4 | 4 | include scripts/init.mk |
5 | 5 |
|
6 | | -# ============================================================================== |
| 6 | +MAKE_DIR := $(abspath $(shell pwd)) |
| 7 | + |
| 8 | +#Installs dependencies using poetry. |
| 9 | +install-python: |
| 10 | + poetry install |
| 11 | + |
| 12 | +#Installs dependencies using npm. |
| 13 | +install-node: |
| 14 | + npm install --legacy-peer-deps |
| 15 | + |
| 16 | +#Configures Git Hooks, which are scripts that run given a specified event. |
| 17 | +.git/hooks/pre-commit: |
| 18 | + cp scripts/pre-commit .git/hooks/pre-commit |
| 19 | + |
| 20 | +#Condensed Target to run all targets above. |
| 21 | +install: install-node install-python .git/hooks/pre-commit |
| 22 | + |
| 23 | +#Run the npm linting script (specified in package.json). Used to check the syntax and formatting of files. |
| 24 | +lint: |
| 25 | + # npm run lint |
| 26 | + poetry run ruff format . --check |
| 27 | + poetry run ruff check . |
| 28 | + poetry run pyright |
| 29 | + |
| 30 | + |
| 31 | +format: ## Format and fix code |
| 32 | + poetry run ruff format . |
| 33 | + poetry run ruff check . --fix-only |
| 34 | + |
| 35 | +#Creates the fully expanded OAS spec in json |
| 36 | +publish: clean |
| 37 | + mkdir -p build |
| 38 | + mkdir -p sandbox/specification |
| 39 | + npm run publish 2> /dev/null |
| 40 | + cp build/eligibility-signposting-api.json sandbox/specification/eligibility-signposting-api.json |
| 41 | +#Files to loop over in release |
| 42 | +_dist_include="pytest.ini poetry.lock poetry.toml pyproject.toml Makefile build/. tests" |
7 | 43 |
|
8 | 44 | # Example CI/CD targets are: dependencies, build, publish, deploy, clean, etc. |
9 | 45 |
|
10 | 46 | dependencies: # Install dependencies needed to build and test the project @Pipeline |
11 | | - # TODO: Implement installation of your project dependencies |
12 | | - |
13 | | -build: # Build the project artefact @Pipeline |
14 | | - # TODO: Implement the artefact build step |
| 47 | + scripts/dependencies.sh |
15 | 48 |
|
16 | | -publish: # Publish the project artefact @Pipeline |
17 | | - # TODO: Implement the artefact publishing step |
18 | 49 |
|
19 | | -deploy: # Deploy the project artefact to the target environment @Pipeline |
20 | | - # TODO: Implement the artefact deployment step |
21 | 50 |
|
22 | | -clean:: # Clean-up project resources (main) @Operations |
23 | | - # TODO: Implement project resources clean-up step |
24 | 51 |
|
25 | 52 | config:: # Configure development environment (main) @Configuration |
26 | 53 | # TODO: Use only 'make' targets that are specific to this project, e.g. you may not need to install Node.js |
27 | 54 | make _install-dependencies |
28 | 55 |
|
| 56 | +################## |
| 57 | +#### Proxygen #### |
| 58 | +################## |
| 59 | + |
| 60 | +retrieve-proxygen-key: # Obtain the 'machine user' credentials from AWS SSM (Development environment) |
| 61 | + mkdir -p ~/.proxygen && \ |
| 62 | + aws ssm get-parameter --name /proxygen/private_key_temp --with-decryption | jq ".Parameter.Value" --raw-output \ |
| 63 | + > ~/.proxygen/eligibility-signposting-api.pem |
| 64 | + |
| 65 | +setup-proxygen-credentials: # Copy Proxygen templated credentials to where it expected them |
| 66 | + cd specification && cp -r .proxygen ~ |
| 67 | + |
| 68 | +get-spec: # Get the most recent specification live in proxygen |
| 69 | + $(MAKE) setup-proxygen-credentials |
| 70 | + proxygen spec get |
| 71 | + |
| 72 | +# Specification |
| 73 | + |
| 74 | +guard-%: |
| 75 | + @ if [ "${${*}}" = "" ]; then \ |
| 76 | + echo "Variable $* not set"; \ |
| 77 | + exit 1; \ |
| 78 | + fi |
| 79 | + |
| 80 | +set-target: guard-APIM_ENV |
| 81 | + @ TARGET=target-$$APIM_ENV.yaml \ |
| 82 | + envsubst '$${TARGET}' \ |
| 83 | + < specification/x-nhsd-apim/target-template.yaml > specification/x-nhsd-apim/target.yaml |
| 84 | + |
| 85 | +set-access: guard-APIM_ENV |
| 86 | + @ ACCESS=access-$$APIM_ENV.yaml \ |
| 87 | + envsubst '$${ACCESS}' \ |
| 88 | + < specification/x-nhsd-apim/access-template.yaml > specification/x-nhsd-apim/access.yaml |
| 89 | + |
| 90 | +set-security: guard-APIM_ENV |
| 91 | + @ SECURITY=security-$$APIM_ENV.yaml \ |
| 92 | + envsubst '$${SECURITY}' \ |
| 93 | + < specification/components/security/security-template.yaml > specification/components/security/security.yaml |
| 94 | + |
| 95 | +set-ratelimit: guard-APIM_ENV |
| 96 | + @ RATELIMIT=ratelimit-$$APIM_ENV.yaml \ |
| 97 | + envsubst '$${RATELIMIT}' \ |
| 98 | + < specification/x-nhsd-apim/ratelimit-template.yaml > specification/x-nhsd-apim/ratelimit.yaml |
| 99 | + |
| 100 | +update-spec-template: guard-APIM_ENV |
| 101 | +ifeq ($(APIM_ENV), $(filter $(APIM_ENV), sandbox internal-dev int ref prod )) |
| 102 | + @ $(MAKE) set-target APIM_ENV=$$APIM_ENV |
| 103 | + @ $(MAKE) set-access APIM_ENV=$$APIM_ENV |
| 104 | + @ $(MAKE) set-security APIM_ENV=$$APIM_ENV |
| 105 | + @ $(MAKE) set-ratelimit APIM_ENV=$$APIM_ENV |
| 106 | +else |
| 107 | + @ echo ERROR: $$APIM_ENV is not a valid environment. Please use one of [sandbox, internal-dev, int, ref, prod] |
| 108 | + @ exit 1; |
| 109 | +endif |
| 110 | + |
| 111 | +construct-spec: guard-APIM_ENV |
| 112 | + @ $(MAKE) update-spec-template APIM_ENV=$$APIM_ENV |
| 113 | + mkdir -p build/specification && \ |
| 114 | + npx redocly bundle specification/eligibility-signposting-api.yaml --remove-unused-components --keep-url-references --ext yaml \ |
| 115 | + > build/specification/eligibility-signposting-api.yaml |
| 116 | +ifeq ($(APIM_ENV), sandbox) |
| 117 | + @ $(MAKE) publish |
| 118 | +endif |
| 119 | + |
| 120 | +SPEC_DIR := $(CURDIR)/specification |
| 121 | +POSTMAN_DIR := $(SPEC_DIR)/postman |
| 122 | + |
| 123 | +convert-postman: # Create Postman collection from OAS spec |
| 124 | + mkdir -p $(POSTMAN_DIR) |
| 125 | + cp $(SPEC_DIR)/eligibility-signposting-api.yaml $(POSTMAN_DIR)/ |
| 126 | + docker build -t portman-converter -f $(POSTMAN_DIR)/Dockerfile $(SPEC_DIR) |
| 127 | + docker run --rm -v $(SPEC_DIR):/app portman-converter \ |
| 128 | + portman -l /app/eligibility-signposting-api.yaml -o /app/postman/collection.json |
| 129 | + rm $(POSTMAN_DIR)/eligibility-signposting-api.yaml |
29 | 130 | # ============================================================================== |
30 | 131 |
|
31 | 132 | ${VERBOSE}.SILENT: \ |
|
0 commit comments