Skip to content

Commit 71ee4c2

Browse files
authored
VED-810 (Child of VED-720) Standalone deploy Github Action to deploy backend (#851)
1 parent 95dcfbc commit 71ee4c2

File tree

14 files changed

+159
-209
lines changed

14 files changed

+159
-209
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
name: Deploy Backend
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
apigee_environment:
7+
required: true
8+
type: string
9+
create_mns_subscription:
10+
required: false
11+
type: boolean
12+
default: true
13+
environment:
14+
required: true
15+
type: string
16+
sub_environment:
17+
required: true
18+
type: string
19+
workflow_dispatch:
20+
inputs:
21+
apigee_environment:
22+
type: choice
23+
description: Select the Apigee proxy environment
24+
options:
25+
- internal-dev
26+
- int
27+
- ref
28+
- prod
29+
create_mns_subscription:
30+
description: Create an MNS Subscription. Only available in dev
31+
required: false
32+
type: boolean
33+
default: true
34+
environment:
35+
type: string
36+
description: Select the backend environment
37+
options:
38+
- dev
39+
- preprod
40+
- prod
41+
sub_environment:
42+
type: string
43+
description: Set the sub environment name e.g. pr-xxx, or green/blue in higher environments
44+
45+
jobs:
46+
terraform-plan:
47+
runs-on: ubuntu-latest
48+
environment:
49+
name: ${{ inputs.environment }}
50+
env: # Sonarcloud - do not allow direct usage of untrusted data
51+
APIGEE_ENVIRONMENT: ${{ inputs.apigee_environment }}
52+
BACKEND_ENVIRONMENT: ${{ inputs.environment }}
53+
BACKEND_SUB_ENVIRONMENT: ${{ inputs.sub_environment }}
54+
permissions:
55+
id-token: write
56+
contents: read
57+
steps:
58+
- name: Connect to AWS
59+
uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a
60+
with:
61+
aws-region: eu-west-2
62+
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/auto-ops
63+
role-session-name: github-actions
64+
65+
- name: Whoami
66+
run: aws sts get-caller-identity
67+
68+
- name: Checkout
69+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
70+
71+
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd
72+
with:
73+
terraform_version: "1.12.2"
74+
75+
- name: Terraform Init
76+
working-directory: ${{ vars.TERRAFORM_DIR_PATH }}
77+
run: make init apigee_environment=$APIGEE_ENVIRONMENT environment=$BACKEND_ENVIRONMENT sub_environment=$BACKEND_SUB_ENVIRONMENT
78+
79+
- name: Terraform Plan
80+
working-directory: ${{ vars.TERRAFORM_DIR_PATH }}
81+
run: make plan apigee_environment=$APIGEE_ENVIRONMENT environment=$BACKEND_ENVIRONMENT sub_environment=$BACKEND_SUB_ENVIRONMENT
82+
83+
terraform-apply:
84+
needs: terraform-plan
85+
runs-on: ubuntu-latest
86+
environment:
87+
name: ${{ inputs.environment }}
88+
env: # Sonarcloud - do not allow direct usage of untrusted data
89+
APIGEE_ENVIRONMENT: ${{ inputs.apigee_environment }}
90+
BACKEND_ENVIRONMENT: ${{ inputs.environment }}
91+
BACKEND_SUB_ENVIRONMENT: ${{ inputs.sub_environment }}
92+
permissions:
93+
id-token: write
94+
contents: read
95+
steps:
96+
- name: Checkout
97+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
98+
99+
- uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a
100+
with:
101+
aws-region: eu-west-2
102+
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/auto-ops
103+
role-session-name: github-actions
104+
105+
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd
106+
with:
107+
terraform_version: "1.12.2"
108+
109+
- name: Terraform Init
110+
working-directory: ${{ vars.TERRAFORM_DIR_PATH }}
111+
run: make init apigee_environment=$APIGEE_ENVIRONMENT environment=$BACKEND_ENVIRONMENT sub_environment=$BACKEND_SUB_ENVIRONMENT
112+
113+
- name: Terraform Apply
114+
working-directory: ${{ vars.TERRAFORM_DIR_PATH }}
115+
run: |
116+
make apply apigee_environment=$APIGEE_ENVIRONMENT environment=$BACKEND_ENVIRONMENT sub_environment=$BACKEND_SUB_ENVIRONMENT
117+
echo "ID_SYNC_QUEUE_ARN=$(make -s output name=id_sync_queue_arn)" >> $GITHUB_ENV
118+
119+
- name: Install poetry
120+
if: ${{ inputs.environment == 'dev' && inputs.create_mns_subscription }}
121+
run: pip install poetry==2.1.4
122+
123+
- uses: actions/setup-python@v5
124+
if: ${{ inputs.environment == 'dev' && inputs.create_mns_subscription }}
125+
with:
126+
python-version: 3.11
127+
cache: 'poetry'
128+
129+
- name: Create MNS Subscription
130+
if: ${{ inputs.environment == 'dev' && inputs.create_mns_subscription }}
131+
working-directory: './lambdas/mns_subscription'
132+
env:
133+
APIGEE_ENVIRONMENT: ${{ inputs.apigee_environment }}
134+
SQS_ARN: ${{ env.ID_SYNC_QUEUE_ARN }}
135+
run: |
136+
poetry install --no-root
137+
echo "Subscribing SQS to MNS for notifications..."
138+
make subscribe

.github/workflows/deploy-blue-green.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

.github/workflows/deploy-template.yml

Lines changed: 0 additions & 162 deletions
This file was deleted.

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ build-proxy:
4141
scripts/build_proxy.sh
4242

4343
#Files to loop over in release
44-
_dist_include="pytest.ini poetry.lock poetry.toml pyproject.toml Makefile build/. specification sandbox terraform scripts $(PYTHON_PROJECT_DIRS) $(PYTHON_LAMBDA_DEPENDENCIES)"
44+
# VED-811: remove everything except for proxy related files as we move to Github Actions for backend deployment
45+
_dist_include="pytest.ini poetry.lock poetry.toml pyproject.toml Makefile build/. specification sandbox terraform scripts"
4546

4647

4748
#Create /dist/ sub-directory and copy files into directory
49+
#Ensure full dir structure is preserved for Lambdas
4850
release: clean publish build-proxy
4951
mkdir -p dist
5052
for f in $(_dist_include); do cp -r $$f dist; done
53+
for f in $(PYTHON_PROJECT_DIRS); do cp --parents -r $$f dist; done
5154
cp ecs-proxies-deploy.yml dist/ecs-deploy-sandbox.yml
5255
cp ecs-proxies-deploy.yml dist/ecs-deploy-internal-qa-sandbox.yml
5356
cp ecs-proxies-deploy.yml dist/ecs-deploy-internal-dev-sandbox.yml

azure/templates/post-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ steps:
9393
echo "Subscribing SQS to MNS for notifications..."
9494
make subscribe
9595
displayName: "Run MNS Subscription"
96-
workingDirectory: "$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)/mns_subscription"
96+
workingDirectory: "$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)/lambdas/mns_subscription"
9797
env:
9898
SQS_ARN: "$(ID_SYNC_QUEUE_ARN)"
9999

backend/src/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ class Urls:
2424

2525
GENERIC_SERVER_ERROR_DIAGNOSTICS_MESSAGE = "Unable to process request. Issue may be transient."
2626
SUPPLIER_PERMISSIONS_HASH_KEY = "supplier_permissions"
27+
# Maximum response size for an AWS Lambda function
28+
MAX_RESPONSE_SIZE_BYTES = 6 * 1024 * 1024

backend/src/search_imms_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from fhir_controller import FhirController, make_controller
1111
from models.errors import Severity, Code, create_operation_outcome
12-
from constants import GENERIC_SERVER_ERROR_DIAGNOSTICS_MESSAGE
12+
from constants import GENERIC_SERVER_ERROR_DIAGNOSTICS_MESSAGE, MAX_RESPONSE_SIZE_BYTES
1313
from log_structure import function_info
1414
import base64
1515
import urllib.parse
@@ -57,7 +57,7 @@ def search_imms(event: events.APIGatewayProxyEventV1, controller: FhirController
5757
result_json = json.dumps(response)
5858
result_size = len(result_json.encode("utf-8"))
5959

60-
if result_size > 6 * 1024 * 1024:
60+
if result_size > MAX_RESPONSE_SIZE_BYTES:
6161
exp_error = create_operation_outcome(
6262
resource_id=str(uuid.uuid4()),
6363
severity=Severity.error,

backend/tests/sample_data/sample_input_search_imms.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

backend/tests/test_search_imms.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,12 @@ def test_search_immunizations_get_id_from_body_imms_identifer(self):
127127
self.controller.get_immunization_by_identifier.assert_called_once_with(lambda_event)
128128
self.assertDictEqual(exp_res, act_res)
129129

130+
@patch("search_imms_handler.MAX_RESPONSE_SIZE_BYTES", 10)
130131
def test_search_immunizations_lambda_size_limit(self):
131132
"""it should return 400 as search returned too many results."""
132133
lambda_event = {"pathParameters": {"id": "an-id"}, "body": None}
133-
request_file = script_location / "sample_data" / "sample_input_search_imms.json"
134-
with open(request_file) as f:
135-
exp_res = json.load(f)
136-
self.controller.search_immunizations.return_value = json.dumps(exp_res)
137134

138-
self.controller.search_immunizations.return_value = exp_res
135+
self.controller.search_immunizations.return_value = {"response": "size is larger than lambda limit"}
139136

140137
# When
141138
act_res = search_imms(lambda_event, self.controller)

0 commit comments

Comments
 (0)