From 5832c81a14c1fdbef6fe512473ed18fb55c493d5 Mon Sep 17 00:00:00 2001 From: Steven Murawski Date: Thu, 8 Feb 2024 18:01:01 -0600 Subject: [PATCH 1/2] support windows --- azd-hooks/postprovision.ps1 | 22 +++++++++++++++++++ azd-hooks/predeploy.ps1 | 39 ++++++++++++++++++++++++++++++++++ azd-hooks/preprovision.ps1 | 10 +++++++++ azure.yaml | 42 ++++++++++++++++++++++++++----------- 4 files changed, 101 insertions(+), 12 deletions(-) create mode 100644 azd-hooks/postprovision.ps1 create mode 100644 azd-hooks/predeploy.ps1 create mode 100644 azd-hooks/preprovision.ps1 diff --git a/azd-hooks/postprovision.ps1 b/azd-hooks/postprovision.ps1 new file mode 100644 index 00000000..d879f787 --- /dev/null +++ b/azd-hooks/postprovision.ps1 @@ -0,0 +1,22 @@ +#!/usr/bin/env pwsh + +$services=@("ai-service", "makeline-service", "order-service", "product-service", "store-admin", "store-front", "virtual-customer", "virtual-worker") + +if (($env:DEPLOY_AZURE_CONTAINER_REGISTRY -like "true") -and ($env:BUILD_CONTAINERS -like "true")) { + echo "Build container images" + foreach ($service in $services) { + echo "Building aks-store-demo/${service}:latest" + az acr build --registry $env:AZURE_REGISTRY_NAME --image aks-store-demo/${service}:latest ./src/${service}/ + } +} +elseif (($env:DEPLOY_AZURE_CONTAINER_REGISTRY -like "true") -and ($env:BUILD_CONTAINERS -like "false")) { + echo "Import container images" + foreach ($service in $services) { + echo "Importing aks-store-demo/${service}:latest" + az acr import --name $env:AZURE_REGISTRY_NAME --source ghcr.io/azure-samples/aks-store-demo/${service}:latest --image aks-store-demo/${service}:latest + } +} +else { + echo "No BUILD_CONTAINERS variable set, skipping container build/import" +} + diff --git a/azd-hooks/predeploy.ps1 b/azd-hooks/predeploy.ps1 new file mode 100644 index 00000000..f196fd9d --- /dev/null +++ b/azd-hooks/predeploy.ps1 @@ -0,0 +1,39 @@ +#!/usr/bin/env pwsh + +echo "Retrieving cluster credentials" +az aks get-credentials --resource-group $env:AZURE_RESOURCEGROUP_NAME --name $env:AZURE_AKS_CLUSTER_NAME --overwrite-existing + +$makelineUseSqlApi = "false" +if ($env:AZURE_DATABASE_API -eq "cosmosdbsql") { + $makelineUseSqlApi = "true" +} + +echo "Deploy Helm chart" +helm upgrade aks-store-demo ./charts/aks-store-demo ` + --install ` + --set aiService.create=true ` + --set aiService.modelDeploymentName=$env:AZURE_OPENAI_MODEL_NAME ` + --set aiService.openAiEndpoint=$env:AZURE_OPENAI_ENDPOINT ` + --set aiService.managedIdentityClientId=$env:AZURE_IDENTITY_CLIENT_ID ` + --set aiService.image.repository=$env:AZURE_REGISTRY_URI/aks-store-demo/ai-service ` + --set orderService.useAzureServiceBus=true ` + --set orderService.queueHost=$env:AZURE_SERVICE_BUS_HOST ` + --set orderService.queuePort=5671 ` + --set orderService.queueUsername=$env:AZURE_SERVICE_BUS_SENDER_NAME ` + --set orderService.queuePassword=$(az keyvault secret show --name $env:AZURE_SERVICE_BUS_SENDER_KEY --vault-name $env:AZURE_KEY_VAULT_NAME --query value -o tsv) ` + --set orderService.queueTransport=tls ` + --set orderService.image.repository=$env:AZURE_REGISTRY_URI/aks-store-demo/order-service ` + --set makelineService.useAzureCosmosDB=true ` + --set makelineService.orderQueueUri=$env:AZURE_SERVICE_BUS_URI ` + --set makelineService.orderQueueUsername=$env:AZURE_SERVICE_BUS_LISTENER_NAME ` + --set makelineService.orderQueuePassword=$(az keyvault secret show --name $env:AZURE_SERVICE_BUS_LISTENER_KEY --vault-name $env:AZURE_KEY_VAULT_NAME --query value -o tsv) ` + --set makelineService.orderDBUri=$env:AZURE_COSMOS_DATABASE_URI ` + --set makelineService.orderDBUsername=$env:AZURE_COSMOS_DATABASE_NAME ` + --set makelineService.orderDBPassword=$(az keyvault secret show --name $env:AZURE_COSMOS_DATABASE_KEY --vault-name $env:AZURE_KEY_VAULT_NAME --query value -o tsv) ` + --set makelineService.image.repository=$env:AZURE_REGISTRY_URI/aks-store-demo/makeline-service ` + --set productService.image.repository=$env:AZURE_REGISTRY_URI/aks-store-demo/product-service ` + --set storeAdmin.image.repository=$env:AZURE_REGISTRY_URI/aks-store-demo/store-admin ` + --set storeFront.image.repository=$env:AZURE_REGISTRY_URI/aks-store-demo/store-front ` + --set virtualCustomer.image.repository=$env:AZURE_REGISTRY_URI/aks-store-demo/virtual-customer ` + --set virtualWorker.image.repository=$env:AZURE_REGISTRY_URI/aks-store-demo/virtual-worker ` + --set makelineService.useSqlApi=$makelineUseSqlApi diff --git a/azd-hooks/preprovision.ps1 b/azd-hooks/preprovision.ps1 new file mode 100644 index 00000000..3cc28f09 --- /dev/null +++ b/azd-hooks/preprovision.ps1 @@ -0,0 +1,10 @@ +#!/usr/bin/env pwsh + +echo "Ensuring Azure CLI extensions and dependencies are installed" +az provider register --namespace Microsoft.ContainerService +az feature register --namespace Microsoft.ContainerService --name AKS-KedaPreview +az feature register --namespace Microsoft.ContainerService --name AKS-PrometheusAddonPreview +az feature register --namespace Microsoft.ContainerService --name EnableWorkloadIdentityPreview +az feature register --namespace Microsoft.ContainerService --name NetworkObservabilityPreview +az extension add --upgrade --name aks-preview +az extension add --upgrade --name amg \ No newline at end of file diff --git a/azure.yaml b/azure.yaml index 38b09f55..01724dd6 100644 --- a/azure.yaml +++ b/azure.yaml @@ -5,20 +5,38 @@ metadata: template: aks-store-demo@1.0.0 hooks: preprovision: - shell: sh - continueOnError: false - interactive: false - run: azd-hooks/preprovision.sh + posix: + shell: sh + continueOnError: false + interactive: false + run: azd-hooks/preprovision.sh + windows: + shell: pwsh + continueOnError: false + interactive: false + run: azd-hooks/preprovision.ps1 postprovision: - shell: sh - continueOnError: false - interactive: false - run: azd-hooks/postprovision.sh + posix: + shell: sh + continueOnError: false + interactive: false + run: azd-hooks/postprovision.sh + windows: + shell: pwsh + continueOnError: false + interactive: false + run: azd-hooks/postprovision.ps1 predeploy: # This is a hack until Helm is supported in azd (https://github.com/Azure/azure-dev/issues/1618) - shell: sh - continueOnError: false - interactive: false - run: azd-hooks/predeploy.sh + posix: + shell: sh + continueOnError: false + interactive: false + run: azd-hooks/predeploy.sh + windows: + shell: pwsh + continueOnError: false + interactive: false + run: azd-hooks/predeploy.ps1 infra: provider: terraform path: infra/terraform \ No newline at end of file From 092ff87b8a8592bce22743a97e39a0de0059f65e Mon Sep 17 00:00:00 2001 From: Steven Murawski Date: Thu, 8 Feb 2024 18:01:55 -0600 Subject: [PATCH 2/2] move playwright server config into individual test files to support testing both the store admin and store front --- tests/e2e/add_product.spec.ts | 1 + tests/e2e/example.spec.ts | 2 ++ tests/e2e/products.spec.ts | 1 + tests/playwright.config.ts | 3 --- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/e2e/add_product.spec.ts b/tests/e2e/add_product.spec.ts index f8c0721b..4dff276a 100644 --- a/tests/e2e/add_product.spec.ts +++ b/tests/e2e/add_product.spec.ts @@ -1,5 +1,6 @@ import { test, expect } from '@playwright/test'; +test.use({ baseURL: process.env.STORE_ADMIN_URL }); test('can add product ', async ({ page }) => { await page.goto('/'); diff --git a/tests/e2e/example.spec.ts b/tests/e2e/example.spec.ts index f6dbb89c..4f70fb8d 100644 --- a/tests/e2e/example.spec.ts +++ b/tests/e2e/example.spec.ts @@ -1,5 +1,7 @@ import { test, expect } from '@playwright/test'; +test.use({ baseURL: process.env.STORE_ADMIN_URL }); + test('has title', async ({ page }) => { await page.goto('/'); diff --git a/tests/e2e/products.spec.ts b/tests/e2e/products.spec.ts index bf08ea98..e6020592 100644 --- a/tests/e2e/products.spec.ts +++ b/tests/e2e/products.spec.ts @@ -1,5 +1,6 @@ import { test, expect } from '@playwright/test'; +test.use({ baseURL: process.env.STORE_ADMIN_URL }); test('renders functionally', async ({ page }) => { await page.goto('/'); diff --git a/tests/playwright.config.ts b/tests/playwright.config.ts index db162d15..69fff512 100644 --- a/tests/playwright.config.ts +++ b/tests/playwright.config.ts @@ -23,9 +23,6 @@ export default defineConfig({ reporter: 'html', /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { - /* Base URL to use in actions like `await page.goto('/')`. */ - baseURL: process.env.STORE_ADMIN_URL, - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', },