Skip to content

Commit aa3c704

Browse files
committed
Pipeline in folder
1 parent 7779b4f commit aa3c704

File tree

4 files changed

+246
-46
lines changed

4 files changed

+246
-46
lines changed

azure/azure-pr-new-int-pipeline.yml

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
trigger: none
2+
pr: none
3+
4+
stages:
5+
- stage: GreenDeploy
6+
displayName: "Deploy to Green"
7+
jobs:
8+
- template: templates/deploy-int-job.yml
9+
parameters:
10+
environmentName: green-env
11+
- stage: BlueDeploy
12+
displayName: "Deploy to Blue"
13+
dependsOn: GreenDeploy
14+
jobs:
15+
- template: templates/deploy-int-job.yml
16+
parameters:
17+
environmentName: blue-env
18+
19+
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
parameters:
2+
- name: aws_dev
3+
default: aws --profile=apim-dev
4+
- name: is_ptl
5+
default: true
6+
- name: 'aws_account_type'
7+
type: string
8+
- name: tf_dir
9+
type: string
10+
default: "terraform"
11+
- name: tf_environment
12+
type: string
13+
default: "green"
14+
15+
steps:
16+
- ${{ if parameters.is_ptl }}:
17+
- template: "azure/components/aws-assume-role.yml@common"
18+
parameters:
19+
role: "auto-ops"
20+
profile: "apm_ptl"
21+
22+
- template: "azure/components/get-aws-secrets-and-ssm-params.yml@common"
23+
parameters:
24+
secret_file_ids:
25+
- ptl/app-credentials/jwt_testing/non-prod/JWT_TESTING_PRIVATE_KEY
26+
secret_ids:
27+
- ptl/app-credentials/immunisation-fhir-api-testing-app/non-prod/INTROSPECTION_CLIENT_ID
28+
- ptl/app-credentials/immunisation-fhir-api-testing-app/non-prod/INTROSPECTION_CLIENT_SECRET
29+
- ptl/app-credentials/immunisation-fhir-api-testing-app/non-prod/INTROSPECTION_CLIENT_ID_INT
30+
- ptl/app-credentials/immunisation-fhir-api-testing-app/non-prod/INTROSPECTION_CLIENT_SECRET_INT
31+
- ptl/app-credentials/immunisation-fhir-api-testing-app/non-prod/INT_CLIENT_ID
32+
- ptl/app-credentials/immunisation-fhir-api-testing-app/non-prod/INT_CLIENT_SECRET
33+
34+
- bash: |
35+
make install-python
36+
workingDirectory: $(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)
37+
displayName: Setup pytests
38+
condition: always()
39+
40+
- template: ./aws-assume-role.yml
41+
parameters:
42+
role: "auto-ops"
43+
profile: "apim-dev"
44+
aws_account: ${{ parameters.aws_account_type }}
45+
46+
- bash: |
47+
set -e
48+
if ! [[ $APIGEE_ENVIRONMENT =~ .*-*sandbox ]]; then
49+
export AWS_PROFILE=apim-dev
50+
aws_account_no="$(aws sts get-caller-identity --query Account --output text)"
51+
52+
service_name=$(FULLY_QUALIFIED_SERVICE_NAME)
53+
54+
pr_no=$(echo $service_name | { grep -oE '[0-9]+$' || true; })
55+
if [ -z $pr_no ]; then
56+
workspace=${{ parameters.tf_environment }}
57+
else
58+
workspace=pr-$pr_no
59+
fi
60+
61+
echo sandbox with following parameters:
62+
echo service_name: $service_name
63+
echo workspace: $workspace
64+
echo Apigee environment: $APIGEE_ENVIRONMENT
65+
echo pr_no: $pr_no
66+
67+
echo "Moving to dir: ${{ parameters.tf_dir }}"
68+
cd ${{ parameters.tf_dir }}
69+
70+
make init
71+
make plan environment=$workspace bucket_name=immunisation-preprod-terraform-state-files
72+
# make apply aws_account_no=${aws_account_no} environment=$workspace
73+
74+
AWS_DOMAIN_NAME=$(make -s output name=service_domain_name)
75+
IMMS_DELTA_TABLE_NAME=$(make -s output name=imms_delta_table_name)
76+
DYNAMODB_TABLE_NAME=$(make -s output name=dynamodb_table_name)
77+
AWS_SQS_QUEUE_NAME=$(make -s output name=aws_sqs_queue_name)
78+
AWS_SNS_TOPIC_NAME=$(make -s output name=aws_sns_topic_name)
79+
echo "##vso[task.setvariable variable=DYNAMODB_TABLE_NAME]$DYNAMODB_TABLE_NAME"
80+
echo "##vso[task.setvariable variable=AWS_DOMAIN_NAME]$AWS_DOMAIN_NAME"
81+
echo "##vso[task.setvariable variable=IMMS_DELTA_TABLE_NAME]$IMMS_DELTA_TABLE_NAME"
82+
echo "##vso[task.setvariable variable=AWS_SQS_QUEUE_NAME]$AWS_SQS_QUEUE_NAME"
83+
echo "##vso[task.setvariable variable=AWS_SNS_TOPIC_NAME]$AWS_SNS_TOPIC_NAME"
84+
fi
85+
displayName: Apply Terraform
86+
workingDirectory: "$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)"
87+
retryCountOnTaskFailure: 2
88+
89+
- bash: |
90+
set -ex
91+
92+
endpoint=""
93+
if [[ $APIGEE_ENVIRONMENT =~ "prod" ]]; then
94+
endpoint="https://api.service.nhs.uk/${SERVICE_BASE_PATH}/_status"
95+
else
96+
endpoint="https://${APIGEE_ENVIRONMENT}.api.service.nhs.uk/${SERVICE_BASE_PATH}/_status"
97+
fi
98+
99+
counter=0
100+
while [[ $counter -lt 31 ]]; do
101+
response=$(curl -H "apikey: $(status-endpoint-api-key)" -s "$endpoint")
102+
response_code=$(jq -r '.checks.healthcheck.responseCode' <<< "$response")
103+
response_body=$(jq -r '.checks.healthcheck.outcome' <<< "$response")
104+
status=$(jq -r '.status' <<< "$response")
105+
if [ "$response_code" -eq 200 ] && [ "$response_body" == "OK" ] && [ "$status" == "pass" ]; then
106+
echo "Status test successful"
107+
break
108+
else
109+
echo "Waiting for $endpoint to return a 200 response with 'OK' body..."
110+
((counter=counter+1)) # Increment counter by 1
111+
echo "Attempt $counter"
112+
sleep 30
113+
fi
114+
done
115+
116+
if [ $counter -eq 31 ]; then
117+
echo "Status test failed: Maximum number of attempts reached"
118+
echo "Last response received:"
119+
echo "$response"
120+
exit 1
121+
fi
122+
displayName: Wait for API to be available
123+
workingDirectory: "$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)"
124+
125+
- bash: |
126+
pyenv install -s 3.10.8
127+
pyenv install -s 3.11.11
128+
pyenv global 3.10.8
129+
python --version
130+
displayName: Install python 3.10 and 3.11
131+
132+
- bash: |
133+
set -e
134+
export RELEASE_RELEASEID=$(Build.BuildId)
135+
export SOURCE_COMMIT_ID=$(Build.SourceVersion)
136+
export APIGEE_ENVIRONMENT="$(ENVIRONMENT)"
137+
138+
export SERVICE_BASE_PATH="$(SERVICE_BASE_PATH)"
139+
export APIGEE_ACCESS_TOKEN="$(secret.AccessToken)"
140+
export PROXY_NAME="$(FULLY_QUALIFIED_SERVICE_NAME)"
141+
export STATUS_API_KEY="$(status-endpoint-api-key)"
142+
export AWS_DOMAIN_NAME="$(AWS_DOMAIN_NAME)"
143+
export DYNAMODB_TABLE_NAME="$(DYNAMODB_TABLE_NAME)"
144+
export IMMS_DELTA_TABLE_NAME="$(IMMS_DELTA_TABLE_NAME)"
145+
export AWS_SQS_QUEUE_NAME="$(AWS_SQS_QUEUE_NAME)"
146+
export AWS_SNS_TOPIC_NAME="$(AWS_SNS_TOPIC_NAME)"
147+
export APIGEE_APP_ID=973b20ff-6e57-4248-b94f-200a18a03e37
148+
echo "api key- $STATUS_API_KEY"
149+
150+
#Exporting the same profile with which Terraform got deployed
151+
export AWS_PROFILE=apim-dev
152+
aws_account_no="$(aws sts get-caller-identity --query Account --output text)"
153+
echo aws_account_no: $aws_account_no
154+
155+
poetry lock --no-update
156+
poetry install
157+
158+
test_cmd="poetry run python -m unittest"
159+
# Run test_deployment before doing anything. This will wait until deployment is ready
160+
$test_cmd -c -v -k test_deployment
161+
162+
if [[ $APIGEE_ENVIRONMENT =~ .*-*sandbox ]]; then
163+
echo "Sandbox env tests"
164+
echo "running: $test_cmd -c -v -k test_proxy.TestProxyHealthcheck -k test_deployment"
165+
$test_cmd -c -v -k test_proxy.TestProxyHealthcheck -k test_deployment
166+
167+
elif [[ $APIGEE_ENVIRONMENT == "ref" ]]; then
168+
echo "running: $test_cmd -v -c test_deployment.py test_proxy.py"
169+
$test_cmd -v -c test_deployment.py test_proxy.py
170+
171+
elif [[ $APIGEE_ENVIRONMENT == "int" ]]; then
172+
export DEFAULT_CLIENT_ID="$(INT_CLIENT_ID)"
173+
export DEFAULT_CLIENT_SECRET="$(INT_CLIENT_SECRET)"
174+
echo "running: $test_cmd -v -c test_deployment.py test_proxy.py"
175+
$test_cmd -v -c test_deployment.py test_proxy.py
176+
177+
elif [[ $APIGEE_ENVIRONMENT == "prod" ]]; then
178+
echo "Proxy test completed successfully as part of terraform resource up status check"
179+
180+
else
181+
echo "running: $test_cmd -v -c"
182+
$test_cmd -v -c
183+
fi
184+
workingDirectory: "$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)/e2e"
185+
displayName: Run Full Test Suite
186+
condition: eq(1, 2)
187+
188+
- bash: |
189+
pyenv local 3.11
190+
poetry env use 3.11
191+
set -e
192+
if ! [[ "$APIGEE_ENVIRONMENT" == "prod" || "$APIGEE_ENVIRONMENT" == "int" || "$APIGEE_ENVIRONMENT" == *"sandbox" ]]; then
193+
echo "Running E2E batch folder test cases"
194+
195+
export AWS_PROFILE="apim-dev"
196+
aws_account_no="$(aws sts get-caller-identity --query Account --output text)"
197+
echo "Using AWS Account: $aws_account_no"
198+
199+
service_name="${FULLY_QUALIFIED_SERVICE_NAME}"
200+
201+
pr_no=$(echo "$service_name" | { grep -oE '[0-9]+$' || true; })
202+
if [ -z "$pr_no" ]; then
203+
workspace="$APIGEE_ENVIRONMENT"
204+
else
205+
workspace="pr-$pr_no"
206+
fi
207+
208+
poetry install --no-root # Install dependencies defined in pyproject.toml
209+
210+
ENV="$workspace" poetry run python -m unittest -v -c
211+
212+
echo "E2E batch folder test cases executed successfully"
213+
else
214+
echo "Skipping E2E batch folder test cases as the environment is prod-int-sandbox"
215+
fi
216+
217+
displayName: Run full batch test suite
218+
workingDirectory: "$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)/e2e_batch"
219+
condition: eq(1, 2) # Disable task but make this step visible in the pipeline
220+
221+
- task: PublishTestResults@2
222+
displayName: 'Publish test results'
223+
condition: always()
224+
inputs:
225+
testResultsFiles: '$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)/tests/test-report.xml'
226+
failTaskOnFailedTests: true

azure/templates/post-prod-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ steps:
3636
echo workspace: $workspace
3737
echo AWS environment: $APIGEE_ENVIRONMENT
3838
39-
cd terraform
39+
cd terraform
4040
4141
make init
4242
make apply aws_account_no=${aws_account_no} environment=$workspace

0 commit comments

Comments
 (0)