Skip to content

Commit d7f50b9

Browse files
committed
test(e2e): adding integration testing via github
workflow and azd - also modified terraform to accomodate running as service principal
1 parent 62c4aed commit d7f50b9

16 files changed

Lines changed: 500 additions & 289 deletions

.github/workflows/azure-dev.yaml

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

.github/workflows/test-azd-deployment.yaml

Lines changed: 0 additions & 163 deletions
This file was deleted.
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# composite workflow to test the azd deployment of the app
2+
# uses a github federated identity
3+
name: Test AZD Deployment
4+
5+
on:
6+
push:
7+
branches:
8+
- main
9+
10+
workflow_dispatch:
11+
12+
permissions:
13+
id-token: write
14+
contents: read
15+
16+
jobs:
17+
deploy:
18+
outputs:
19+
storeAdminIp: ${{ steps.kubectl_get_service.outputs.STORE_ADMIN_IP }}
20+
storeFrontIp: ${{ steps.kubectl_get_service.outputs.STORE_FRONT_IP }}
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
25+
26+
- name: Install Terraform
27+
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3
28+
29+
- name: Install azd
30+
uses: Azure/setup-azd@ae0f8b5482eeac61e940f447327d84c73beb8b1e # v2.1.0
31+
32+
- name: Install kubelogin
33+
uses: azure/use-kubelogin@76597ae0fcbaace21b05e13a2cbf8daee2c6e820 # v1
34+
with:
35+
kubelogin-version: "v0.2.8"
36+
37+
- name: Azure CLI login
38+
uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5 # v2
39+
with:
40+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
41+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
42+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
43+
44+
- name: Azure Developer CLI login
45+
run: |
46+
azd auth login \
47+
--client-id ${{ secrets.AZURE_CLIENT_ID }} \
48+
--federated-credential-provider "github" \
49+
--tenant-id ${{ secrets.AZURE_TENANT_ID }}
50+
51+
- name: Turn on Helm support for azd
52+
run: azd config set alpha.aks.helm on
53+
54+
- name: Provision and deploy
55+
id: provision_deploy
56+
continue-on-error: true
57+
run: |
58+
azd env new ${{ vars.AZURE_ENV_NAME }}
59+
azd env set AKS_NODE_POOL_VM_SIZE Standard_D2_v4
60+
azd env set BUILD_CONTAINERS false
61+
azd env set DEPLOY_AZURE_CONTAINER_REGISTRY true
62+
azd env set DEPLOY_AZURE_OPENAI true
63+
azd env set AZURE_OPENAI_LOCATION ${{ vars.AZURE_LOCATION }}
64+
azd env set DEPLOY_AZURE_OPENAI_DALL_E_MODEL false
65+
azd env set DEPLOY_AZURE_SERVICE_BUS true
66+
azd env set DEPLOY_AZURE_COSMOSDB true
67+
azd env set AZURE_COSMOSDB_ACCOUNT_KIND MongoDB
68+
azd env set DEPLOY_OBSERVABILITY_TOOLS true
69+
azd up --no-prompt
70+
env:
71+
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
72+
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
73+
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
74+
75+
- name: Save azd cache
76+
uses: actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 # v4
77+
if: always()
78+
with:
79+
path: |
80+
.azure/
81+
key: ${{ runner.os }}-azd-${{ github.run_id }}-${{ github.sha }}
82+
83+
- name: Check provision and deploy result
84+
if: steps.provision_deploy.outcome == 'failure'
85+
run: |
86+
echo "Provision and deploy failed"
87+
exit 1
88+
89+
- name: Get Store IPs
90+
id: kubectl_get_service
91+
if: steps.provision_deploy.outcome == 'success'
92+
run: |
93+
eval $(azd env get-values)
94+
storeAdminIp=$(kubectl get service store-admin -n $AZURE_AKS_NAMESPACE -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
95+
while [ -z "$storeAdminIp" ]; do
96+
sleep 60
97+
storeAdminIp=$(kubectl get service store-admin -n $AZURE_AKS_NAMESPACE -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
98+
done
99+
echo "STORE_ADMIN_IP=${storeAdminIp}"
100+
echo "STORE_ADMIN_IP=${storeAdminIp}" >> "$GITHUB_OUTPUT"
101+
storeFrontIp=$(kubectl get service store-front -n $AZURE_AKS_NAMESPACE -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
102+
while [ -z "$storeFrontIp" ]; do
103+
sleep 60
104+
storeFrontIp=$(kubectl get service store-front -n $AZURE_AKS_NAMESPACE -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
105+
done
106+
echo "STORE_FRONT_IP=${storeFrontIp}"
107+
echo "STORE_FRONT_IP=${storeFrontIp}" >> "$GITHUB_OUTPUT"
108+
109+
playwright-tests:
110+
needs: deploy
111+
uses: ./.github/workflows/test-playwright.yaml
112+
secrets: inherit
113+
with:
114+
storeAdminUrl: "http://${{ needs.deploy.outputs.storeAdminIp }}"
115+
storeFrontUrl: "http://${{ needs.deploy.outputs.storeFrontIp }}"
116+
117+
teardown:
118+
if: always()
119+
needs: playwright-tests
120+
runs-on: ubuntu-latest
121+
steps:
122+
- name: Checkout
123+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
124+
125+
- name: Install Terraform
126+
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3
127+
128+
- name: Install azd
129+
uses: Azure/setup-azd@ae0f8b5482eeac61e940f447327d84c73beb8b1e # v2.1.0
130+
131+
- name: Restore azd cache
132+
uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4
133+
with:
134+
path: |
135+
.azure/
136+
key: ${{ runner.os }}-azd-${{ github.run_id }}-${{ github.sha }}
137+
138+
- name: Azure CLI login
139+
uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5 # v2
140+
with:
141+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
142+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
143+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
144+
145+
- name: Azure Developer CLI login
146+
run: |
147+
azd auth login \
148+
--client-id ${{ secrets.AZURE_CLIENT_ID }} \
149+
--federated-credential-provider "github" \
150+
--tenant-id ${{ secrets.AZURE_TENANT_ID }}
151+
152+
- name: Destroy environment
153+
run: azd down --force --purge
154+
env:
155+
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
156+
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
157+
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
158+
159+
- name: Remove azd folder
160+
run: rm -rf .azure

0 commit comments

Comments
 (0)