From d6fac55bdbc9b2316b1456066b83c03f41729e2f Mon Sep 17 00:00:00 2001 From: Gwyneth Pena-Siguenza Date: Wed, 4 Sep 2024 06:40:48 -0400 Subject: [PATCH 1/6] Add GitHub Actions workflow for .NET Core Azure deployment Added a new GitHub Actions workflow configuration in the `azureprojectgenerator.yml` file to automate the build and deployment of a .NET Core application to an Azure Function App. The workflow triggers on push events to the `generatesmallerprojects` branch and includes environment variable setup, build, and deploy jobs. The build job handles dependency restoration, project build, and artifact upload, while the deploy job manages the deployment to Azure. --- .github/workflows/azureprojectgenerator.yml | 51 +++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/azureprojectgenerator.yml diff --git a/.github/workflows/azureprojectgenerator.yml b/.github/workflows/azureprojectgenerator.yml new file mode 100644 index 0000000..c0d4024 --- /dev/null +++ b/.github/workflows/azureprojectgenerator.yml @@ -0,0 +1,51 @@ +name: Build and deploy .NET Core application to Function App azureprojectgenerator +on: + push: + branches: + - generatesmallerprojects +env: + AZURE_FUNCTIONAPP_NAME: azureprojectgenerator + AZURE_FUNCTIONAPP_PACKAGE_PATH: azure-project-generator/published + CONFIGURATION: Release + DOTNET_CORE_VERSION: 8.0.x + WORKING_DIRECTORY: azure-project-generator + DOTNET_CORE_VERSION_INPROC: 6.0.x +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup .NET SDK + uses: actions/setup-dotnet@v3 + with: + dotnet-version: ${{ env.DOTNET_CORE_VERSION }} + - name: Setup .NET Core (for inproc extensions) + uses: actions/setup-dotnet@v1 + with: + dotnet-version: ${{ env.DOTNET_CORE_VERSION_INPROC }} + - name: Restore + run: dotnet restore "${{ env.WORKING_DIRECTORY }}" + - name: Build + run: dotnet build "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-restore + - name: Publish + run: dotnet publish "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-build --output "${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}" + - name: Publish Artifacts + uses: actions/upload-artifact@v3 + with: + name: functionapp + path: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }} + deploy: + runs-on: ubuntu-latest + needs: build + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v3 + with: + name: functionapp + path: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }} + - name: Deploy to Azure Function App + uses: Azure/functions-action@v1 + with: + app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }} + publish-profile: ${{ secrets.azureprojectgenerator_A149 }} + package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }} From 278aa05be779dd89e61178e515ecdbcb119ce8e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwyneth=20Pe=C3=B1a-Siguenza?= Date: Wed, 4 Sep 2024 09:19:31 -0400 Subject: [PATCH 2/6] Update azureprojectgenerator.yml --- .github/workflows/azureprojectgenerator.yml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/azureprojectgenerator.yml b/.github/workflows/azureprojectgenerator.yml index c0d4024..11f505c 100644 --- a/.github/workflows/azureprojectgenerator.yml +++ b/.github/workflows/azureprojectgenerator.yml @@ -6,10 +6,9 @@ on: env: AZURE_FUNCTIONAPP_NAME: azureprojectgenerator AZURE_FUNCTIONAPP_PACKAGE_PATH: azure-project-generator/published - CONFIGURATION: Release - DOTNET_CORE_VERSION: 8.0.x + DOTNET_VERSION: 8.0.x WORKING_DIRECTORY: azure-project-generator - DOTNET_CORE_VERSION_INPROC: 6.0.x + jobs: build: runs-on: ubuntu-latest @@ -18,11 +17,7 @@ jobs: - name: Setup .NET SDK uses: actions/setup-dotnet@v3 with: - dotnet-version: ${{ env.DOTNET_CORE_VERSION }} - - name: Setup .NET Core (for inproc extensions) - uses: actions/setup-dotnet@v1 - with: - dotnet-version: ${{ env.DOTNET_CORE_VERSION_INPROC }} + dotnet-version: ${{ env.DOTNET_VERSION }} - name: Restore run: dotnet restore "${{ env.WORKING_DIRECTORY }}" - name: Build From 6ece865f3753fcebaf9f6061822203456fcfda94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwyneth=20Pe=C3=B1a-Siguenza?= Date: Wed, 4 Sep 2024 09:22:24 -0400 Subject: [PATCH 3/6] Update azureprojectgenerator.yml --- .github/workflows/azureprojectgenerator.yml | 54 ++++++++++----------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/.github/workflows/azureprojectgenerator.yml b/.github/workflows/azureprojectgenerator.yml index 11f505c..02c4254 100644 --- a/.github/workflows/azureprojectgenerator.yml +++ b/.github/workflows/azureprojectgenerator.yml @@ -7,40 +7,38 @@ env: AZURE_FUNCTIONAPP_NAME: azureprojectgenerator AZURE_FUNCTIONAPP_PACKAGE_PATH: azure-project-generator/published DOTNET_VERSION: 8.0.x - WORKING_DIRECTORY: azure-project-generator jobs: - build: - runs-on: ubuntu-latest + build-and-deploy: + runs-on: ubuntu-latest # For Linux, use ubuntu-latest + environment: dev steps: - - uses: actions/checkout@v4 - - name: Setup .NET SDK + - name: 'Checkout GitHub Action' + uses: actions/checkout@v3 + + - name: Setup DotNet ${{ env.DOTNET_VERSION }} Environment uses: actions/setup-dotnet@v3 with: dotnet-version: ${{ env.DOTNET_VERSION }} - - name: Restore - run: dotnet restore "${{ env.WORKING_DIRECTORY }}" - - name: Build - run: dotnet build "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-restore - - name: Publish - run: dotnet publish "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-build --output "${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}" - - name: Publish Artifacts - uses: actions/upload-artifact@v3 - with: - name: functionapp - path: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }} - deploy: - runs-on: ubuntu-latest - needs: build - steps: - - name: Download artifact from build job - uses: actions/download-artifact@v3 - with: - name: functionapp - path: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }} - - name: Deploy to Azure Function App + + - name: 'Resolve Project Dependencies Using Dotnet' + shell: pwsh # For Linux, use bash + run: | + pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}' + dotnet build --configuration Release --output ./output + popd + + - name: 'Run Unit Tests' + shell: pwsh # For Linux, use bash + run: | + pushd './tests' + dotnet test --verbosity normal + popd + + - name: 'Run Azure Functions Action' uses: Azure/functions-action@v1 + id: fa with: app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }} - publish-profile: ${{ secrets.azureprojectgenerator_A149 }} - package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }} + package: '${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}/output' + publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }} From e148b45128adcd9dc24739e2bd9a4a40a89bd55f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwyneth=20Pe=C3=B1a-Siguenza?= Date: Wed, 4 Sep 2024 09:24:40 -0400 Subject: [PATCH 4/6] Update azureprojectgenerator.yml --- .github/workflows/azureprojectgenerator.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/azureprojectgenerator.yml b/.github/workflows/azureprojectgenerator.yml index 02c4254..2d5a50d 100644 --- a/.github/workflows/azureprojectgenerator.yml +++ b/.github/workflows/azureprojectgenerator.yml @@ -28,13 +28,6 @@ jobs: dotnet build --configuration Release --output ./output popd - - name: 'Run Unit Tests' - shell: pwsh # For Linux, use bash - run: | - pushd './tests' - dotnet test --verbosity normal - popd - - name: 'Run Azure Functions Action' uses: Azure/functions-action@v1 id: fa From 460591064854a4e180a64de88cd80d251302e39e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwyneth=20Pe=C3=B1a-Siguenza?= Date: Wed, 4 Sep 2024 09:28:16 -0400 Subject: [PATCH 5/6] Update azureprojectgenerator.yml --- .github/workflows/azureprojectgenerator.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/azureprojectgenerator.yml b/.github/workflows/azureprojectgenerator.yml index 2d5a50d..bb26a5d 100644 --- a/.github/workflows/azureprojectgenerator.yml +++ b/.github/workflows/azureprojectgenerator.yml @@ -5,7 +5,7 @@ on: - generatesmallerprojects env: AZURE_FUNCTIONAPP_NAME: azureprojectgenerator - AZURE_FUNCTIONAPP_PACKAGE_PATH: azure-project-generator/published + AZURE_FUNCTIONAPP_PACKAGE_PATH: azure-project-generator DOTNET_VERSION: 8.0.x jobs: From 33b7e46eceff87ca4492470d98a101e185fa3b5b Mon Sep 17 00:00:00 2001 From: Gwyneth Pena-Siguenza Date: Wed, 4 Sep 2024 10:40:48 -0400 Subject: [PATCH 6/6] Update Program.cs, add ARM templates, and upgrade package - Updated `Program.cs` to use `ConfigureFunctionsWebApplication` instead of `ConfigureFunctionsWorkerDefaults`. - Added ARM templates: `appInsights1.arm.json` for Application Insights and `storage1.arm.json` for Storage Account. - Updated `serviceDependencies.azureprojectgenerator.json` to include resource IDs and connection strings for the new resources. - Updated `serviceDependencies.json` to include connection IDs for the new resources. - Upgraded `Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore` in `azure-project-generator.csproj` from version `1.2.1` to `1.3.2`. - Removed an unnecessary empty line in the constructor of `ContentGenerationService.cs`. --- azure-project-generator/Program.cs | 2 +- .../appInsights1.arm.json | 67 ++++++++++++++++++ .../azureprojectgenerator/storage1.arm.json | 70 +++++++++++++++++++ ...iceDependencies.azureprojectgenerator.json | 14 ++++ .../Properties/serviceDependencies.json | 15 ++-- .../azure-project-generator.csproj | 2 +- .../services/ContentGenerationService.cs | 1 - 7 files changed, 161 insertions(+), 10 deletions(-) create mode 100644 azure-project-generator/Properties/ServiceDependencies/azureprojectgenerator/appInsights1.arm.json create mode 100644 azure-project-generator/Properties/ServiceDependencies/azureprojectgenerator/storage1.arm.json create mode 100644 azure-project-generator/Properties/serviceDependencies.azureprojectgenerator.json diff --git a/azure-project-generator/Program.cs b/azure-project-generator/Program.cs index 5e3f857..240db6b 100644 --- a/azure-project-generator/Program.cs +++ b/azure-project-generator/Program.cs @@ -7,7 +7,7 @@ using Microsoft.Extensions.Hosting; var host = new HostBuilder() - .ConfigureFunctionsWorkerDefaults() + .ConfigureFunctionsWebApplication() .ConfigureServices((context, services) => { services.AddApplicationInsightsTelemetryWorkerService(); diff --git a/azure-project-generator/Properties/ServiceDependencies/azureprojectgenerator/appInsights1.arm.json b/azure-project-generator/Properties/ServiceDependencies/azureprojectgenerator/appInsights1.arm.json new file mode 100644 index 0000000..380de34 --- /dev/null +++ b/azure-project-generator/Properties/ServiceDependencies/azureprojectgenerator/appInsights1.arm.json @@ -0,0 +1,67 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "resourceGroupName": { + "type": "string", + "defaultValue": "azureprojectgenerator-rg", + "metadata": { + "_parameterType": "resourceGroup", + "description": "Name of the resource group for the resource. It is recommended to put resources under same resource group for better tracking." + } + }, + "resourceGroupLocation": { + "type": "string", + "defaultValue": "eastus", + "metadata": { + "_parameterType": "location", + "description": "Location of the resource group. Resource groups could have different location than resources." + } + }, + "resourceLocation": { + "type": "string", + "defaultValue": "[parameters('resourceGroupLocation')]", + "metadata": { + "_parameterType": "location", + "description": "Location of the resource. By default use resource group's location, unless the resource provider is not supported there." + } + } + }, + "resources": [ + { + "type": "Microsoft.Resources/resourceGroups", + "name": "[parameters('resourceGroupName')]", + "location": "[parameters('resourceGroupLocation')]", + "apiVersion": "2019-10-01" + }, + { + "type": "Microsoft.Resources/deployments", + "name": "[concat(parameters('resourceGroupName'), 'Deployment', uniqueString(concat('azure-project-generator', subscription().subscriptionId)))]", + "resourceGroup": "[parameters('resourceGroupName')]", + "apiVersion": "2019-10-01", + "dependsOn": [ + "[parameters('resourceGroupName')]" + ], + "properties": { + "mode": "Incremental", + "template": { + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "resources": [ + { + "kind": "web", + "name": "azure-project-generator", + "type": "microsoft.insights/components", + "location": "[parameters('resourceLocation')]", + "properties": {}, + "apiVersion": "2015-05-01" + } + ] + } + } + } + ], + "metadata": { + "_dependencyType": "appInsights.azure" + } +} \ No newline at end of file diff --git a/azure-project-generator/Properties/ServiceDependencies/azureprojectgenerator/storage1.arm.json b/azure-project-generator/Properties/ServiceDependencies/azureprojectgenerator/storage1.arm.json new file mode 100644 index 0000000..cb635bd --- /dev/null +++ b/azure-project-generator/Properties/ServiceDependencies/azureprojectgenerator/storage1.arm.json @@ -0,0 +1,70 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "resourceGroupName": { + "type": "string", + "defaultValue": "azureprojectgenerator-rg", + "metadata": { + "_parameterType": "resourceGroup", + "description": "Name of the resource group for the resource. It is recommended to put resources under same resource group for better tracking." + } + }, + "resourceGroupLocation": { + "type": "string", + "defaultValue": "eastus", + "metadata": { + "_parameterType": "location", + "description": "Location of the resource group. Resource groups could have different location than resources." + } + }, + "resourceLocation": { + "type": "string", + "defaultValue": "[parameters('resourceGroupLocation')]", + "metadata": { + "_parameterType": "location", + "description": "Location of the resource. By default use resource group's location, unless the resource provider is not supported there." + } + } + }, + "resources": [ + { + "type": "Microsoft.Resources/resourceGroups", + "name": "[parameters('resourceGroupName')]", + "location": "[parameters('resourceGroupLocation')]", + "apiVersion": "2019-10-01" + }, + { + "type": "Microsoft.Resources/deployments", + "name": "[concat(parameters('resourceGroupName'), 'Deployment', uniqueString(concat('azureprojectgenstor', subscription().subscriptionId)))]", + "resourceGroup": "[parameters('resourceGroupName')]", + "apiVersion": "2019-10-01", + "dependsOn": [ + "[parameters('resourceGroupName')]" + ], + "properties": { + "mode": "Incremental", + "template": { + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "resources": [ + { + "sku": { + "name": "Standard_RAGRS", + "tier": "Standard" + }, + "kind": "StorageV2", + "name": "azureprojectgenstor", + "type": "Microsoft.Storage/storageAccounts", + "location": "[parameters('resourceLocation')]", + "apiVersion": "2017-10-01" + } + ] + } + } + } + ], + "metadata": { + "_dependencyType": "storage.azure" + } +} \ No newline at end of file diff --git a/azure-project-generator/Properties/serviceDependencies.azureprojectgenerator.json b/azure-project-generator/Properties/serviceDependencies.azureprojectgenerator.json new file mode 100644 index 0000000..c0eb4f4 --- /dev/null +++ b/azure-project-generator/Properties/serviceDependencies.azureprojectgenerator.json @@ -0,0 +1,14 @@ +{ + "dependencies": { + "appInsights1": { + "resourceId": "/subscriptions/[parameters('subscriptionId')]/resourceGroups/[parameters('resourceGroupName')]/providers/microsoft.insights/components/azure-project-generator", + "type": "appInsights.azure", + "connectionId": "APPLICATIONINSIGHTS_CONNECTION_STRING" + }, + "storage1": { + "resourceId": "/subscriptions/[parameters('subscriptionId')]/resourceGroups/[parameters('resourceGroupName')]/providers/Microsoft.Storage/storageAccounts/azureprojectgenstor", + "type": "storage.azure", + "connectionId": "AzureWebJobsStorage" + } + } +} \ No newline at end of file diff --git a/azure-project-generator/Properties/serviceDependencies.json b/azure-project-generator/Properties/serviceDependencies.json index 0b7b98a..498af49 100644 --- a/azure-project-generator/Properties/serviceDependencies.json +++ b/azure-project-generator/Properties/serviceDependencies.json @@ -1,12 +1,5 @@ { "dependencies": { - "appInsights1": { - "type": "appInsights" - }, - "storage1": { - "type": "storage", - "connectionId": "AzureWebJobsStorage" - }, "secrets1": { "type": "secrets" }, @@ -14,6 +7,14 @@ "type": "storage", "connectionId": "azurestorage", "dynamicId": null + }, + "appInsights1": { + "type": "appInsights", + "connectionId": "APPLICATIONINSIGHTS_CONNECTION_STRING" + }, + "storage1": { + "type": "storage", + "connectionId": "AzureWebJobsStorage" } } } \ No newline at end of file diff --git a/azure-project-generator/azure-project-generator.csproj b/azure-project-generator/azure-project-generator.csproj index 1a87338..551488a 100644 --- a/azure-project-generator/azure-project-generator.csproj +++ b/azure-project-generator/azure-project-generator.csproj @@ -21,7 +21,7 @@ - + diff --git a/azure-project-generator/services/ContentGenerationService.cs b/azure-project-generator/services/ContentGenerationService.cs index 5f59657..4e0989c 100644 --- a/azure-project-generator/services/ContentGenerationService.cs +++ b/azure-project-generator/services/ContentGenerationService.cs @@ -17,7 +17,6 @@ public ContentGenerationService(ILogger logger, Embedd _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _embeddingClient = embeddingClient ?? throw new ArgumentNullException(nameof(embeddingClient)); _completionsClient = completionsClient ?? throw new ArgumentNullException(nameof(completionsClient)); - } public string GenerateCertServiceContextSentence(CertificationService data) =>