Skip to content

Commit a7b606d

Browse files
committed
Pipelines for int
1 parent 7003530 commit a7b606d

File tree

2 files changed

+83
-40
lines changed

2 files changed

+83
-40
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: "$(SourceBranchName)+$(BuildID)"
2+
3+
trigger: none
4+
pr: none
5+
6+
resources:
7+
repositories:
8+
- repository: common
9+
type: github
10+
name: NHSDigital/api-management-utils
11+
ref: refs/heads/edge
12+
endpoint: NHSDigital
13+
14+
pool:
15+
name: 'AWS-ECS'
16+
17+
variables:
18+
- template: project.yml
19+
20+
extends:
21+
template: azure/common/apigee-deployment.yml@common
22+
parameters:
23+
service_name: ${{ variables.service_name }}
24+
short_service_name: ${{ variables.short_service_name }}
25+
service_base_path: ${{ variables.service_base_path }}
26+
apigee_deployments:
27+
# To Do: this should be moved to release step. keeping it here for testing
28+
- environment: internal-qa # limited by api-management-utils
29+
jinja_templates:
30+
DOMAIN_ENDPOINT: https://green.imms.int.vds.platform.nhs.uk
31+
post_deploy:
32+
- template: ./templates/post-deploy.yml
33+
parameters:
34+
aws_account_type: 'dev'
35+
tf_dir: 'terraform_old'
36+
tf_environment: 'green'
37+

azure/templates/post-deploy.yml

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ parameters:
55
default: true
66
- name: 'aws_account_type'
77
type: string
8+
- name: tf_dir
9+
type: string
10+
default: "terraform"
811

