From 2e465f07f7d1b306ab6bfd530eaccb5a2859a16a Mon Sep 17 00:00:00 2001 From: Justin Yoo Date: Mon, 27 Nov 2023 16:10:35 +0900 Subject: [PATCH 1/8] Add GHA workflow --- .github/workflows/azure-dev.yml | 127 ++++++++++++++++++ .gitignore | 4 + .../appsettings.Development.sample.json | 10 -- .../appsettings.json | 10 -- AspireYouTubeSummariser.AppHost/Program.cs | 12 ++ .../Properties/launchSettings.json | 15 ++- .../appsettings.Development.sample.json | 10 +- .../appsettings.json | 10 +- AspireYouTubeSummariser.WebApp/Program.cs | 2 +- .../appsettings.Development.sample.json | 11 -- .../appsettings.json | 11 -- README.md | 41 +++++- azure.yaml | 8 ++ biceps/Run-PostProvision.ps1 | 90 +++++++++++++ biceps/Set-GitHubActionsVariables.ps1 | 47 +++++++ biceps/openAI.bicep | 63 +++++++++ biceps/resourceGroup.bicep | 1 + next-steps.md | 69 ++++++++++ 18 files changed, 491 insertions(+), 50 deletions(-) create mode 100644 .github/workflows/azure-dev.yml create mode 100644 azure.yaml create mode 100644 biceps/Run-PostProvision.ps1 create mode 100644 biceps/Set-GitHubActionsVariables.ps1 create mode 100644 biceps/openAI.bicep create mode 100644 biceps/resourceGroup.bicep create mode 100644 next-steps.md diff --git a/.github/workflows/azure-dev.yml b/.github/workflows/azure-dev.yml new file mode 100644 index 0000000..21ed33b --- /dev/null +++ b/.github/workflows/azure-dev.yml @@ -0,0 +1,127 @@ +on: + workflow_dispatch: + push: + branches: + - main + - 'feature/*' + +# https://learn.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-portal%2Clinux#set-up-azure-login-with-openid-connect-authentication +permissions: + id-token: write + contents: read + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Login to Azure + # if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' + uses: azure/login@v1 + with: + tenant-id: ${{ vars.AZURE_TENANT_ID }} + subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }} + client-id: ${{ vars.AZURE_CLIENT_ID }} + + # - name: Install Azure Developer CLI + # if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' + # uses: Azure/setup-azd@v0.1.0 + + - name: Install Azure Developer CLI (nightly build) + # if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' + shell: pwsh + run: | + Invoke-RestMethod 'https://aka.ms/install-azd.ps1' -OutFile ./install-azd.ps1 + ./install-azd.ps1 -Version daily + + - name: Login to Azure Developer CLI + # if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' + shell: pwsh + run: | + azd auth login ` + --tenant-id "${{ vars.AZURE_TENANT_ID }}" ` + --client-id "${{ vars.AZURE_CLIENT_ID }}" ` + --federated-credential-provider "${{ vars.AZD_PIPELINE_PROVIDER }}" + + - name: Setup environment + # if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' + shell: pwsh + run: | + # Create config.json under .azure + New-Item -Type Directory .azure + $config = @{ version = 1; defaultEnvironment = "${{ vars.AZURE_ENV_NAME }}" } + $config | ConvertTo-Json -Depth 100 | Out-File -Path ./.azure/config.json -Force + + # Create config.json under .azure/${{ vars.AZURE_ENV_NAME }} + New-Item -Type Directory .azure/${{ vars.AZURE_ENV_NAME }} + $config = @{ services = @{ app = @{ config = @{ exposedServices = @( "webapp" ) } } } } + $config | ConvertTo-Json -Depth 100 | Out-File -Path ./.azure/${{ vars.AZURE_ENV_NAME }}/config.json -Force + + # Create .env under .azure/${{ vars.AZURE_ENV_NAME }} + $dotenv = @() + $dotenv += "AZD_PIPELINE_PROVIDER=`"${{ vars.AZD_PIPELINE_PROVIDER }}`"" + $dotenv += "AZURE_CONTAINER_APPS_ENVIRONMENT_DEFAULT_DOMAIN=`"${{ vars.AZURE_CONTAINER_APPS_ENVIRONMENT_DEFAULT_DOMAIN }}`"" + $dotenv += "AZURE_CONTAINER_APPS_ENVIRONMENT_ID=`"${{ vars.AZURE_CONTAINER_APPS_ENVIRONMENT_ID }}`"" + $dotenv += "AZURE_CONTAINER_REGISTRY_ENDPOINT=`"${{ vars.AZURE_CONTAINER_REGISTRY_ENDPOINT }}`"" + $dotenv += "AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID=`"${{ vars.AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID }}`"" + $dotenv += "AZURE_ENV_NAME=`"${{ vars.AZURE_ENV_NAME }}`"" + $dotenv += "AZURE_LOCATION=`"${{ vars.AZURE_LOCATION }}`"" + $dotenv += "AZURE_PIPELINE_CLIENT_ID=`"${{ vars.AZURE_PIPELINE_CLIENT_ID }}`"" + $dotenv += "AZURE_SUBSCRIPTION_ID=`"${{ vars.AZURE_SUBSCRIPTION_ID }}`"" + $dotenv += "MANAGED_IDENTITY_CLIENT_ID=`"${{ vars.MANAGED_IDENTITY_CLIENT_ID }}`"" + $dotenv += "SERVICE_BINDING_QUEUE_ENDPOINT=`"${{ vars.SERVICE_BINDING_QUEUE_ENDPOINT }}`"" + $dotenv += "SERVICE_BINDING_TABLE_ENDPOINT=`"${{ vars.SERVICE_BINDING_TABLE_ENDPOINT }}`"" + $dotenv | Out-File -Path ./.azure/${{ vars.AZURE_ENV_NAME }}/.env -Force + + - name: Update appsettings.json + # if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' + shell: pwsh + run: | + $resource = az resource list -g rg-${{ vars.AZURE_ENV_NAME }} --query "[?type=='Microsoft.CognitiveServices/accounts'].name" -o tsv + $endpoint = az cognitiveservices account show -g rg-${{ vars.AZURE_ENV_NAME }} -n $instance --query "properties.endpoint" -o tsv + $apiKey = az cognitiveservices account keys list -g rg-${{ vars.AZURE_ENV_NAME }} -n $instance --query "key1" -o tsv + $deploymentId = az cognitiveservices account deployment list -g rg-${{ vars.AZURE_ENV_NAME }} -n $instance --query "[].name" -o tsv + + $openAI = @{ Endpoint = $endpoint; ApiKey = $apiKey; DeploymentId = $deploymentId; } + + Copy-Item -Path ./AspireYouTubeSummariser.AppHost/appsettings.Development.sample.json ` + -Destination ./AspireYouTubeSummariser.AppHost/appsettings.Development.json -Force + + $appsettings = Get-Content -Path ./AspireYouTubeSummariser.AppHost/appsettings.Development.json | ConvertFrom-Json + $appsettings.OpenAI = $openAI + $appsettings | ConvertTo-Json -Depth 100 | Out-File -Path ./AspireYouTubeSummariser.AppHost/appsettings.Development.json -Force + + - name: Setup .NET SDK + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 8.x + + - name: Install Aspire workload + shell: pwsh + run: | + dotnet workload update + dotnet workload install aspire + + - name: Restore NuGet packages + shell: bash + run: | + dotnet restore + + - name: Build solution + shell: bash + run: | + dotnet build + + - name: Test solution + shell: bash + run: | + dotnet test + + - name: Deploy to Azure Container Apps + # if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' + shell: pwsh + run: | + azd deploy diff --git a/.gitignore b/.gitignore index 339a364..c9ccd65 100644 --- a/.gitignore +++ b/.gitignore @@ -486,3 +486,7 @@ $RECYCLE.BIN/ appsettings.Development.json **/bundle.js **/bundle.js.*.txt +.azure + +*.bak +*.org diff --git a/AspireYouTubeSummariser.ApiApp/appsettings.Development.sample.json b/AspireYouTubeSummariser.ApiApp/appsettings.Development.sample.json index 4e461d8..0c208ae 100644 --- a/AspireYouTubeSummariser.ApiApp/appsettings.Development.sample.json +++ b/AspireYouTubeSummariser.ApiApp/appsettings.Development.sample.json @@ -4,15 +4,5 @@ "Default": "Information", "Microsoft.AspNetCore": "Warning" } - }, - - // "ConnectionStrings": { - // "table": "{{AZURE_STORAGE_CONNECTION_STRING}}" - // }, - - "OpenAI": { - "Endpoint": "{{AOAI_ENDPOINT_URL}}", - "ApiKey": "{{AOAI_API_KEY}}", - "DeploymentId": "{{AOAI_DEPLOYMENT_ID}}" } } diff --git a/AspireYouTubeSummariser.ApiApp/appsettings.json b/AspireYouTubeSummariser.ApiApp/appsettings.json index 7531797..a80d39e 100644 --- a/AspireYouTubeSummariser.ApiApp/appsettings.json +++ b/AspireYouTubeSummariser.ApiApp/appsettings.json @@ -6,16 +6,6 @@ } }, - // "ConnectionStrings": { - // "table": "{{AZURE_STORAGE_CONNECTION_STRING}}" - // }, - - "OpenAI": { - "Endpoint": "{{AOAI_ENDPOINT_URL}}", - "ApiKey": "{{AOAI_API_KEY}}", - "DeploymentId": "{{AOAI_DEPLOYMENT_ID}}" - }, - "Prompt": { "System": "You are the expert of summarising long contents. You are going to summarise the following YouTube video transcript in a given language code.", "MaxTokens": 3000, diff --git a/AspireYouTubeSummariser.AppHost/Program.cs b/AspireYouTubeSummariser.AppHost/Program.cs index 76fedfc..71e4dc4 100644 --- a/AspireYouTubeSummariser.AppHost/Program.cs +++ b/AspireYouTubeSummariser.AppHost/Program.cs @@ -1,3 +1,7 @@ +using AspireYouTubeSummariser.Shared.Configurations; + +using Microsoft.Extensions.Configuration; + var builder = DistributedApplication.CreateBuilder(args); var cache = builder.AddRedisContainer("cache"); @@ -5,7 +9,12 @@ var queue = storage.AddQueues("queue"); var table = storage.AddTables("table"); +var openAISettings = builder.Configuration.GetSection(OpenAISettings.Name).Get(); + var apiapp = builder.AddProject("apiapp") + .WithEnvironment("OpenAI__Endpoint", openAISettings.Endpoint) + .WithEnvironment("OpenAI__ApiKey", openAISettings.ApiKey) + .WithEnvironment("OpenAI__DeploymentId", openAISettings.DeploymentId) .WithReference(table); builder.AddProject("webapp") @@ -14,6 +23,9 @@ .WithReference(apiapp); builder.AddProject("worker") + .WithEnvironment("OpenAI__Endpoint", openAISettings.Endpoint) + .WithEnvironment("OpenAI__ApiKey", openAISettings.ApiKey) + .WithEnvironment("OpenAI__DeploymentId", openAISettings.DeploymentId) .WithReference(queue) .WithReference(table); diff --git a/AspireYouTubeSummariser.AppHost/Properties/launchSettings.json b/AspireYouTubeSummariser.AppHost/Properties/launchSettings.json index a6a22b8..ac18696 100644 --- a/AspireYouTubeSummariser.AppHost/Properties/launchSettings.json +++ b/AspireYouTubeSummariser.AppHost/Properties/launchSettings.json @@ -5,11 +5,22 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "applicationUrl": "http://localhost:15218", + "applicationUrl": "http://localhost:15000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "DOTNET_ENVIRONMENT": "Development", - "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16101" + "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16000" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:15001", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "DOTNET_ENVIRONMENT": "Development", + "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16001" } } } diff --git a/AspireYouTubeSummariser.AppHost/appsettings.Development.sample.json b/AspireYouTubeSummariser.AppHost/appsettings.Development.sample.json index a559928..ac61cfc 100644 --- a/AspireYouTubeSummariser.AppHost/appsettings.Development.sample.json +++ b/AspireYouTubeSummariser.AppHost/appsettings.Development.sample.json @@ -7,7 +7,13 @@ }, "ConnectionStrings": { - "queue": "{{AZURE_STORAGE_CONNECTION_STRING}}", - "table": "{{AZURE_STORAGE_CONNECTION_STRING}}" + "queue": "https://{account_name}.table.core.windows.net/", + "table": "https://{account_name}.table.core.windows.net/" + }, + + "OpenAI": { + "Endpoint": "https://{account_name}.openai.azure.com/", + "ApiKey": "random.apikey.aoai", + "DeploymentId": "random.deploymentid.aoai" } } diff --git a/AspireYouTubeSummariser.AppHost/appsettings.json b/AspireYouTubeSummariser.AppHost/appsettings.json index e1c8737..1a4a0b3 100644 --- a/AspireYouTubeSummariser.AppHost/appsettings.json +++ b/AspireYouTubeSummariser.AppHost/appsettings.json @@ -8,7 +8,13 @@ }, "ConnectionStrings": { - "queue": "{{AZURE_STORAGE_CONNECTION_STRING}}", - "table": "{{AZURE_STORAGE_CONNECTION_STRING}}" + "queue": "https://{account_name}.table.core.windows.net/", + "table": "https://{account_name}.table.core.windows.net/" + }, + + "OpenAI": { + "Endpoint": "https://{account_name}.openai.azure.com/", + "ApiKey": "random.apikey.aoai", + "DeploymentId": "random.deploymentid.aoai" } } diff --git a/AspireYouTubeSummariser.WebApp/Program.cs b/AspireYouTubeSummariser.WebApp/Program.cs index f8cc90e..27d4c1c 100644 --- a/AspireYouTubeSummariser.WebApp/Program.cs +++ b/AspireYouTubeSummariser.WebApp/Program.cs @@ -14,7 +14,7 @@ builder.Services.AddHttpClient(client => { //client.BaseAddress = new Uri("http://localhost:5050"); - client.BaseAddress = new Uri("http://apiapp"); + client.BaseAddress = new Uri("https://apiapp"); }); builder.Services.AddScoped(); diff --git a/AspireYouTubeSummariser.Worker/appsettings.Development.sample.json b/AspireYouTubeSummariser.Worker/appsettings.Development.sample.json index 0e57b74..0c208ae 100644 --- a/AspireYouTubeSummariser.Worker/appsettings.Development.sample.json +++ b/AspireYouTubeSummariser.Worker/appsettings.Development.sample.json @@ -4,16 +4,5 @@ "Default": "Information", "Microsoft.AspNetCore": "Warning" } - }, - - // "ConnectionStrings": { - // "queue": "{{AZURE_STORAGE_CONNECTION_STRING}}", - // "table": "{{AZURE_STORAGE_CONNECTION_STRING}}" - // }, - - "OpenAI": { - "Endpoint": "{{AOAI_ENDPOINT_URL}}", - "ApiKey": "{{AOAI_API_KEY}}", - "DeploymentId": "{{AOAI_DEPLOYMENT_ID}}" } } diff --git a/AspireYouTubeSummariser.Worker/appsettings.json b/AspireYouTubeSummariser.Worker/appsettings.json index 544fd24..a80d39e 100644 --- a/AspireYouTubeSummariser.Worker/appsettings.json +++ b/AspireYouTubeSummariser.Worker/appsettings.json @@ -6,17 +6,6 @@ } }, - // "ConnectionStrings": { - // "queue": "{{AZURE_STORAGE_CONNECTION_STRING}}", - // "table": "{{AZURE_STORAGE_CONNECTION_STRING}}" - // }, - - "OpenAI": { - "Endpoint": "{{AOAI_ENDPOINT_URL}}", - "ApiKey": "{{AOAI_API_KEY}}", - "DeploymentId": "{{AOAI_DEPLOYMENT_ID}}" - }, - "Prompt": { "System": "You are the expert of summarising long contents. You are going to summarise the following YouTube video transcript in a given language code.", "MaxTokens": 3000, diff --git a/README.md b/README.md index 6b15866..7f1349e 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,11 @@ This provides sample Aspire-orchestrated apps that summarise a YouTube video tra - [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0?WT.mc_id=dotnet-107070-juyoo) - [Visual Studio 2022](https://visualstudio.microsoft.com?WT.mc_id=dotnet-107070-juyoo) 17.9 or later with the .NET Aspire workload installed -- [Docker Desktop](https://www.docker.com/products/docker-desktop) +- [Docker Desktop](https://docker.com/products/docker-desktop) - [Azure Developer CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/overview?WT.mc_id=dotnet-107070-juyoo) +- [Azure CLI](https://learn.microsoft.com/cli/azure/what-is-azure-cli?WT.mc_id=dotnet-107070-juyoo) +- [GitHub CLI](https://cli.github.com/) +- [PowerShell](https://learn.microsoft.com/powershell/scripting/overview?WT.mc_id=dotnet-107070-juyoo) - [Azure subscription](https://azure.microsoft.com/free?WT.mc_id=dotnet-107070-juyoo) - [Azure OpenAI Service subscription](https://aka.ms/oaiapply) @@ -100,6 +103,42 @@ This provides sample Aspire-orchestrated apps that summarise a YouTube video tra dotnet run --project AspireYouTubeSummariser.AppHost ``` +### Deploy to Azure + +1. Checkout to the `main` branch + + ```bash + git switch main + dotnet restore && dotnet build + ``` + +1. Rename `appsettings.Development.sample.json` in the `AppHost` project to `appsettings.Development.json`. + +1. Add Azure OpenAI Service details – endpoint, API key and deployment ID – to the file. You can get these details from the [Azure Portal](https://portal.azure.com/?WT.mc_id=dotnet-107070-juyoo). + +1. Add Azure Queue/Table Storage Account details – connection strings – to the file You can get these details from the [Azure Portal](https://portal.azure.com/?WT.mc_id=dotnet-107070-juyoo). + +1. Run the following commands in order: + + ```bash + # Initialise azd + AZURE_ENV_NAME="aspire$RANDOM" + azd init -e $AZURE_ENV_NAME + + # Provision resources to Azure + azd provision + + # Provision GitHub Actions environment + azd pipeline config + pwsh Set-GitHubActionsVariables.ps1 -GitHubAlias + + # Provision rest of resources to Azure outside Aspire + pwsh Run-PostProvision.ps1 -GitHubAlias + + # Deploy apps to Azure + azd deploy + ``` + ## Resources - [.NET Aspire overview](https://learn.microsoft.com/dotnet/aspire/get-started/aspire-overview?WT.mc_id=dotnet-107070-juyoo) diff --git a/azure.yaml b/azure.yaml new file mode 100644 index 0000000..264a5b2 --- /dev/null +++ b/azure.yaml @@ -0,0 +1,8 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json + +name: aspire-youtube-summariser +services: + app: + language: dotnet + project: .\AspireYouTubeSummariser.AppHost\AspireYouTubeSummariser.AppHost.csproj + host: containerapp diff --git a/biceps/Run-PostProvision.ps1 b/biceps/Run-PostProvision.ps1 new file mode 100644 index 0000000..d3d24c3 --- /dev/null +++ b/biceps/Run-PostProvision.ps1 @@ -0,0 +1,90 @@ +# Run post-provisioning tasks +Param( + [string] + [Parameter(Mandatory=$false)] + $GitHubAlias = $null, + + [string] + [Parameter(Mandatory=$false)] + $GitHubRepository = "aspire-youtube-summariser", + + [switch] + [Parameter(Mandatory=$false)] + $Help +) + +function Show-Usage { + Write-Output " This runs the post-provisioning tasks + + Usage: $(Split-Path $MyInvocation.ScriptName -Leaf) `` + [-GitHubAlias ] `` + [-GitHubRepository ] `` + + [-Help] + + Options: + -GitHubAlias GitHub username. eg) 'devkimchi' of https://github.com/devkimchi. Default is `$null. + -GitHubRepository GitHub repository name. Default is 'aspire-youtube-summariser'. + + -Help Show this message. +" + + Exit 0 +} + +# Show usage +$needHelp = $Help -eq $true +if ($needHelp -eq $true) { + Show-Usage + Exit 0 +} + +if ($GitHubAlias -ne $null) { + $vars = gh api repos/$GitHubAlias/$GitHubRepository/actions/variables | ConvertFrom-Json + $env:AZURE_ENV_NAME = $($vars.variables | Where-Object { $_.name -eq "AZURE_ENV_NAME" }).value +} + +$rg = "rg-$env:AZURE_ENV_NAME" + +# Provision AOAI instances +Write-Output "Provisioning Azure OpenAI instance ..." + +$provisioned = az deployment group create -n aoai -g $rg ` + --template-file ./biceps/openAI.bicep ` + --parameters environmentName=$env:AZURE_ENV_NAME | ConvertFrom-Json + +Write-Output "... Provisioned" + +$openAI = $provisioned.properties.outputs.aoaiInstance.value | ` + Select-Object -Property @{ Name = "Endpoint"; Expression = "endpoint" }, @{ Name = "ApiKey"; Expression = "apiKey" }, @{ Name = "DeploymentId"; Expression = "deploymentName" } + +# Get resource token +Write-Output "Updating Azure Storage ..." + +$token = az deployment group create -n resourceToken -g $rg ` + --template-file ./biceps/resourceGroup.bicep | ConvertFrom-Json + +$token = $token.properties.outputs.resourceToken.value + +# Get connection string +$connectionString = az storage account show-connection-string -g $rg -n storage$token --query "connectionString" -o tsv + +# Add tables to table storage +$queue = az storage queue create -n summaries --connection-string $connectionString +$table = az storage table create -n videos --connection-string $connectionString + +Write-Output "... Updated" + +# Update appsettings.Development.json +Write-Output "Updating appsettings.Development.json ..." + +Copy-Item -Path ./AspireYouTubeSummariser.AppHost/appsettings.Development.sample.json ` + -Destination ./AspireYouTubeSummariser.AppHost/appsettings.Development.json -Force + +$appsettings = Get-Content -Path ./AspireYouTubeSummariser.AppHost/appsettings.Development.json | ConvertFrom-Json +$appsettings.ConnectionStrings.queue = $connectionString +$appsettings.ConnectionStrings.table = $connectionString +$appsettings.OpenAI = $openAI +$appsettings | ConvertTo-Json -Depth 100 | Out-File -Path ./AspireYouTubeSummariser.AppHost/appsettings.Development.json -Force + +Write-Output "... Updated" diff --git a/biceps/Set-GitHubActionsVariables.ps1 b/biceps/Set-GitHubActionsVariables.ps1 new file mode 100644 index 0000000..bec5881 --- /dev/null +++ b/biceps/Set-GitHubActionsVariables.ps1 @@ -0,0 +1,47 @@ +# Set variables for GitHub Actions +Param( + [string] + [Parameter(Mandatory=$false)] + $GitHubAlias = $null, + + [string] + [Parameter(Mandatory=$false)] + $GitHubRepository = "aspire-youtube-summariser", + + [switch] + [Parameter(Mandatory=$false)] + $Help +) + +function Show-Usage { + Write-Output " This sets variables for GitHub Actions + + Usage: $(Split-Path $MyInvocation.ScriptName -Leaf) `` + [-GitHubAlias ] `` + [-GitHubRepository ] `` + + [-Help] + + Options: + -GitHubAlias GitHub username. eg) 'devkimchi' of https://github.com/devkimchi. Default is `$null. + -GitHubRepository GitHub repository name. Default is 'aspire-youtube-summariser'. + + -Help Show this message. +" + + Exit 0 +} + +# Show usage +$needHelp = $Help -eq $true +if ($needHelp -eq $true) { + Show-Usage + Exit 0 +} + +if ($GitHubAlias -ne $null) { + $vars = gh api repos/$GitHubAlias/$GitHubRepository/actions/variables | ConvertFrom-Json + $env:AZURE_ENV_NAME = $($vars.variables | Where-Object { $_.name -eq "AZURE_ENV_NAME" }).value +} + +gh variable set -f ./.azure/$env:AZURE_ENV_NAME/.env diff --git a/biceps/openAI.bicep b/biceps/openAI.bicep new file mode 100644 index 0000000..c17570c --- /dev/null +++ b/biceps/openAI.bicep @@ -0,0 +1,63 @@ +@minLength(1) +@maxLength(64) +@description('Name of the environment that can be used as part of naming resource convention, the name of the resource group for your application will use this name, prefixed with rg-') +param environmentName string + +var tags = { + 'azd-env-name': environmentName +} + +var resourceToken = uniqueString(resourceGroup().id) +var location = 'eastus' + +var openai = { + name: 'aoai-${resourceToken}' + location: location + tags: tags + skuName: 'S0' + model: { + name: 'gpt-4-32k' + deploymentName: 'model-gpt432k' + version: '0613' + skuName: 'Standard' + skuCapacity: 10 + } +} + +resource aoai 'Microsoft.CognitiveServices/accounts@2023-05-01' = { + name: openai.name + location: openai.location + kind: 'OpenAI' + tags: openai.tags + sku: { + name: openai.skuName + } + properties: { + customSubDomainName: openai.name + publicNetworkAccess: 'Enabled' + } +} + +resource aoaiDeployment 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = { + name: openai.model.deploymentName + parent: aoai + sku: { + name: openai.model.skuName + capacity: openai.model.skuCapacity + } + properties: { + model: { + format: 'OpenAI' + name: openai.model.name + version: openai.model.version + } + } +} + +output aoaiInstance object = { + id: aoai.id + name: aoai.name + endpoint: aoai.properties.endpoint + apiKey: listKeys(aoai.id, '2023-05-01').key1 + deploymentName: aoaiDeployment.name +} diff --git a/biceps/resourceGroup.bicep b/biceps/resourceGroup.bicep new file mode 100644 index 0000000..69d38b4 --- /dev/null +++ b/biceps/resourceGroup.bicep @@ -0,0 +1 @@ +output resourceToken string = uniqueString(resourceGroup().id) diff --git a/next-steps.md b/next-steps.md new file mode 100644 index 0000000..a0803b5 --- /dev/null +++ b/next-steps.md @@ -0,0 +1,69 @@ +# Next Steps after `azd init` + +## Table of Contents + +1. [Next Steps](#next-steps) +2. [What was added](#what-was-added) +3. [Billing](#billing) +4. [Troubleshooting](#troubleshooting) + +## Next Steps + +### Provision infrastructure and deploy application code + +Run `azd up` to provision your infrastructure and deploy to Azure in one step (or run `azd provision` then `azd deploy` to accomplish the tasks separately). Visit the service endpoints listed to see your application up-and-running! + +To troubleshoot any issues, see [troubleshooting](#troubleshooting). + +### Configure CI/CD pipeline + +1. Create a workflow pipeline file locally. The following starters are available: + - [Deploy with GitHub Actions](https://github.com/Azure-Samples/azd-starter-bicep/blob/main/.github/workflows/azure-dev.yml) + - [Deploy with Azure Pipelines](https://github.com/Azure-Samples/azd-starter-bicep/blob/main/.azdo/pipelines/azure-dev.yml) +2. Run `azd pipeline config -e ` to configure the deployment pipeline to connect securely to Azure. An environment name is specified here to configure the pipeline with a different environment for isolation purposes. Run `azd env list` and `azd env set` to reselect the default environment after this step. + +## What was added + +### Infrastructure configuration + +To describe the infrastructure and application and `azure.yaml` was added with the following directory structure: + +```yaml +- azure.yaml # azd project configuration +``` + +This file contains a single service, which references your project's App Host. When needed, `azd` generates the required infrastructure as code in memory and uses it. + +If you would like to see or modify the infrastructure that `azd` uses, run `azd infra synth` to persist it to disk. + +If you do this, some additional directories will be created: + +```yaml +- infra/ # Infrastructure as Code (bicep) files + - main.bicep # main deployment module + - resources.bicep # resources shared across your application's services +``` + +In addition, for each project resource referenced by your app host, a `containerApp.tmpl.yaml` file will be created in a directory named `manifests` next the project file. This file contains the infrastructure as code for running the project on Azure Container Apps. + +*Note*: Once you have synthesized your infrastructure to disk, changes made to your App Host will not be reflected in the infrastructure. You can re-generate the infrastructure by running `azd infra synth` again. It will prompt you before overwriting files. You can pass `--force` to force `azd infra synth` to overwrite the files without prompting. + +*Note*: `azd infra synth` is currently an alpha feature and must be explicitly enabled by running `azd config set alpha.infraSynth on`. You only need to do this once. + +## Billing + +Visit the *Cost Management + Billing* page in Azure Portal to track current spend. For more information about how you're billed, and how you can monitor the costs incurred in your Azure subscriptions, visit [billing overview](https://learn.microsoft.com/en-us/azure/developer/intro/azure-developer-billing). + +## Troubleshooting + +Q: I visited the service endpoint listed, and I'm seeing a blank or error page. + +A: Your service may have failed to start or misconfigured. To investigate further: + +1. Click on the resource group link shown to visit Azure Portal. +2. Navigate to the specific Azure Container App resource for the service. +3. Select *Monitoring -> Log stream* under the navigation pane. +4. Observe the log output to identify any errors. +5. If logs are written to disk, examine the local logs or debug the application by using the *Console* to connect to a shell within the running container. + +For additional information about setting up your `azd` project, visit our official [docs](https://learn.microsoft.com/en-us/azure/developer/azure-developer-cli/make-azd-compatible?pivots=azd-convert). From 41e257ab1050a65e53f121576fb311510f285fff Mon Sep 17 00:00:00 2001 From: Justin Yoo Date: Mon, 27 Nov 2023 16:13:21 +0900 Subject: [PATCH 2/8] Update GHA workflow --- .github/workflows/azure-dev.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/azure-dev.yml b/.github/workflows/azure-dev.yml index 21ed33b..1a4c578 100644 --- a/.github/workflows/azure-dev.yml +++ b/.github/workflows/azure-dev.yml @@ -80,10 +80,10 @@ jobs: # if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' shell: pwsh run: | - $resource = az resource list -g rg-${{ vars.AZURE_ENV_NAME }} --query "[?type=='Microsoft.CognitiveServices/accounts'].name" -o tsv - $endpoint = az cognitiveservices account show -g rg-${{ vars.AZURE_ENV_NAME }} -n $instance --query "properties.endpoint" -o tsv - $apiKey = az cognitiveservices account keys list -g rg-${{ vars.AZURE_ENV_NAME }} -n $instance --query "key1" -o tsv - $deploymentId = az cognitiveservices account deployment list -g rg-${{ vars.AZURE_ENV_NAME }} -n $instance --query "[].name" -o tsv + $resourceName = az resource list -g rg-${{ vars.AZURE_ENV_NAME }} --query "[?type=='Microsoft.CognitiveServices/accounts'].name" -o tsv + $endpoint = az cognitiveservices account show -g rg-${{ vars.AZURE_ENV_NAME }} -n $resourceName --query "properties.endpoint" -o tsv + $apiKey = az cognitiveservices account keys list -g rg-${{ vars.AZURE_ENV_NAME }} -n $resourceName --query "key1" -o tsv + $deploymentId = az cognitiveservices account deployment list -g rg-${{ vars.AZURE_ENV_NAME }} -n $resourceName --query "[].name" -o tsv $openAI = @{ Endpoint = $endpoint; ApiKey = $apiKey; DeploymentId = $deploymentId; } From df73d59b2079bfe108f29cc2a0bbd81e9a705d7f Mon Sep 17 00:00:00 2001 From: Justin Yoo Date: Mon, 27 Nov 2023 16:43:04 +0900 Subject: [PATCH 3/8] Update GHA workflow --- .github/workflows/azure-dev.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/azure-dev.yml b/.github/workflows/azure-dev.yml index 1a4c578..b166e6c 100644 --- a/.github/workflows/azure-dev.yml +++ b/.github/workflows/azure-dev.yml @@ -87,12 +87,12 @@ jobs: $openAI = @{ Endpoint = $endpoint; ApiKey = $apiKey; DeploymentId = $deploymentId; } - Copy-Item -Path ./AspireYouTubeSummariser.AppHost/appsettings.Development.sample.json ` - -Destination ./AspireYouTubeSummariser.AppHost/appsettings.Development.json -Force + # Copy-Item -Path ./AspireYouTubeSummariser.AppHost/appsettings.Development.sample.json ` + # -Destination ./AspireYouTubeSummariser.AppHost/appsettings.Development.json -Force - $appsettings = Get-Content -Path ./AspireYouTubeSummariser.AppHost/appsettings.Development.json | ConvertFrom-Json + $appsettings = Get-Content -Path ./AspireYouTubeSummariser.AppHost/appsettings.json | ConvertFrom-Json $appsettings.OpenAI = $openAI - $appsettings | ConvertTo-Json -Depth 100 | Out-File -Path ./AspireYouTubeSummariser.AppHost/appsettings.Development.json -Force + $appsettings | ConvertTo-Json -Depth 100 | Out-File -Path ./AspireYouTubeSummariser.AppHost/appsettings.json -Force - name: Setup .NET SDK uses: actions/setup-dotnet@v3 From 036eb4495c6ea3196cd241dd9eb6a7967dd77b59 Mon Sep 17 00:00:00 2001 From: Justin Yoo Date: Mon, 27 Nov 2023 17:03:12 +0900 Subject: [PATCH 4/8] Add OpenTelemetry for Azure Monitor --- .../AspireYouTubeSummariser.ServiceDefaults.csproj | 3 ++- AspireYouTubeSummariser.ServiceDefaults/Extensions.cs | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/AspireYouTubeSummariser.ServiceDefaults/AspireYouTubeSummariser.ServiceDefaults.csproj b/AspireYouTubeSummariser.ServiceDefaults/AspireYouTubeSummariser.ServiceDefaults.csproj index 00e0d1f..f6823f8 100644 --- a/AspireYouTubeSummariser.ServiceDefaults/AspireYouTubeSummariser.ServiceDefaults.csproj +++ b/AspireYouTubeSummariser.ServiceDefaults/AspireYouTubeSummariser.ServiceDefaults.csproj @@ -1,4 +1,4 @@ - + Library @@ -11,6 +11,7 @@ + diff --git a/AspireYouTubeSummariser.ServiceDefaults/Extensions.cs b/AspireYouTubeSummariser.ServiceDefaults/Extensions.cs index baa7549..8097fe2 100644 --- a/AspireYouTubeSummariser.ServiceDefaults/Extensions.cs +++ b/AspireYouTubeSummariser.ServiceDefaults/Extensions.cs @@ -1,11 +1,14 @@ using System.Net; +using Azure.Monitor.OpenTelemetry.AspNetCore; + using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Http.Resilience; using Microsoft.Extensions.Logging; + using OpenTelemetry.Logs; using OpenTelemetry.Metrics; using OpenTelemetry.Trace; @@ -116,8 +119,8 @@ private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostAppli // .WithMetrics(metrics => metrics.AddPrometheusExporter()); // Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.Exporter package) - // builder.Services.AddOpenTelemetry() - // .UseAzureMonitor(); + builder.Services.AddOpenTelemetry() + .UseAzureMonitor(); return builder; } From aa7afcb0cae1e4221abaf09ac014e4e7a969ab63 Mon Sep 17 00:00:00 2001 From: Justin Yoo Date: Mon, 27 Nov 2023 18:08:10 +0900 Subject: [PATCH 5/8] Disable AzureMonitor --- .../Extensions.cs | 4 +- biceps/Purge-CognitiveServices.ps1 | 163 ++++++++++++++++++ 2 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 biceps/Purge-CognitiveServices.ps1 diff --git a/AspireYouTubeSummariser.ServiceDefaults/Extensions.cs b/AspireYouTubeSummariser.ServiceDefaults/Extensions.cs index 8097fe2..b57d2d7 100644 --- a/AspireYouTubeSummariser.ServiceDefaults/Extensions.cs +++ b/AspireYouTubeSummariser.ServiceDefaults/Extensions.cs @@ -119,8 +119,8 @@ private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostAppli // .WithMetrics(metrics => metrics.AddPrometheusExporter()); // Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.Exporter package) - builder.Services.AddOpenTelemetry() - .UseAzureMonitor(); + // builder.Services.AddOpenTelemetry() + // .UseAzureMonitor(); return builder; } diff --git a/biceps/Purge-CognitiveServices.ps1 b/biceps/Purge-CognitiveServices.ps1 new file mode 100644 index 0000000..39a06a7 --- /dev/null +++ b/biceps/Purge-CognitiveServices.ps1 @@ -0,0 +1,163 @@ +# Purges the deleted the Azure Cognitive Service instance. +Param( + [string] + [Parameter(Mandatory=$false)] + $ApiVersion = "2021-10-01", + + [switch] + [Parameter(Mandatory=$false)] + $Help +) + +function Show-Usage { + Write-Output " This permanently deletes the Azure Cognitive Service instance + + Usage: $(Split-Path $MyInvocation.ScriptName -Leaf) `` + [-ApiVersion ] `` + + [-Help] + + Options: + -ApiVersion REST API version. Default is `2021-10-01`. + + -Help: Show this message. +" + + Exit 0 +} + +# Show usage +$needHelp = $Help -eq $true +if ($needHelp -eq $true) { + Show-Usage + Exit 0 +} + +# List soft-deleted Azure Cognitive Service instances +function List-DeletedCognitiveServices { + param ( + [string] $ApiVersion + ) + + $account = $(az account show | ConvertFrom-Json) + + $url = "https://management.azure.com/subscriptions/$($account.id)/providers/Microsoft.CognitiveServices/deletedAccounts?api-version=$($ApiVersion)" + + # Uncomment to debug + # $url + + $options = "" + + $aoais = $(az rest -m get -u $url --query "value" | ConvertFrom-Json) + if ($aoais -eq $null) { + $options = "All soft-deleted Azure Cognitive Service instances purged or no such instance found to purge" + $returnValue = @{ aoais = $aoais; options = $options } + return $returnValue + } + + if ($aoais.Count -eq 1) { + $name = $aoais.name + $options += " 1: $name `n" + } else { + $aoais | ForEach-Object { + $i = $aoais.IndexOf($_) + $name = $_.name + $options += " $($i +1): $name `n" + } + } + $options += " a: Purge all`n" + $options += " q: Quit`n" + + $returnValue = @{ aoais = $aoais; options = $options } + return $returnValue +} + +# Purge all soft-deleted Azure Cognitive Service instances at once. +function Purge-AllDeletedCognitiveServices { + param ( + [string] $ApiVersion, + [object[]] $Instances + ) + + Process { + $Instances | ForEach-Object { + Write-Output "Purging $($_.name) ..." + + $url = "https://management.azure.com$($_.id)?api-version=$($ApiVersion)" + + $aoai = $(az rest -m get -u $url) + if ($aoai -ne $null) { + $deleted = $(az rest -m delete -u $url) + } + + Write-Output "... $($_.name) purged" + } + + Write-Output "All soft-deleted Azure Cognitive Service instances purged" + } +} + +# Purge soft-deleted Azure Cognitive Service instances +function Purge-DeletedCognitiveServices { + param ( + [string] $ApiVersion + ) + + $continue = $true + $result = List-DeletedCognitiveServices -ApiVersion $ApiVersion + if ($result.aoais -eq $null) { + $continue = $false + } + + while ($continue -eq $true) { + $options = $result.options + + $input = Read-Host "Select the number to purge the soft-deleted Azure Cognitive Service instance, 'a' to purge all or 'q' to quit: `n`n$options" + if ($input -eq "q") { + $continue = $false + break + } + + if ($input -eq "a") { + Purge-AllDeletedCognitiveServices -ApiVersion $ApiVersion -Instances $result.aoais + break + } + + $parsed = $input -as [int] + if ($parsed -eq $null) { + Write-Output "Invalid input" + $continue = $false + break + } + + $aoais = $result.aoais + if ($parsed -gt $aoais.Count) { + Write-Output "Invalid input" + $continue = $false + break + } + + $index = $parsed - 1 + + $url = "https://management.azure.com$($aoais[$index].id)?api-version=$($ApiVersion)" + + # Uncomment to debug + # $url + + $apim = $(az rest -m get -u $url) + if ($apim -ne $null) { + $deleted = $(az rest -m delete -u $url) + } + + $result = List-DeletedCognitiveServices -ApiVersion $ApiVersion + if ($result.aoais -eq $null) { + $continue = $false + } + } + + if ($continue -eq $false) { + return $result.options + } +} + +Purge-DeletedCognitiveServices -ApiVersion $ApiVersion From ba4c385a921765ec99e7cc31081158042f97c5da Mon Sep 17 00:00:00 2001 From: Justin Yoo Date: Mon, 27 Nov 2023 18:23:42 +0900 Subject: [PATCH 6/8] Update GHA workflow --- .github/workflows/azure-dev.yml | 11 +++++++---- README.md | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/azure-dev.yml b/.github/workflows/azure-dev.yml index b166e6c..3f37d4a 100644 --- a/.github/workflows/azure-dev.yml +++ b/.github/workflows/azure-dev.yml @@ -4,6 +4,9 @@ on: branches: - main - 'feature/*' + pull_request: + branches: + - main # https://learn.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-portal%2Clinux#set-up-azure-login-with-openid-connect-authentication permissions: @@ -87,12 +90,12 @@ jobs: $openAI = @{ Endpoint = $endpoint; ApiKey = $apiKey; DeploymentId = $deploymentId; } - # Copy-Item -Path ./AspireYouTubeSummariser.AppHost/appsettings.Development.sample.json ` - # -Destination ./AspireYouTubeSummariser.AppHost/appsettings.Development.json -Force + Copy-Item -Path ./AspireYouTubeSummariser.AppHost/appsettings.Development.sample.json ` + -Destination ./AspireYouTubeSummariser.AppHost/appsettings.Development.json -Force - $appsettings = Get-Content -Path ./AspireYouTubeSummariser.AppHost/appsettings.json | ConvertFrom-Json + $appsettings = Get-Content -Path ./AspireYouTubeSummariser.AppHost/appsettings.Development.json | ConvertFrom-Json $appsettings.OpenAI = $openAI - $appsettings | ConvertTo-Json -Depth 100 | Out-File -Path ./AspireYouTubeSummariser.AppHost/appsettings.json -Force + $appsettings | ConvertTo-Json -Depth 100 | Out-File -Path ./AspireYouTubeSummariser.AppHost/appsettings.Development.json -Force - name: Setup .NET SDK uses: actions/setup-dotnet@v3 diff --git a/README.md b/README.md index 7f1349e..7bac46e 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,8 @@ This provides sample Aspire-orchestrated apps that summarise a YouTube video tra azd deploy ``` +1. Push code changes to the GitHub repository to trigger a GitHub Actions workflow. + ## Resources - [.NET Aspire overview](https://learn.microsoft.com/dotnet/aspire/get-started/aspire-overview?WT.mc_id=dotnet-107070-juyoo) From 43037859180785ecae5f186c090dd2c359ed6bb9 Mon Sep 17 00:00:00 2001 From: Justin Yoo Date: Mon, 27 Nov 2023 18:48:10 +0900 Subject: [PATCH 7/8] Update GHA workflow --- .github/workflows/azure-dev.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/azure-dev.yml b/.github/workflows/azure-dev.yml index 3f37d4a..788133e 100644 --- a/.github/workflows/azure-dev.yml +++ b/.github/workflows/azure-dev.yml @@ -22,7 +22,7 @@ jobs: uses: actions/checkout@v4 - name: Login to Azure - # if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' + # if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' uses: azure/login@v1 with: tenant-id: ${{ vars.AZURE_TENANT_ID }} @@ -30,18 +30,18 @@ jobs: client-id: ${{ vars.AZURE_CLIENT_ID }} # - name: Install Azure Developer CLI - # if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' + # if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' # uses: Azure/setup-azd@v0.1.0 - name: Install Azure Developer CLI (nightly build) - # if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' + # if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' shell: pwsh run: | Invoke-RestMethod 'https://aka.ms/install-azd.ps1' -OutFile ./install-azd.ps1 ./install-azd.ps1 -Version daily - name: Login to Azure Developer CLI - # if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' + # if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' shell: pwsh run: | azd auth login ` @@ -50,7 +50,7 @@ jobs: --federated-credential-provider "${{ vars.AZD_PIPELINE_PROVIDER }}" - name: Setup environment - # if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' + # if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' shell: pwsh run: | # Create config.json under .azure @@ -80,7 +80,7 @@ jobs: $dotenv | Out-File -Path ./.azure/${{ vars.AZURE_ENV_NAME }}/.env -Force - name: Update appsettings.json - # if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' + # if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' shell: pwsh run: | $resourceName = az resource list -g rg-${{ vars.AZURE_ENV_NAME }} --query "[?type=='Microsoft.CognitiveServices/accounts'].name" -o tsv @@ -90,12 +90,12 @@ jobs: $openAI = @{ Endpoint = $endpoint; ApiKey = $apiKey; DeploymentId = $deploymentId; } - Copy-Item -Path ./AspireYouTubeSummariser.AppHost/appsettings.Development.sample.json ` - -Destination ./AspireYouTubeSummariser.AppHost/appsettings.Development.json -Force + # Copy-Item -Path ./AspireYouTubeSummariser.AppHost/appsettings.Development.sample.json ` + # -Destination ./AspireYouTubeSummariser.AppHost/appsettings.Development.json -Force - $appsettings = Get-Content -Path ./AspireYouTubeSummariser.AppHost/appsettings.Development.json | ConvertFrom-Json + $appsettings = Get-Content -Path ./AspireYouTubeSummariser.AppHost/appsettings.json | ConvertFrom-Json $appsettings.OpenAI = $openAI - $appsettings | ConvertTo-Json -Depth 100 | Out-File -Path ./AspireYouTubeSummariser.AppHost/appsettings.Development.json -Force + $appsettings | ConvertTo-Json -Depth 100 | Out-File -Path ./AspireYouTubeSummariser.AppHost/appsettings.json -Force - name: Setup .NET SDK uses: actions/setup-dotnet@v3 @@ -124,7 +124,7 @@ jobs: dotnet test - name: Deploy to Azure Container Apps - # if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' + # if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' shell: pwsh run: | azd deploy From fcbfeb3d6e982c87f45f9bf8873a53140c15650a Mon Sep 17 00:00:00 2001 From: Justin Yoo Date: Mon, 27 Nov 2023 18:54:57 +0900 Subject: [PATCH 8/8] Update GHA workflow --- .github/workflows/azure-dev.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/azure-dev.yml b/.github/workflows/azure-dev.yml index 788133e..7476c72 100644 --- a/.github/workflows/azure-dev.yml +++ b/.github/workflows/azure-dev.yml @@ -22,7 +22,7 @@ jobs: uses: actions/checkout@v4 - name: Login to Azure - # if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' + if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' uses: azure/login@v1 with: tenant-id: ${{ vars.AZURE_TENANT_ID }} @@ -34,14 +34,14 @@ jobs: # uses: Azure/setup-azd@v0.1.0 - name: Install Azure Developer CLI (nightly build) - # if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' + if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' shell: pwsh run: | Invoke-RestMethod 'https://aka.ms/install-azd.ps1' -OutFile ./install-azd.ps1 ./install-azd.ps1 -Version daily - name: Login to Azure Developer CLI - # if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' + if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' shell: pwsh run: | azd auth login ` @@ -50,7 +50,7 @@ jobs: --federated-credential-provider "${{ vars.AZD_PIPELINE_PROVIDER }}" - name: Setup environment - # if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' + if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' shell: pwsh run: | # Create config.json under .azure @@ -80,7 +80,7 @@ jobs: $dotenv | Out-File -Path ./.azure/${{ vars.AZURE_ENV_NAME }}/.env -Force - name: Update appsettings.json - # if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' + if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' shell: pwsh run: | $resourceName = az resource list -g rg-${{ vars.AZURE_ENV_NAME }} --query "[?type=='Microsoft.CognitiveServices/accounts'].name" -o tsv @@ -124,7 +124,7 @@ jobs: dotnet test - name: Deploy to Azure Container Apps - # if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' + if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' shell: pwsh run: | azd deploy