From c6585ec7015b4f391a517882c5b9d0193686b98a Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Tue, 29 Oct 2024 13:28:26 +0100 Subject: [PATCH 01/29] Remove pages YAML file --- .github/workflows/pages.yml | 62 ------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 .github/workflows/pages.yml diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml deleted file mode 100644 index cedae546..00000000 --- a/.github/workflows/pages.yml +++ /dev/null @@ -1,62 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -# Sample workflow for building and deploying a Jekyll site to GitHub Pages -name: Deploy Jekyll site to Pages - -on: - push: - branches: ["main"] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages -permissions: - contents: read - pages: write - id-token: write - -# Allow one concurrent deployment -concurrency: - group: "pages" - cancel-in-progress: true - -jobs: - # Build job - build: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Setup Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3.1' # Not needed with a .ruby-version file - bundler-cache: true # runs 'bundle install' and caches installed gems automatically - cache-version: 0 # Increment this number if you need to re-download cached gems - - name: Setup Pages - id: pages - uses: actions/configure-pages@v2 - - name: Build with Jekyll - # Outputs to the './_site' directory by default - run: bundle exec jekyll build --baseurl "${{ steps.pages.outputs.base_path }}" - env: - JEKYLL_ENV: production - - name: Upload artifact - # Automatically uploads an artifact from the './_site' directory by default - uses: actions/upload-pages-artifact@v1 - - # Deployment job - deploy: - environment: - name: github-pages - url: "${{ steps.deployment.outputs.page_url }}" - runs-on: ubuntu-latest - needs: build - steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v1 From 5758ecd8a7eeedb25ed524986029766518abf241 Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Tue, 29 Oct 2024 13:44:24 +0100 Subject: [PATCH 02/29] Add first workflow YAML file --- .github/workflows/first-workflow.yml | 56 ++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/workflows/first-workflow.yml diff --git a/.github/workflows/first-workflow.yml b/.github/workflows/first-workflow.yml new file mode 100644 index 00000000..62e09a19 --- /dev/null +++ b/.github/workflows/first-workflow.yml @@ -0,0 +1,56 @@ +# The name of the job is what will display on the GitHub repository in the Actions tab. +name: First Workflow + +# The 'on' section tells GitHub under what conditions we want to run this workflow. +# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows +# Common scenarios include: +# workflow-dispatch (manual execution) +# issues +# push +# pull_request +# schedule +on: + workflow_dispatch: + issues: + types: [opened] + +# This section covers the work to perform. +# We include one or more jobs in this section. +jobs: + # Each individual job will include details like execution order, + # pre-requisite jobs, and execution platform. + job1: + # We can run jobs on GitHub hosted VM runners in Windows, Ubuntu, and Mac OS. + # We can also run jobs on self-hosted hardware. + runs-on: ubuntu-latest + + # Each job contains one or more steps. A step needs to have at least a name and a command. + steps: + - name: Step one + # The 'run' command executes a shell or command script. Because this is Ubuntu, the + # default run command will be /bin/bash + run: echo "Log from step one" + # This section does not appear in the solution file but demonstrates how to set + # custom variables that will be available in the run script. + env: + VARIABLE_NAME: value + - name: Step two + run: echo "Log from step two" + + job2: + # Job 2 will only run after job 1 completes. + # Removing this 'needs' section would make the jobs run simultaneously. + needs: job1 + runs-on: ubuntu-latest + + steps: + - name: Cowsays + # The 'uses' command executes a remote GitHub action. + # A command like mscoutermarsh/cowsays-action means you can + # find this code at https://github.com/mscoutermarsh/cowsays-action + uses: mscoutermarsh/cowsays-action@master + # The 'with' block includes parameters that the workflow will pass + # to this action. Parameters are all in key-value format. + with: + text: "Ready for prod--ship it!" + color: "magenta" From cb92614c36b04a3f3a121b3198cf67658c07b720 Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Tue, 29 Oct 2024 14:28:04 +0100 Subject: [PATCH 03/29] Update character limit for message text field --- .../src/RazorPagesTestSample/Data/Message.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Application/src/RazorPagesTestSample/Data/Message.cs b/src/Application/src/RazorPagesTestSample/Data/Message.cs index ea99cbd6..85cfc22e 100644 --- a/src/Application/src/RazorPagesTestSample/Data/Message.cs +++ b/src/Application/src/RazorPagesTestSample/Data/Message.cs @@ -7,9 +7,21 @@ public class Message { public int Id { get; set; } - [Required] + /// + /// Gets or sets the text of the message. + /// + /// + /// The text content of the message, limited to 250 characters. + /// + /// + /// The text must be a valid string and is required. If the text exceeds 250 characters, an error message will be displayed. + /// + /// + /// Thrown when the text exceeds 250 characters or is not provided. + /// + /// /// /// /// /// /// /// /// /// /// /// /// [Required] [DataType(DataType.Text)] - [StringLength(200, ErrorMessage = "There's a 200 character limit on messages. Please shorten your message.")] + [StringLength(250, ErrorMessage = "There's a 200 character limit on messages. Please shorten your message.")] public string Text { get; set; } } #endregion From 6cb1bbf911906aac2c5977fcc9cfd4529035ae48 Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Tue, 29 Oct 2024 14:57:05 +0100 Subject: [PATCH 04/29] Add workflow YAML file for Azure Bicep deployment --- .github/workflows/deploy.yml | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..8d169abe --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,51 @@ +# We only want to run this script manually. +on: workflow_dispatch + +# Environment variables are defined in an "env" section. +# We set the target environment to dev. +# Open the deploy-advanced.yml file to see how we can accept user input +# instead of needing to change this file to switch environments. +env: + targetEnv: dev + +# The overall workflow name will be Azure Bicep. This will show up in the +# GitHub Action page. +name: Azure Bicep +jobs: + # This script has one job: build and deploy the IaC resources + build-and-deploy: + # We run this on an Ubuntu-based GitHub hosted runner. This hosted runner + # has certain software already installed, including az cli + runs-on: ubuntu-latest + steps: + # Check out the code. This grabs code from the repository and + # makes it available to the GitHub hosted runner. It will usually be the + # first task for any workflow + - uses: actions/checkout@main + + # Log into Azure using a federated credential. We have already set up the + # federation process in a prior step, so we need to pass in the following: + # Client ID = Application registration ID + # Tenant ID = Application owner organization ID (previously called Tenant ID in Azure) + # Subscription ID + # https://github.com/azure/login + - uses: azure/login@v2.1.1 + with: + client-id: $ + tenant-id: $ + subscription-id: $ + # We also need to ensure that enable-AzPSSession is true. This is important for + # using OIDC in Azure. If we were to pass in a client secret instead, we would not need + # this setting enabled + enable-AzPSSession: true + + # Deploy ARM template + - name: Run ARM deploy + # https://github.com/azure/arm-deploy + uses: azure/arm-deploy@v1 + with: + subscriptionId: $ + resourceGroupName: $ + template: ./InfrastructureAsCode/main.bicep + # Use the environment variable called targetEnv + parameters: environment=$ From bd79bd420ddab9198c8078fc6a8d09bd389be58e Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Tue, 29 Oct 2024 15:07:18 +0100 Subject: [PATCH 05/29] Update deploy.yml --- .github/workflows/deploy.yml | 66 ++++++++++++++---------------------- 1 file changed, 25 insertions(+), 41 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 8d169abe..2de39864 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,51 +1,35 @@ -# We only want to run this script manually. -on: workflow_dispatch +name: Azure Bicep + +on: + workflow_dispatch -# Environment variables are defined in an "env" section. -# We set the target environment to dev. -# Open the deploy-advanced.yml file to see how we can accept user input -# instead of needing to change this file to switch environments. env: targetEnv: dev -# The overall workflow name will be Azure Bicep. This will show up in the -# GitHub Action page. -name: Azure Bicep jobs: - # This script has one job: build and deploy the IaC resources build-and-deploy: - # We run this on an Ubuntu-based GitHub hosted runner. This hosted runner - # has certain software already installed, including az cli runs-on: ubuntu-latest + permissions: + contents: read + pages: write + id-token: write steps: - # Check out the code. This grabs code from the repository and - # makes it available to the GitHub hosted runner. It will usually be the - # first task for any workflow - - uses: actions/checkout@main + # Checkout code + - uses: actions/checkout@main - # Log into Azure using a federated credential. We have already set up the - # federation process in a prior step, so we need to pass in the following: - # Client ID = Application registration ID - # Tenant ID = Application owner organization ID (previously called Tenant ID in Azure) - # Subscription ID - # https://github.com/azure/login - - uses: azure/login@v2.1.1 - with: - client-id: $ - tenant-id: $ - subscription-id: $ - # We also need to ensure that enable-AzPSSession is true. This is important for - # using OIDC in Azure. If we were to pass in a client secret instead, we would not need - # this setting enabled - enable-AzPSSession: true + # Log into Azure + - uses: azure/login@v2.1.1 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + enable-AzPSSession: true - # Deploy ARM template - - name: Run ARM deploy - # https://github.com/azure/arm-deploy - uses: azure/arm-deploy@v1 - with: - subscriptionId: $ - resourceGroupName: $ - template: ./InfrastructureAsCode/main.bicep - # Use the environment variable called targetEnv - parameters: environment=$ + # Deploy ARM template + - name: Run ARM deploy + uses: azure/arm-deploy@v1 + with: + subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + resourceGroupName: ${{ secrets.AZURE_RG }} + template: ./src/InfrastructureAsCode/main.bicep + parameters: environment=${{ env.targetEnv }} From b1cf0ac01d8bbb177d0685cc85f4e73ab5156202 Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Tue, 29 Oct 2024 15:28:37 +0100 Subject: [PATCH 06/29] Update main.bicep with new resource definitions --- src/InfrastructureAsCode/main.bicep | 91 ++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 2 deletions(-) diff --git a/src/InfrastructureAsCode/main.bicep b/src/InfrastructureAsCode/main.bicep index 6dc69618..c84eb3f3 100644 --- a/src/InfrastructureAsCode/main.bicep +++ b/src/InfrastructureAsCode/main.bicep @@ -8,10 +8,97 @@ var webAppName = '${uniqueString(resourceGroup().id)}-${environment}' var appServicePlanName = '${uniqueString(resourceGroup().id)}-mpnp-asp' var logAnalyticsName = '${uniqueString(resourceGroup().id)}-mpnp-la' var appInsightsName = '${uniqueString(resourceGroup().id)}-mpnp-ai' -var sku = 'S1' +var sku = 'P0V3' var registryName = '${uniqueString(resourceGroup().id)}mpnpreg' var registrySku = 'Standard' var imageName = 'techexcel/dotnetcoreapp' var startupCommand = '' -// TODO: complete this script +resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2021-12-01-preview' = { + name: logAnalyticsName + location: location + properties: { + sku: { + name: 'PerGB2018' + } + retentionInDays: 90 + workspaceCapping: { + dailyQuotaGb: 1 + } + } +} + +resource appInsights 'Microsoft.Insights/components@2020-02-02-preview' = { + name: appInsightsName + location: location + kind: 'web' + properties: { + Application_Type: 'web' + WorkspaceResourceId: logAnalyticsWorkspace.id + } +} + +resource containerRegistry 'Microsoft.ContainerRegistry/registries@2020-11-01-preview' = { + name: registryName + location: location + sku: { + name: registrySku + } + properties: { + adminUserEnabled: true + } +} + +resource appServicePlan 'Microsoft.Web/serverFarms@2022-09-01' = { + name: appServicePlanName + location: location + kind: 'linux' + properties: { + reserved: true + } + sku: { + name: sku + } +} + +resource appServiceApp 'Microsoft.Web/sites@2020-12-01' = { + name: webAppName + location: location + properties: { + serverFarmId: appServicePlan.id + httpsOnly: true + clientAffinityEnabled: false + siteConfig: { + linuxFxVersion: 'DOCKER|${containerRegistry.name}.azurecr.io/${uniqueString(resourceGroup().id)}/${imageName}' + http20Enabled: true + minTlsVersion: '1.2' + appCommandLine: startupCommand + appSettings: [ + { + name: 'WEBSITES_ENABLE_APP_SERVICE_STORAGE' + value: 'false' + } + { + name: 'DOCKER_REGISTRY_SERVER_URL' + value: 'https://${containerRegistry.name}.azurecr.io' + } + { + name: 'DOCKER_REGISTRY_SERVER_USERNAME' + value: containerRegistry.name + } + { + name: 'DOCKER_REGISTRY_SERVER_PASSWORD' + value: containerRegistry.listCredentials().passwords[0].value + } + { + name: 'APPINSIGHTS_INSTRUMENTATIONKEY' + value: appInsights.properties.InstrumentationKey + } + ] + } + } +} + +output application_name string = appServiceApp.name +output application_url string = appServiceApp.properties.hostNames[0] +output container_registry_name string = containerRegistry.name From 3f4d21939a0fe0f18527be6db90dafaa79dc5be3 Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Tue, 29 Oct 2024 15:40:55 +0100 Subject: [PATCH 07/29] Refactor Azure Bicep deployment workflow --- .github/workflows/deploy.yml | 39 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2de39864..99bda891 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,10 +1,9 @@ name: Azure Bicep -on: - workflow_dispatch +on: workflow_dispatch env: - targetEnv: dev + targetEnv: test jobs: build-and-deploy: @@ -14,22 +13,22 @@ jobs: pages: write id-token: write steps: - # Checkout code - - uses: actions/checkout@main + # Checkout code + - uses: actions/checkout@main - # Log into Azure - - uses: azure/login@v2.1.1 - with: - client-id: ${{ secrets.AZURE_CLIENT_ID }} - tenant-id: ${{ secrets.AZURE_TENANT_ID }} - subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - enable-AzPSSession: true + # Log into Azure + - uses: azure/login@v2.1.1 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + enable-AzPSSession: true - # Deploy ARM template - - name: Run ARM deploy - uses: azure/arm-deploy@v1 - with: - subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - resourceGroupName: ${{ secrets.AZURE_RG }} - template: ./src/InfrastructureAsCode/main.bicep - parameters: environment=${{ env.targetEnv }} + # Deploy ARM template + - name: Run ARM deploy + uses: azure/arm-deploy@v1 + with: + subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + resourceGroupName: ${{ secrets.AZURE_RG }} + template: ./src/InfrastructureAsCode/main.bicep + parameters: environment=${{ env.targetEnv }} From ca8b1892e50b5032a0b7e15d27db464a3ef6f0d2 Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Tue, 29 Oct 2024 15:44:42 +0100 Subject: [PATCH 08/29] Update target environment to prod in deploy.yml --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 99bda891..4df4b838 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,7 +3,7 @@ name: Azure Bicep on: workflow_dispatch env: - targetEnv: test + targetEnv: prod jobs: build-and-deploy: From 6d72b8bee32ee70ad2c6f054e6911b73d3f0a63b Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Wed, 30 Oct 2024 10:23:32 +0100 Subject: [PATCH 09/29] Create dotnet-deployment.yml --- .github/workflows/dotnet-deployment.yml | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/dotnet-deployment.yml diff --git a/.github/workflows/dotnet-deployment.yml b/.github/workflows/dotnet-deployment.yml new file mode 100644 index 00000000..42928f8d --- /dev/null +++ b/.github/workflows/dotnet-deployment.yml @@ -0,0 +1,30 @@ +# This workflow will build a .NET project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net + +name: .NET + +on: + push: + branches: [ "main" ] + paths: src/Application/** + pull_request: + branches: [ "main" ] + paths: src/Application/** + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --no-restore + - name: Test + run: dotnet test --no-build --verbosity normal From b3e89a38c36c99984b4b09d07a2b907392cadaab Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Wed, 30 Oct 2024 10:31:31 +0100 Subject: [PATCH 10/29] Update dotnet-deployment.yml to specify project paths for restore, build, and test steps --- .github/workflows/dotnet-deployment.yml | 27 ++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/.github/workflows/dotnet-deployment.yml b/.github/workflows/dotnet-deployment.yml index 42928f8d..982dfbc0 100644 --- a/.github/workflows/dotnet-deployment.yml +++ b/.github/workflows/dotnet-deployment.yml @@ -5,26 +5,25 @@ name: .NET on: push: - branches: [ "main" ] + branches: ["main"] paths: src/Application/** pull_request: - branches: [ "main" ] + branches: ["main"] paths: src/Application/** jobs: build: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Setup .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: 8.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --no-restore - - name: Test - run: dotnet test --no-build --verbosity normal + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + - name: Restore dependencies + run: dotnet restore src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj + - name: Build + run: dotnet build --no-restore src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj + - name: Test + run: dotnet test --no-build --verbosity normal src/Application/tests/RazorPagesTestSample.Tests/RazorPagesTestSample.Tests.csproj From 5099c7b3fc5297a1a663613464b0e58aae63d184 Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Wed, 30 Oct 2024 10:34:26 +0100 Subject: [PATCH 11/29] Add Dockerfile for .NET 8 SDK and runtime setup --- src/Application/src/Dockerfile | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/Application/src/Dockerfile diff --git a/src/Application/src/Dockerfile b/src/Application/src/Dockerfile new file mode 100644 index 00000000..52e10376 --- /dev/null +++ b/src/Application/src/Dockerfile @@ -0,0 +1,27 @@ +# Use the official .NET 8 SDK image as a build stage +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build + +# Set the working directory +WORKDIR /app + +# Copy the project file and restore dependencies +COPY *.csproj ./ +RUN dotnet restore + +# Copy the rest of the application code +COPY . ./ + +# Build the application +RUN dotnet publish -c Release -o out + +# Use the official .NET 8 runtime image as a runtime stage +FROM mcr.microsoft.com/dotnet/aspnet:8.0 + +# Set the working directory +WORKDIR /app + +# Copy the built application from the build stage +COPY --from=build /app/out . + +# Set the entry point for the application +ENTRYPOINT ["dotnet", "RazorPagesTestSample.dll"] \ No newline at end of file From 36f5d327ed7a0a15583d98c1615f0024397cc8a9 Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Wed, 30 Oct 2024 10:36:17 +0100 Subject: [PATCH 12/29] Update error message for message length validation to reflect correct limit --- src/Application/src/RazorPagesTestSample/Data/Message.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application/src/RazorPagesTestSample/Data/Message.cs b/src/Application/src/RazorPagesTestSample/Data/Message.cs index 85cfc22e..1ddd7518 100644 --- a/src/Application/src/RazorPagesTestSample/Data/Message.cs +++ b/src/Application/src/RazorPagesTestSample/Data/Message.cs @@ -21,7 +21,7 @@ public class Message /// /// /// /// /// /// /// /// /// /// /// /// /// [Required] [DataType(DataType.Text)] - [StringLength(250, ErrorMessage = "There's a 200 character limit on messages. Please shorten your message.")] + [StringLength(250, ErrorMessage = "There's a 250 character limit on messages. Please shorten your message.")] public string Text { get; set; } } #endregion From edf5d705d4a750fb832e361e13bdbd30031ff074 Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Wed, 30 Oct 2024 10:53:19 +0100 Subject: [PATCH 13/29] Add Docker build and push steps to dotnet-deployment.yml --- .github/workflows/dotnet-deployment.yml | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/.github/workflows/dotnet-deployment.yml b/.github/workflows/dotnet-deployment.yml index 982dfbc0..4e07b52f 100644 --- a/.github/workflows/dotnet-deployment.yml +++ b/.github/workflows/dotnet-deployment.yml @@ -11,6 +11,12 @@ on: branches: ["main"] paths: src/Application/** +env: + registryName: kqrfo3r42nm3umpnpreg.azurecr.io + repositoryName: techexcel/dotnetcoreapp + dockerFolderPath: ./src/Application/src/RazorPagesTestSample + tag: ${{ github.run_number }} + jobs: build: runs-on: ubuntu-latest @@ -27,3 +33,30 @@ jobs: run: dotnet build --no-restore src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj - name: Test run: dotnet test --no-build --verbosity normal src/Application/tests/RazorPagesTestSample.Tests/RazorPagesTestSample.Tests.csproj + + dockerBuildPush: + runs-on: ubuntu-latest + needs: build + + steps: + - uses: actions/checkout@v3 + + - name: Docker Login + # You may pin to the exact commit or the version. + # uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c + uses: docker/login-action@v1.9.0 + with: + # Server address of Docker registry. If not set then will default to Docker Hub + registry: ${{ secrets.ACR_LOGIN_SERVER }} + # Username used to log against the Docker registry + username: ${{ secrets.ACR_USERNAME }} + # Password or personal access token used to log against the Docker registry + password: ${{ secrets.ACR_PASSWORD }} + # Log out from the Docker registry at the end of a job + logout: true + + - name: Docker Build + run: docker build -t $registryName/$repositoryName:$tag --build-arg build_version=$tag $dockerFolderPath + + - name: Docker Push + run: docker push $registryName/$repositoryName:$tag From 6021458fcf74ad1ffcec5b8e75e8243e865abb01 Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Wed, 30 Oct 2024 10:54:27 +0100 Subject: [PATCH 14/29] Fix typo in exception documentation for message length validation --- src/Application/src/RazorPagesTestSample/Data/Message.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application/src/RazorPagesTestSample/Data/Message.cs b/src/Application/src/RazorPagesTestSample/Data/Message.cs index 1ddd7518..9f331807 100644 --- a/src/Application/src/RazorPagesTestSample/Data/Message.cs +++ b/src/Application/src/RazorPagesTestSample/Data/Message.cs @@ -17,7 +17,7 @@ public class Message /// The text must be a valid string and is required. If the text exceeds 250 characters, an error message will be displayed. /// /// - /// Thrown when the text exceeds 250 characters or is not provided. + /// Thrown when the text exceeds 250 characters or is not provided. /// /// /// /// /// /// /// /// /// /// /// /// /// [Required] [DataType(DataType.Text)] From 074f51f1ecb6b6acff8045f7e7b544bc66161189 Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Wed, 30 Oct 2024 11:01:03 +0100 Subject: [PATCH 15/29] Replace Dockerfile in RazorPagesTestSample with a new build and runtime setup --- src/Application/src/{ => RazorPagesTestSample}/Dockerfile | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/Application/src/{ => RazorPagesTestSample}/Dockerfile (100%) diff --git a/src/Application/src/Dockerfile b/src/Application/src/RazorPagesTestSample/Dockerfile similarity index 100% rename from src/Application/src/Dockerfile rename to src/Application/src/RazorPagesTestSample/Dockerfile From 90aa71848b72f2dbe570f95a6346bddaee501d92 Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Wed, 30 Oct 2024 11:08:13 +0100 Subject: [PATCH 16/29] Add deployment job to Azure in dotnet-deployment.yml --- .github/workflows/dotnet-deployment.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/dotnet-deployment.yml b/.github/workflows/dotnet-deployment.yml index 4e07b52f..e13bd263 100644 --- a/.github/workflows/dotnet-deployment.yml +++ b/.github/workflows/dotnet-deployment.yml @@ -60,3 +60,21 @@ jobs: - name: Docker Push run: docker push $registryName/$repositoryName:$tag + + deploy-to-dev: + runs-on: ubuntu-latest + needs: dockerBuildPush + environment: + name: dev + url: https://MngEnvMCAP399752-dev.azurewebsites.net/ + + steps: + - name: "Login via Azure CLI" + uses: azure/login@v2.1.1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - uses: azure/webapps-deploy@v2 + with: + app-name: "MngEnvMCAP399752-dev" + images: $registryName/techexcel/dotnetcoreapp:${{github.run_number}} From 4864ff1ae955357f9f4541c36286a7719b157a03 Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Wed, 30 Oct 2024 11:09:16 +0100 Subject: [PATCH 17/29] Update panel titles and button formatting in Index.cshtml --- .../src/RazorPagesTestSample/Pages/Index.cshtml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml index f7645733..d9dc4ee3 100644 --- a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml +++ b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml @@ -12,7 +12,7 @@
-

