Skip to content

Commit a74c272

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 a74c272

9 files changed

Lines changed: 130 additions & 12 deletions

File tree

.github/workflows/test-e2e.yaml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: test-e2e
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
id-token: write
8+
contents: read
9+
10+
jobs:
11+
test-e2e:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v3
16+
17+
- name: Install Terraform
18+
uses: hashicorp/setup-terraform@v3
19+
20+
- name: Install azd
21+
uses: Azure/setup-azd@v2.1.0
22+
23+
- uses: azure/use-kubelogin@v1
24+
with:
25+
kubelogin-version: "v0.2.8"
26+
27+
- name: Azure login
28+
uses: azure/login@v2
29+
with:
30+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
31+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
32+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
33+
34+
- name: Azure Developer CLI login
35+
run: |
36+
azd auth login \
37+
--client-id ${{ secrets.AZURE_CLIENT_ID }} \
38+
--federated-credential-provider "github" \
39+
--tenant-id ${{ secrets.AZURE_TENANT_ID }}
40+
41+
- name: Turn on Helm support for AKS
42+
run: azd config set alpha.aks.helm on
43+
44+
- name: Provision and deploy
45+
run: azd up --no-prompt
46+
env:
47+
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
48+
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
49+
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
50+
51+
- name: Get Store IPs
52+
id: kubectl_get_service
53+
run: |
54+
eval $(azd env get-values)
55+
#az aks get-credentials --resource-group $AZURE_RESOURCE_GROUP --name $AZURE_AKS_CLUSTER_NAME
56+
storeAdminIp=$(kubectl get service store-admin -n $AZURE_AKS_NAMESPACE -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
57+
while [ -z "$storeAdminIp" ]; do
58+
sleep 60
59+
storeAdminIp=$(kubectl get service store-admin -n $AZURE_AKS_NAMESPACE -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
60+
done
61+
echo "STORE_ADMIN_IP=${storeAdminIp}"
62+
echo "STORE_ADMIN_IP=${storeAdminIp}" >> "$GITHUB_OUTPUT"
63+
storeFrontIp=$(kubectl get service store-front -n $AZURE_AKS_NAMESPACE -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
64+
while [ -z "$storeFrontIp" ]; do
65+
sleep 60
66+
storeFrontIp=$(kubectl get service store-front -n $AZURE_AKS_NAMESPACE -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
67+
done
68+
echo "STORE_FRONT_IP=${storeFrontIp}"
69+
echo "STORE_FRONT_IP=${storeFrontIp}" >> "$GITHUB_OUTPUT"
70+
71+
- name: Install Playwright dependencies
72+
run: npm ci
73+
working-directory: tests
74+
75+
- name: Run Playwright tests
76+
run: npx playwright test --config=playwright.service.config.ts --workers=20
77+
working-directory: tests
78+
env:
79+
PLAYWRIGHT_SERVICE_URL: ${{ secrets.PLAYWRIGHT_SERVICE_URL }}
80+
STORE_ADMIN_URL: "http://${{ steps.kubectl_get_service.outputs.STORE_ADMIN_IP }}"
81+
STORE_FRONT_URL: "http://${{ steps.kubectl_get_service.outputs.STORE_FRONT_IP }}"
82+
CI: true
83+
84+
# - uses: actions/upload-artifact@v4
85+
# if: ${{ !cancelled() }}
86+
# with:
87+
# name: playwright-report
88+
# path: tests/playwright-report/
89+
# retention-days: 30
90+
91+
- name: Destroy environment
92+
run: azd down --force --purge
93+
if: always()
94+
env:
95+
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
96+
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
97+
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

azd-hooks/postprovision.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ elif [ "$DEPLOY_AZURE_CONTAINER_REGISTRY" == "true" ] && ([ -z "$BUILD_CONTAINER
1212
echo "Import container images"
1313
for service in "${services[@]}"; do
1414
echo "Importing aks-store-demo/${service}:latest"
15-
az acr import --name ${AZURE_REGISTRY_NAME} --source ghcr.io/azure-samples/aks-store-demo/${service}:latest --image aks-store-demo/${service}:latest
15+
az acr import --name ${AZURE_REGISTRY_NAME} --source ghcr.io/pauldotyu/aks-store-demo/${service}:latest --image aks-store-demo/${service}:latest
1616
done
1717
else
1818
echo "No BUILD_CONTAINERS variable set, skipping container build/import"

azure.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ services:
6161
helm:
6262
repositories:
6363
- name: aks-store-demo
64-
url: https://azure-samples.github.io/aks-store-demo
64+
url: https://pauldotyu.github.io/aks-store-demo
6565
releases:
6666
- name: demo
6767
chart: aks-store-demo/aks-store-demo-chart

infra/terraform/kubernetes.tf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ module "aks" {
6464
module "aks-role" {
6565
source = "Azure/avm-res-authorization-roleassignment/azurerm"
6666
version = "0.2.0"
67-
users_by_object_id = {
68-
current_user = data.azurerm_client_config.current.object_id
67+
# users_by_object_id = {
68+
# current_user = data.azurerm_client_config.current.object_id
69+
# }
70+
groups_by_object_id = {
71+
demo_group = azuread_group.example.object_id
6972
}
7073
role_definitions = {
7174
aks_cluster_admin_role = {
@@ -78,7 +81,7 @@ module "aks-role" {
7881
role_assignments = {
7982
role_assignment_1 = {
8083
role_definition = "aks_cluster_admin_role"
81-
users = ["current_user"]
84+
groups = ["demo_group"]
8285
}
8386
}
8487
}

infra/terraform/main.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,13 @@ resource "azurerm_resource_group" "example" {
8282
name = "rg-${local.name}"
8383
location = var.location
8484
}
85+
86+
resource "azuread_group" "example" {
87+
display_name = "AKS Store Demo App"
88+
security_enabled = true
89+
}
90+
91+
resource "azuread_group_member" "example" {
92+
group_object_id = azuread_group.example.object_id
93+
member_object_id = data.azurerm_client_config.current.object_id
94+
}

infra/terraform/openai.tf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ module "aoai-role" {
4444
count = local.deploy_azure_openai ? 1 : 0
4545
source = "Azure/avm-res-authorization-roleassignment/azurerm"
4646
version = "0.2.0"
47-
users_by_object_id = {
48-
current_user = data.azurerm_client_config.current.object_id
47+
# users_by_object_id = {
48+
# current_user = data.azurerm_client_config.current.object_id
49+
# }
50+
groups_by_object_id = {
51+
"demo_group" = azuread_group.example.object_id
4952
}
5053
role_definitions = {
5154
cognitive_services_openai_user_role = {
@@ -58,7 +61,7 @@ module "aoai-role" {
5861
role_assignments = {
5962
role_assignment_1 = {
6063
role_definition = "cognitive_services_openai_user_role"
61-
users = ["current_user"]
64+
any_principals = ["demo_group"]
6265
}
6366
}
6467
}

infra/terraform/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ output "AZURE_REGISTRY_NAME" {
7676
}
7777

7878
output "AZURE_REGISTRY_URI" {
79-
value = local.deploy_azure_container_registry ? module.acr[0].resource.login_server : "ghcr.io/azure-samples"
79+
value = local.deploy_azure_container_registry ? module.acr[0].resource.login_server : "ghcr.io/pauldotyu"
8080
}
8181

8282
output "AZURE_TENANT_ID" {

infra/terraform/servicebus.tf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ module "avm-res-authorization-roleassignment-sb" {
2222
count = local.deploy_azure_servicebus ? 1 : 0
2323
source = "Azure/avm-res-authorization-roleassignment/azurerm"
2424
version = "0.2.0"
25-
users_by_object_id = {
26-
current_user = data.azurerm_client_config.current.object_id
25+
# users_by_object_id = {
26+
# current_user = data.azurerm_client_config.current.object_id
27+
# }
28+
groups_by_object_id = {
29+
demo_group = azuread_group.example.object_id
2730
}
2831
role_definitions = {
2932
service_bus_data_owner_role = {
@@ -36,7 +39,7 @@ module "avm-res-authorization-roleassignment-sb" {
3639
role_assignments = {
3740
role_assignment_1 = {
3841
role_definition = "service_bus_data_owner_role"
39-
users = ["current_user"]
42+
any_principals = ["demo_group"]
4043
}
4144
}
4245
}

tests/playwright.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export default defineConfig({
2525
use: {
2626
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
2727
trace: 'on-first-retry',
28+
video: 'retain-on-failure',
29+
screenshot: 'on'
2830
},
2931

3032
/* Configure projects for major browsers */

0 commit comments

Comments
 (0)