912
steps:
1013
- ${{ if parameters.is_ptl }}:
@@ -58,7 +61,8 @@ steps:
5861
echo Apigee environment: $APIGEE_ENVIRONMENT
5962
echo pr_no: $pr_no
6063
61-
cd terraform
64+
echo "Moving to dir: ${{ parameters.tf_dir }}"
65+
cd ${{ parameters.tf_dir }}
6266
6367
make init
6468
make apply aws_account_no=${aws_account_no} environment=$workspace
@@ -80,45 +84,46 @@ steps:
8084
8185
- bash: |
8286
set -ex
83-
if ! [[ $APIGEE_ENVIRONMENT =~ .*-*sandbox ]]; then
84-
counter=0
85-
base_path="$SERVICE_BASE_PATH"
8687
87-
endpoint=""
88+
endpoint=""
89+
if [[ $APIGEE_ENVIRONMENT =~ "prod" ]]; then
90+
endpoint="https://api.service.nhs.uk/${SERVICE_BASE_PATH}/_status"
91+
else
92+
endpoint="https://${APIGEE_ENVIRONMENT}.api.service.nhs.uk/${SERVICE_BASE_PATH}/_status"
93+
fi
8894
89-
if [[ $APIGEE_ENVIRONMENT =~ "prod" ]]; then
90-
endpoint="https://api.service.nhs.uk/${base_path}/_status"
95+
counter=0
96+
while [[ $counter -lt 31 ]]; do
97+
response=$(curl -H "apikey: $(status-endpoint-api-key)" -s "$endpoint")
98+
response_code=$(jq -r '.checks.healthcheck.responseCode' <<< "$response")
99+
response_body=$(jq -r '.checks.healthcheck.outcome' <<< "$response")
100+
status=$(jq -r '.status' <<< "$response")
101+
if [ "$response_code" -eq 200 ] && [ "$response_body" == "OK" ] && [ "$status" == "pass" ]; then
102+
echo "Status test successful"
103+
break
91104
else
92-
endpoint="https://${APIGEE_ENVIRONMENT}.api.service.nhs.uk/${base_path}/_status"
105+
echo "Waiting for $endpoint to return a 200 response with 'OK' body..."
106+
((counter=counter+1)) # Increment counter by 1
107+
echo "Attempt $counter"
108+
sleep 30
93109
fi
110+
done
94111
95-
while [[ $counter -lt 11 ]]; do
96-
response=$(curl -H "apikey: $(status-endpoint-api-key)" -s "$endpoint")
97-
response_code=$(jq -r '.checks.healthcheck.responseCode' <<< "$response")
98-
response_body=$(jq -r '.checks.healthcheck.outcome' <<< "$response")
99-
if [ "$response_code" -eq 200 ] && [ "$response_body" == "OK" ]; then
100-
echo "Status test successful"
101-
break
102-
else
103-
echo "Waiting for $endpoint to return a 200 response with 'OK' body..."
104-
((counter=counter+1)) # Increment counter by 1
105-
echo "Attempt $counter"
106-
sleep 30
107-
fi
108-
done
109-
if [ $counter -eq 11 ]; then
110-
echo "Status test failed: Maximum number of attempts reached"
111-
exit 1
112-
fi
112+
if [ $counter -eq 31 ]; then
113+
echo "Status test failed: Maximum number of attempts reached"
114+
echo "Last response received:"
115+
echo "$response"
116+
exit 1
113117
fi
114-
displayName: Waiting for TF resources to be UP
118+
displayName: Wait for API to be available
115119
workingDirectory: "$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)"
116120
117121
- bash: |
118122
pyenv install -s 3.10.8
123+
pyenv install -s 3.11.11
119124
pyenv global 3.10.8
120125
python --version
121-
displayName: Set Python 3.10
126+
displayName: Install python 3.10 and 3.11
122127
123128
- bash: |
124129
set -e
@@ -164,7 +169,7 @@ steps:
164169
export DEFAULT_CLIENT_SECRET="$(INT_CLIENT_SECRET)"
165170
echo "running: $test_cmd -v -c test_deployment.py test_proxy.py"
166171
$test_cmd -v -c test_deployment.py test_proxy.py
167-
172+
168173
elif [[ $APIGEE_ENVIRONMENT == "prod" ]]; then
169174
echo "Proxy test completed successfully as part of terraform resource up status check"
170175
@@ -174,43 +179,44 @@ steps:
174179
fi
175180
workingDirectory: "$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)/e2e"
176181
displayName: Run Full Test Suite
177-
178-
182+
condition: eq(1, 2)
179183
180184
- bash: |
185+
pyenv local 3.11
186+
poetry env use 3.11
181187
set -e
182188
if ! [[ "$APIGEE_ENVIRONMENT" == "prod" || "$APIGEE_ENVIRONMENT" == "int" || "$APIGEE_ENVIRONMENT" == *"sandbox" ]]; then
183189
echo "Running E2E batch folder test cases"
184-
190+
185191
export AWS_PROFILE="apim-dev"
186192
aws_account_no="$(aws sts get-caller-identity --query Account --output text)"
187193
echo "Using AWS Account: $aws_account_no"
188-
194+
189195
service_name="${FULLY_QUALIFIED_SERVICE_NAME}"
190-
196+
191197
pr_no=$(echo "$service_name" | { grep -oE '[0-9]+$' || true; })
192198
if [ -z "$pr_no" ]; then
193199
workspace="$APIGEE_ENVIRONMENT"
194200
else
195201
workspace="pr-$pr_no"
196202
fi
197-
203+
198204
poetry install --no-root # Install dependencies defined in pyproject.toml
199-
205+
200206
ENV="$workspace" poetry run python -m unittest -v -c
201-
207+
202208
echo "E2E batch folder test cases executed successfully"
203209
else
204210
echo "Skipping E2E batch folder test cases as the environment is prod-int-sandbox"
205211
fi
206-
212+
207213
displayName: Run full batch test suite
208214
workingDirectory: "$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)/e2e_batch"
209-
215+
condition: eq(1, 2) # Disable task but make this step visible in the pipeline
210216
211217
- task: PublishTestResults@2
212218
displayName: 'Publish test results'
213219
condition: always()
214220
inputs:
215221
testResultsFiles: '$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)/tests/test-report.xml'
216-
failTaskOnFailedTests: true
222+
failTaskOnFailedTests: true

0 commit comments

Comments
 (0)