Add a message

+

Add a new message

@@ -36,7 +36,8 @@
- +

Messages

@@ -44,7 +45,8 @@ @foreach (var message in Model.Messages) {
  • - + @message.Text
  • } @@ -66,7 +68,8 @@
    - +
    @Model.MessageAnalysisResult From 98b1e5b0ce36871834ab7a387fa5ca03ecca5234 Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Wed, 30 Oct 2024 11:13:48 +0100 Subject: [PATCH 18/29] Update Azure deployment configuration with new environment URL and app name --- .github/workflows/dotnet-deployment.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dotnet-deployment.yml b/.github/workflows/dotnet-deployment.yml index e13bd263..a94df7f7 100644 --- a/.github/workflows/dotnet-deployment.yml +++ b/.github/workflows/dotnet-deployment.yml @@ -66,7 +66,7 @@ jobs: needs: dockerBuildPush environment: name: dev - url: https://MngEnvMCAP399752-dev.azurewebsites.net/ + url: https://kqrfo3r42nm3u-dev.azurewebsites.net/ steps: - name: "Login via Azure CLI" @@ -76,5 +76,5 @@ jobs: - uses: azure/webapps-deploy@v2 with: - app-name: "MngEnvMCAP399752-dev" + app-name: "kqrfo3r42nm3u-dev" images: $registryName/techexcel/dotnetcoreapp:${{github.run_number}} From cbd0548bbec7d85816407c61e20938d3a61d9723 Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Wed, 30 Oct 2024 11:15:20 +0100 Subject: [PATCH 19/29] Update panel title in Index.cshtml for clarity --- src/Application/src/RazorPagesTestSample/Pages/Index.cshtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml index d9dc4ee3..b766490e 100644 --- a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml +++ b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml @@ -12,7 +12,7 @@
    -

    Add a new message

    +

    Add a message

    From bb853707461f9ed096208cf392944b1f862457b9 Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Wed, 30 Oct 2024 11:23:55 +0100 Subject: [PATCH 20/29] Add deployment jobs for test and production environments in dotnet-deployment.yml --- .github/workflows/dotnet-deployment.yml | 42 ++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dotnet-deployment.yml b/.github/workflows/dotnet-deployment.yml index a94df7f7..14327f51 100644 --- a/.github/workflows/dotnet-deployment.yml +++ b/.github/workflows/dotnet-deployment.yml @@ -77,4 +77,44 @@ jobs: - uses: azure/webapps-deploy@v2 with: app-name: "kqrfo3r42nm3u-dev" - images: $registryName/techexcel/dotnetcoreapp:${{github.run_number}} + images: kqrfo3r42nm3umpnpreg.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}} + + deploy-to-test: + runs-on: ubuntu-latest + needs: deploy-to-dev + environment: + name: test + url: https://kqrfo3r42nm3u-test.azurewebsites.net/ + + steps: + - uses: actions/checkout@v3 + + - name: "Login via Azure CLI" + uses: azure/login@v2.1.1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - uses: azure/webapps-deploy@v2 + with: + app-name: "kqrfo3r42nm3u-test" + images: kqrfo3r42nm3umpnpreg.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}} + + deploy-to-prod: + runs-on: ubuntu-latest + needs: deploy-to-test + environment: + name: prod + url: https://kqrfo3r42nm3u-prod.azurewebsites.net/ + + steps: + - uses: actions/checkout@v3 + + - name: "Login via Azure CLI" + uses: azure/login@v2.1.1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - uses: azure/webapps-deploy@v2 + with: + app-name: "kqrfo3r42nm3u-prod" + images: kqrfo3r42nm3umpnpreg.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}} From ba258357f9b7f17fb5e9bd8c6f7d0f705edb2276 Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Wed, 30 Oct 2024 11:24:15 +0100 Subject: [PATCH 21/29] Update button text in Index.cshtml for improved clarity --- src/Application/src/RazorPagesTestSample/Pages/Index.cshtml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml index b766490e..97d56de4 100644 --- a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml +++ b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml @@ -21,7 +21,8 @@
    - +
    From 6b8a2ebea3199db030d120ea4a5ad7ab06b9bf73 Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Wed, 30 Oct 2024 11:30:43 +0100 Subject: [PATCH 22/29] Add environment variables for Docker deployment in dotnet-deployment.yml --- .github/workflows/dotnet-deployment.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/dotnet-deployment.yml b/.github/workflows/dotnet-deployment.yml index 14327f51..9bba913f 100644 --- a/.github/workflows/dotnet-deployment.yml +++ b/.github/workflows/dotnet-deployment.yml @@ -3,6 +3,12 @@ name: .NET +env: + registryName: kqrfo3r42nm3umpnpreg.azurecr.io + repositoryName: techexcel/dotnetcoreapp + dockerFolderPath: ./src/Application/src/RazorPagesTestSample + tag: ${{ github.run_number }} + on: push: branches: ["main"] @@ -10,12 +16,8 @@ on: pull_request: branches: ["main"] paths: src/Application/** - -env: - registryName: kqrfo3r42nm3umpnpreg.azurecr.io - repositoryName: techexcel/dotnetcoreapp - dockerFolderPath: ./src/Application/src/RazorPagesTestSample - tag: ${{ github.run_number }} + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: jobs: build: From ab1b16e5ba05d45e852934fb3ef5e70fd84de3c8 Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Wed, 30 Oct 2024 11:31:37 +0100 Subject: [PATCH 23/29] Update button text in Index.cshtml for brevity --- src/Application/src/RazorPagesTestSample/Pages/Index.cshtml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml index 97d56de4..b766490e 100644 --- a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml +++ b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml @@ -21,8 +21,7 @@
    - +
    From 7294f1faf29d1adabd1c9b1d076969b4327efdd9 Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Wed, 30 Oct 2024 11:39:33 +0100 Subject: [PATCH 24/29] Add GitHub Actions script to notify on workflow failure --- .github/workflows/dotnet-deployment.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/dotnet-deployment.yml b/.github/workflows/dotnet-deployment.yml index 9bba913f..a4d2dbcc 100644 --- a/.github/workflows/dotnet-deployment.yml +++ b/.github/workflows/dotnet-deployment.yml @@ -35,6 +35,18 @@ jobs: run: dotnet build --no-restore src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj - name: Test run: dotnet test --no-build --verbosity normal src/Application/tests/RazorPagesTestSample.Tests/RazorPagesTestSample.Tests.csproj + - uses: actions/github-script@v6 + if: failure() + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + let body = "${{ env.build_name }} Workflow Failure \n Build Number: ${{ github.run_number }} \n Build Log: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} \n SHA: [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) \n"; + github.issues.create({ + owner: context.repo.owner, + repo: context.repo.repo, + title: "${{ env.build_name }} Workflow ${{ github.run_number }} Failed! ", + body: body + }); dockerBuildPush: runs-on: ubuntu-latest From 3b4c0d77786092c18bc71caabbdf0289ad33bfe2 Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Wed, 30 Oct 2024 12:18:08 +0100 Subject: [PATCH 25/29] Update button text in Index.cshtml for improved clarity --- src/Application/src/RazorPagesTestSample/Pages/Index.cshtml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml index b766490e..e9754d94 100644 --- a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml +++ b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml @@ -21,7 +21,8 @@
    - +
    From b7b8f77558b60bac4c8bbadf7bf4470c7c7d8645 Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Wed, 30 Oct 2024 12:21:35 +0100 Subject: [PATCH 26/29] Add CODEOWNERS file to specify repository ownership --- src/CODEOWNERS | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/CODEOWNERS diff --git a/src/CODEOWNERS b/src/CODEOWNERS new file mode 100644 index 00000000..9cece6fa --- /dev/null +++ b/src/CODEOWNERS @@ -0,0 +1,7 @@ +# Code owners for the repository + +- @sven-pohl + +# Specify sven-pohl as the owner for the /src/Application/ directory + +/Application/ @sven-pohl From d437864af870e1e5dfe7b06759bad2481dab014c Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Wed, 30 Oct 2024 12:51:13 +0100 Subject: [PATCH 27/29] Update button text in Index.cshtml for brevity --- src/Application/src/RazorPagesTestSample/Pages/Index.cshtml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml index e9754d94..b766490e 100644 --- a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml +++ b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml @@ -21,8 +21,7 @@
    - +
    From 0d73d328e1e4a4b7525f272b056f947228b06b8d Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Wed, 30 Oct 2024 12:57:40 +0100 Subject: [PATCH 28/29] Update CODEOWNERS to include additional owner for clarity --- src/CODEOWNERS | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CODEOWNERS b/src/CODEOWNERS index 9cece6fa..465ede2c 100644 --- a/src/CODEOWNERS +++ b/src/CODEOWNERS @@ -1,7 +1,7 @@ # Code owners for the repository -- @sven-pohl +* @sven-pohl @svpohl # Specify sven-pohl as the owner for the /src/Application/ directory -/Application/ @sven-pohl +/Application/ @sven-pohl @svpohl From 05bdda9e0bf62a2b4dc868014c32763a508c880c Mon Sep 17 00:00:00 2001 From: Sven Pohl Date: Wed, 30 Oct 2024 13:10:01 +0100 Subject: [PATCH 29/29] Update panel title in Index.cshtml for improved clarity --- src/Application/src/RazorPagesTestSample/Pages/Index.cshtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml index b766490e..d9dc4ee3 100644 --- a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml +++ b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml @@ -12,7 +12,7 @@
    -

    Add a message

    +

    Add a new message