From 990c8212250b4205540bf44f462843973fbbaf45 Mon Sep 17 00:00:00 2001 From: Frederic Wickert <11938627+fwickert@users.noreply.github.com> Date: Tue, 29 Oct 2024 12:03:11 +0100 Subject: [PATCH 01/22] 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 bb51638b926239fe1246ccb2217e1216b0da35d8 Mon Sep 17 00:00:00 2001 From: Frederic Wickert Date: Tue, 29 Oct 2024 12:21:15 +0100 Subject: [PATCH 02/22] WF --- docs/.github/workflows/first-workflow.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 docs/.github/workflows/first-workflow.yml diff --git a/docs/.github/workflows/first-workflow.yml b/docs/.github/workflows/first-workflow.yml new file mode 100644 index 00000000..48b1fd5d --- /dev/null +++ b/docs/.github/workflows/first-workflow.yml @@ -0,0 +1,22 @@ +name: First Workflow + +on: + workflow_dispatch: + +jobs: + job1: + runs-on: ubuntu-latest + steps: + - name: Echo Step 1 + run: echo "This is Step 1" + - name: Echo Step 2 + run: echo "This is Step 2" + + job2: + runs-on: ubuntu-latest + steps: + - name: Cowsays + uses: mscoutermarsh/cowsays-action@master + with: + text: "Ready for prod LOL" + color: "mangenta" \ No newline at end of file From 434360b00f7c85dfd0d0741a11440809d1413ef5 Mon Sep 17 00:00:00 2001 From: Frederic Wickert <11938627+fwickert@users.noreply.github.com> Date: Tue, 29 Oct 2024 12:25:19 +0100 Subject: [PATCH 03/22] Create firstWF.yml --- .github/workflows/firstWF.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/firstWF.yml diff --git a/.github/workflows/firstWF.yml b/.github/workflows/firstWF.yml new file mode 100644 index 00000000..1929003a --- /dev/null +++ b/.github/workflows/firstWF.yml @@ -0,0 +1,22 @@ +name: First Workflow + +on: + workflow_dispatch: + +jobs: + job1: + runs-on: ubuntu-latest + steps: + - name: Echo Step 1 + run: echo "This is Step 1" + - name: Echo Step 2 + run: echo "This is Step 2" + + job2: + runs-on: ubuntu-latest + steps: + - name: Cowsays + uses: mscoutermarsh/cowsays-action@master + with: + text: "Ready for prod LOL" + color: "mangenta" From bf501970f7248893218f1228109c44568781959c Mon Sep 17 00:00:00 2001 From: Frederic Wickert <11938627+fwickert@users.noreply.github.com> Date: Tue, 29 Oct 2024 13:12:17 +0100 Subject: [PATCH 04/22] Update firstWF.yml --- .github/workflows/firstWF.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/firstWF.yml b/.github/workflows/firstWF.yml index 1929003a..6c078b3d 100644 --- a/.github/workflows/firstWF.yml +++ b/.github/workflows/firstWF.yml @@ -1,7 +1,7 @@ name: First Workflow on: - workflow_dispatch: + issues: jobs: job1: From ed5103145461f3e3c8c3e2a43153049ceba876de Mon Sep 17 00:00:00 2001 From: Frederic Wickert Date: Tue, 29 Oct 2024 13:22:47 +0100 Subject: [PATCH 05/22] resolves #3 --- .../src/RazorPagesTestSample/Data/Message.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Application/src/RazorPagesTestSample/Data/Message.cs b/src/Application/src/RazorPagesTestSample/Data/Message.cs index ea99cbd6..c50cf088 100644 --- a/src/Application/src/RazorPagesTestSample/Data/Message.cs +++ b/src/Application/src/RazorPagesTestSample/Data/Message.cs @@ -7,9 +7,19 @@ public class Message { public int Id { get; set; } + /// + /// Gets or sets the text of the message. + /// + /// + /// The text content of the message, limited to 250 characters. + /// + /// + /// This property is required and must be a text data type. If the text exceeds 250 characters, + /// an error message will be displayed indicating the character limit. + /// [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 250 character limit on messages. Please shorten your message.")] public string Text { get; set; } } #endregion From 4d6bd3e7a545c0c6502bd09fa3a90901c304ca79 Mon Sep 17 00:00:00 2001 From: Frederic Wickert Date: Tue, 29 Oct 2024 13:54:55 +0100 Subject: [PATCH 06/22] Ex 3.2 --- src/InfrastructureAsCode/credentials.json | 9 +++ src/InfrastructureAsCode/deploy.yml | 35 +++++++++ src/InfrastructureAsCode/main.bicep | 92 ++++++++++++++++++++++- 3 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 src/InfrastructureAsCode/credentials.json create mode 100644 src/InfrastructureAsCode/deploy.yml diff --git a/src/InfrastructureAsCode/credentials.json b/src/InfrastructureAsCode/credentials.json new file mode 100644 index 00000000..dff1f597 --- /dev/null +++ b/src/InfrastructureAsCode/credentials.json @@ -0,0 +1,9 @@ +{ + "name": "GitHubDevOpsCredential", + "issuer": "https://token.actions.githubusercontent.com", + "subject": "repo:fwickert/TechExcel-Accelerate-developer-productivity-with-GitHub-Copilot-and-Dev-Box", + "description": "Deploy Azure resources from the TechExcel DevOps practices GitHub repo", + "audiences": [ + "api://AzureADTokenExchange" + ] +} diff --git a/src/InfrastructureAsCode/deploy.yml b/src/InfrastructureAsCode/deploy.yml new file mode 100644 index 00000000..fb6905d0 --- /dev/null +++ b/src/InfrastructureAsCode/deploy.yml @@ -0,0 +1,35 @@ +name: Azure Bicep + +on: + workflow_dispatch + +env: + targetEnv: dev + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + permissions: + contents: read + pages: write + id-token: write + steps: + # 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 + + # 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 }} \ No newline at end of file diff --git a/src/InfrastructureAsCode/main.bicep b/src/InfrastructureAsCode/main.bicep index 6dc69618..d8e740d2 100644 --- a/src/InfrastructureAsCode/main.bicep +++ b/src/InfrastructureAsCode/main.bicep @@ -8,10 +8,98 @@ 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 bd19f467688c5d8aed712a109cf8c9926a6af268 Mon Sep 17 00:00:00 2001 From: Frederic Wickert Date: Tue, 29 Oct 2024 13:57:31 +0100 Subject: [PATCH 07/22] update WF path --- .../workflows}/deploy.yml | 0 docs/.github/workflows/first-workflow.yml | 22 ------------------- 2 files changed, 22 deletions(-) rename {src/InfrastructureAsCode => .github/workflows}/deploy.yml (100%) delete mode 100644 docs/.github/workflows/first-workflow.yml diff --git a/src/InfrastructureAsCode/deploy.yml b/.github/workflows/deploy.yml similarity index 100% rename from src/InfrastructureAsCode/deploy.yml rename to .github/workflows/deploy.yml diff --git a/docs/.github/workflows/first-workflow.yml b/docs/.github/workflows/first-workflow.yml deleted file mode 100644 index 48b1fd5d..00000000 --- a/docs/.github/workflows/first-workflow.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: First Workflow - -on: - workflow_dispatch: - -jobs: - job1: - runs-on: ubuntu-latest - steps: - - name: Echo Step 1 - run: echo "This is Step 1" - - name: Echo Step 2 - run: echo "This is Step 2" - - job2: - runs-on: ubuntu-latest - steps: - - name: Cowsays - uses: mscoutermarsh/cowsays-action@master - with: - text: "Ready for prod LOL" - color: "mangenta" \ No newline at end of file From 4a60981d2f6f9a65f31a4a416f7c20e103cbf81f Mon Sep 17 00:00:00 2001 From: Frederic Wickert <11938627+fwickert@users.noreply.github.com> Date: Tue, 29 Oct 2024 14:30:09 +0100 Subject: [PATCH 08/22] Create dotnet.yml --- .github/workflows/dotnet.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/dotnet.yml diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml new file mode 100644 index 00000000..3e77d999 --- /dev/null +++ b/.github/workflows/dotnet.yml @@ -0,0 +1,29 @@ +# 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/** + + workflow_dispatch: +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 ./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 cc1694f1d4a1cf7689ef711501dfa9d252689db5 Mon Sep 17 00:00:00 2001 From: Frederic Wickert Date: Tue, 29 Oct 2024 14:34:31 +0100 Subject: [PATCH 09/22] docker --- .../src/RazorPagesTestSample/dockerfile | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/Application/src/RazorPagesTestSample/dockerfile diff --git a/src/Application/src/RazorPagesTestSample/dockerfile b/src/Application/src/RazorPagesTestSample/dockerfile new file mode 100644 index 00000000..ab3fcaf2 --- /dev/null +++ b/src/Application/src/RazorPagesTestSample/dockerfile @@ -0,0 +1,18 @@ +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env +WORKDIR /app + +# Copy csproj and restore as distinct layers +COPY *.csproj ./ +RUN dotnet restore + +# Copy everything else and build +COPY . ./ +RUN dotnet publish -c Release -o out + +# Build runtime image +FROM mcr.microsoft.com/dotnet/aspnet:8.0 +WORKDIR /app +COPY --from=build-env /app/out . +# Default ASP.NET port changed with .NET 8.0 +ENV ASPNETCORE_HTTP_PORTS=80 +ENTRYPOINT ["dotnet", "RazorPagesTestSample.dll"] \ No newline at end of file From 1bcdd931026358f048f3befd81db0f4e3fa118c0 Mon Sep 17 00:00:00 2001 From: Frederic Wickert Date: Tue, 29 Oct 2024 14:40:17 +0100 Subject: [PATCH 10/22] Docker build push --- .github/workflows/deploy.yml | 82 ++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 27 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index fb6905d0..57603721 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,35 +1,63 @@ -name: Azure Bicep - -on: - workflow_dispatch +name: .NET CI env: - targetEnv: dev - + registryName: p5tgcusa4unsumpnpreg.azurecr.io + repositoryName: techexcel/dotnetcoreapp + dockerFolderPath: ./src/Application/src/RazorPagesTestSample + tag: ${{github.run_number}} + +on: + push: + branches: [ main ] + paths: src/Application/** + pull_request: + branches: [ main ] + paths: src/Application/** + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: jobs: - build-and-deploy: + build: + runs-on: ubuntu-latest - permissions: - contents: read - pages: write - id-token: write - steps: - # Checkout code - - uses: actions/checkout@main - # Log into Azure - - uses: azure/login@v2.1.1 + steps: + - uses: actions/checkout@v3 + - name: Setup .NET + uses: actions/setup-dotnet@v3 with: - client-id: ${{ secrets.AZURE_CLIENT_ID }} - tenant-id: ${{ secrets.AZURE_TENANT_ID }} - subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - enable-AzPSSession: true + dotnet-version: 8.0 + + - 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 + + dockerBuildPush: + + runs-on: ubuntu-latest + needs: build - # Deploy ARM template - - name: Run ARM deploy - uses: azure/arm-deploy@v1 + 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: - subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - resourceGroupName: ${{ secrets.AZURE_RG }} - template: ./src/InfrastructureAsCode/main.bicep - parameters: environment=${{ env.targetEnv }} \ No newline at end of file + # 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 16e3ed6b5e99b3b0ad43b10d143604b0e32fc327 Mon Sep 17 00:00:00 2001 From: Frederic Wickert Date: Tue, 29 Oct 2024 14:41:27 +0100 Subject: [PATCH 11/22] test --- src/Application/src/RazorPagesTestSample/Data/Message.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Application/src/RazorPagesTestSample/Data/Message.cs b/src/Application/src/RazorPagesTestSample/Data/Message.cs index c50cf088..08a8b2e5 100644 --- a/src/Application/src/RazorPagesTestSample/Data/Message.cs +++ b/src/Application/src/RazorPagesTestSample/Data/Message.cs @@ -22,5 +22,7 @@ public class Message [StringLength(250, ErrorMessage = "There's a 250 character limit on messages. Please shorten your message.")] public string Text { get; set; } } + + //comment for test #endregion } From 7e693cdcfbb26e63158ebcb152a7c54b1f78512c Mon Sep 17 00:00:00 2001 From: Frederic Wickert Date: Tue, 29 Oct 2024 14:48:47 +0100 Subject: [PATCH 12/22] Docker to deploy --- .github/workflows/deploy.yml | 64 ++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 57603721..a013b9a7 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -5,7 +5,7 @@ env: repositoryName: techexcel/dotnetcoreapp dockerFolderPath: ./src/Application/src/RazorPagesTestSample tag: ${{github.run_number}} - + on: push: branches: [ main ] @@ -35,7 +35,6 @@ jobs: run: dotnet test --no-build --verbosity normal ./src/Application/tests/RazorPagesTestSample.Tests/RazorPagesTestSample.Tests.csproj dockerBuildPush: - runs-on: ubuntu-latest needs: build @@ -61,3 +60,64 @@ jobs: - name: Docker Push run: docker push $registryName/$repositoryName:$tag + + deploy-to-dev: + + runs-on: ubuntu-latest + needs: dockerBuildPush + environment: + name: dev + url: https://p5tgcusa4unsu-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: 'p5tgcusa4unsu-dev' + images: p5tgcusa4unsumpnpreg.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}} + + deploy-to-test: + + runs-on: ubuntu-latest + needs: deploy-to-dev + environment: + name: test + url: https://p5tgcusa4unsu-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: 'p5tgcusa4unsu-test' + images: p5tgcusa4unsumpnpreg.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}} + + deploy-to-prod: + + runs-on: ubuntu-latest + needs: deploy-to-test + environment: + name: prod + url: https://p5tgcusa4unsu-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: 'p5tgcusa4unsu-prod' + images: p5tgcusa4unsumpnpreg.azurecr.io /techexcel/dotnetcoreapp:${{github.run_number}} From a2f9c05da1095a730d99d0be44553ead09e3caa6 Mon Sep 17 00:00:00 2001 From: Frederic Wickert Date: Tue, 29 Oct 2024 14:49:12 +0100 Subject: [PATCH 13/22] change for test --- src/Application/src/RazorPagesTestSample/Data/Message.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Application/src/RazorPagesTestSample/Data/Message.cs b/src/Application/src/RazorPagesTestSample/Data/Message.cs index 08a8b2e5..03683d17 100644 --- a/src/Application/src/RazorPagesTestSample/Data/Message.cs +++ b/src/Application/src/RazorPagesTestSample/Data/Message.cs @@ -21,8 +21,6 @@ public class Message [DataType(DataType.Text)] [StringLength(250, ErrorMessage = "There's a 250 character limit on messages. Please shorten your message.")] public string Text { get; set; } - } - - //comment for test + } #endregion } From 62f8f6151e2804aa01d9352e66e8133f1bb6e0d2 Mon Sep 17 00:00:00 2001 From: Frederic Wickert <11938627+fwickert@users.noreply.github.com> Date: Wed, 30 Oct 2024 09:19:40 +0100 Subject: [PATCH 14/22] Create CODEOWNERS --- CODEOWNERS | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 CODEOWNERS diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 00000000..1cb0c9f8 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,6 @@ +# CODEOWNERS file +# This file designates code owners for specific directories or files +* @fwickert + +# fwickert owns the /src/Application/ directory +/src/Application/ @fwickert From b4d11cb04b0dfdc616e66807f6a71a7669f88d48 Mon Sep 17 00:00:00 2001 From: Frederic Wickert <11938627+fwickert@users.noreply.github.com> Date: Wed, 30 Oct 2024 09:22:12 +0100 Subject: [PATCH 15/22] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 21027307..712bb84b 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,5 @@ trademarks or logos is subject to and must follow [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/legal/intellectualproperty/trademarks/usage/general). Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies. + +Update for testing From 3bb1b417f1efea4c54a271635bfca904771a766a Mon Sep 17 00:00:00 2001 From: Frederic Wickert Date: Wed, 30 Oct 2024 10:22:30 +0100 Subject: [PATCH 16/22] Fix issue with prod deployment --- .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 a013b9a7..3bdfe2f2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -120,4 +120,4 @@ jobs: - uses: azure/webapps-deploy@v2 with: app-name: 'p5tgcusa4unsu-prod' - images: p5tgcusa4unsumpnpreg.azurecr.io /techexcel/dotnetcoreapp:${{github.run_number}} + images: p5tgcusa4unsumpnpreg.azurecr.io/techexcel/dotnetcoreapp:${{github.run_number}} From 0bcf77e51b2eb3c2d2091dbdeba1375bc6b3090a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 30 Oct 2024 09:32:45 +0000 Subject: [PATCH 17/22] Bump rexml from 3.3.6 to 3.3.9 Bumps [rexml](https://github.com/ruby/rexml) from 3.3.6 to 3.3.9. - [Release notes](https://github.com/ruby/rexml/releases) - [Changelog](https://github.com/ruby/rexml/blob/master/NEWS.md) - [Commits](https://github.com/ruby/rexml/compare/v3.3.6...v3.3.9) --- updated-dependencies: - dependency-name: rexml dependency-type: indirect ... Signed-off-by: dependabot[bot] --- Gemfile.lock | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 045212ad..492a25c2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -56,13 +56,11 @@ GEM rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) - rexml (3.3.6) - strscan + rexml (3.3.9) rouge (4.0.0) safe_yaml (1.0.5) sassc (2.4.0) ffi (~> 1.9) - strscan (3.1.0) terminal-table (3.0.2) unicode-display_width (>= 1.1.1, < 3) unicode-display_width (2.3.0) From 93fa64f53fc2370194a3e915154f11d7f5fb6ece Mon Sep 17 00:00:00 2001 From: Frederic Wickert Date: Wed, 30 Oct 2024 10:38:17 +0100 Subject: [PATCH 18/22] Revise SECURITY.md to reflect updated reporting procedures and remove Microsoft-specific content --- SECURITY.md | 41 +++++++---------------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index b3c89efc..e9bcae74 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -1,41 +1,14 @@ - +# Reporting Security Issues -## Security +Munson’s Pickles and Preserves team and community take security bugs in Team Messaging System seriously. We appreciate your efforts to responsibly disclose your findings, and will make every effort to acknowledge your contributions. -Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet) and [Xamarin](https://github.com/xamarin). +To report a security issue, please use the GitHub Security Advisory ["Report a Vulnerability"](https://github.com/fwickert/TechExcel-Accelerate-developer-productivity-with-GitHub-Copilot-and-Dev-Box/security/advisories/new) tab. -If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/security.md/definition), please report it to us as described below. +The Munson’s Pickles and Preserves team will send a response indicating the next steps in handling your report. After the initial reply to your report, the security team will keep you informed of the progress towards a fix and full announcement, and may ask for additional information or guidance. -## Reporting Security Issues +Report security bugs in third-party modules to the person or team maintaining the module. You can also report a vulnerability through the [npm contact form](https://www.npmjs.com/support) by selecting "I'm reporting a security vulnerability". -**Please do not report security vulnerabilities through public GitHub issues.** -Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/security.md/msrc/create-report). +## Learning More About Security -If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/security.md/msrc/pgp). - -You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc). - -Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: - - * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) - * Full paths of source file(s) related to the manifestation of the issue - * The location of the affected source code (tag/branch/commit or direct URL) - * Any special configuration required to reproduce the issue - * Step-by-step instructions to reproduce the issue - * Proof-of-concept or exploit code (if possible) - * Impact of the issue, including how an attacker might exploit the issue - -This information will help us triage your report more quickly. - -If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/security.md/msrc/bounty) page for more details about our active programs. - -## Preferred Languages - -We prefer all communications to be in English. - -## Policy - -Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/security.md/cvd). - - +To learn more about securing an Electron application, please see the [security tutorial](docs/tutorial/security.md). \ No newline at end of file From 2c1d071a547595f6d0b04a93ebc9463bbb668223 Mon Sep 17 00:00:00 2001 From: Frederic Wickert <11938627+fwickert@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:40:46 +0100 Subject: [PATCH 19/22] Create codeql.yml --- .github/workflows/codeql.yml | 94 ++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 00000000..b99a7c37 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,94 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL Advanced" + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + schedule: + - cron: '42 17 * * 2' + +jobs: + analyze: + name: Analyze (${{ matrix.language }}) + # Runner size impacts CodeQL analysis time. To learn more, please see: + # - https://gh.io/recommended-hardware-resources-for-running-codeql + # - https://gh.io/supported-runners-and-hardware-resources + # - https://gh.io/using-larger-runners (GitHub.com only) + # Consider using larger runners or machines with greater resources for possible analysis time improvements. + runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} + permissions: + # required for all workflows + security-events: write + + # required to fetch internal or private CodeQL packs + packages: read + + # only required for workflows in private repositories + actions: read + contents: read + + strategy: + fail-fast: false + matrix: + include: + - language: csharp + build-mode: none + - language: ruby + build-mode: none + # CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' + # Use `c-cpp` to analyze code written in C, C++ or both + # Use 'java-kotlin' to analyze code written in Java, Kotlin or both + # Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both + # To learn more about changing the languages that are analyzed or customizing the build mode for your analysis, + # see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning. + # If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how + # your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + build-mode: ${{ matrix.build-mode }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + # If the analyze step fails for one of the languages you are analyzing with + # "We were unable to automatically build your code", modify the matrix above + # to set the build mode to "manual" for that language. Then modify this step + # to build your code. + # ℹ️ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + - if: matrix.build-mode == 'manual' + shell: bash + run: | + echo 'If you are using a "manual" build mode for one or more of the' \ + 'languages you are analyzing, replace this with the commands to build' \ + 'your code, for example:' + echo ' make bootstrap' + echo ' make release' + exit 1 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:${{matrix.language}}" From 68f137ebb01d92a6d21baeab7564f421661d4d4e Mon Sep 17 00:00:00 2001 From: Frederic Wickert Date: Wed, 30 Oct 2024 11:05:48 +0100 Subject: [PATCH 20/22] Update .gitignore, enhance file extraction safety, and upgrade Newtonsoft.Json package --- .gitignore | 4 ++++ .../src/RazorPagesTestSample/Pages/Index.cshtml.cs | 8 +++++++- src/Application/src/RazorPagesTestSample/config.json | 4 ---- .../RazorPagesTestSample.Tests.csproj | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) delete mode 100644 src/Application/src/RazorPagesTestSample/config.json diff --git a/.gitignore b/.gitignore index 9bea4330..d66e1761 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ .DS_Store + + # Local configuration file for developers + src/Application/src/RazorPagesTestSample/config.json + diff --git a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml.cs b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml.cs index 2e6d94bb..c17e08dc 100644 --- a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml.cs +++ b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml.cs @@ -94,7 +94,13 @@ public async Task OnPostAnalyzeMessagesAsync() public static void WriteToDirectory(ZipArchiveEntry entry, string destDirectory) { - string destFileName = Path.Combine(destDirectory, entry.FullName); + string destFileName = Path.GetFullPath(Path.Combine(destDirectory, entry.FullName)); + + if (!destFileName.StartsWith(destDirectory, StringComparison.OrdinalIgnoreCase)) + { + throw new InvalidOperationException("Entry is outside of the target directory."); + } + entry.ExtractToFile(destFileName); } } diff --git a/src/Application/src/RazorPagesTestSample/config.json b/src/Application/src/RazorPagesTestSample/config.json deleted file mode 100644 index 1a3874d4..00000000 --- a/src/Application/src/RazorPagesTestSample/config.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "registry_key": "8yYKDsFTjatiQI9nVcsoQ1P3rdnh+P5Mlz9gVBgVgx+ACRArmBQ3", - "registry_type": "AzureContainerRegistry" -} \ No newline at end of file diff --git a/src/Application/tests/RazorPagesTestSample.Tests/RazorPagesTestSample.Tests.csproj b/src/Application/tests/RazorPagesTestSample.Tests/RazorPagesTestSample.Tests.csproj index a66e0a92..a0f5f511 100644 --- a/src/Application/tests/RazorPagesTestSample.Tests/RazorPagesTestSample.Tests.csproj +++ b/src/Application/tests/RazorPagesTestSample.Tests/RazorPagesTestSample.Tests.csproj @@ -13,7 +13,7 @@ - + From 55e92ff3f52af728a1ecc91ce696bc3461268ecf Mon Sep 17 00:00:00 2001 From: Frederic Wickert Date: Wed, 30 Oct 2024 12:07:29 +0100 Subject: [PATCH 21/22] Refactor word count calculation for improved performance and readability --- .../src/RazorPagesTestSample/Pages/Index.cshtml.cs | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml.cs b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml.cs index c17e08dc..b8011e52 100644 --- a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml.cs +++ b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml.cs @@ -72,19 +72,7 @@ public async Task OnPostAnalyzeMessagesAsync() } else { - // Speed loop. Lower this number once every quarter so we - // get our performance improvement quarterly bonus. - for (int i = 0; i < 3000; i++) { - Thread.Sleep(1); - } - - var wordCount = 0; - - foreach (var message in Messages) - { - wordCount += message.Text.Split(' ').Length; - } - + var wordCount = Messages.Sum(message => message.Text.Split(' ').Length); var avgWordCount = Decimal.Divide(wordCount, Messages.Count); MessageAnalysisResult = $"The average message length is {avgWordCount:0.##} words."; } From 0a0c3699a2a561fe6793786ca9bec86fce842e8a Mon Sep 17 00:00:00 2001 From: Frederic Wickert Date: Wed, 30 Oct 2024 12:55:28 +0100 Subject: [PATCH 22/22] Add missing using directive for System.Linq in Index.cshtml.cs --- src/Application/src/RazorPagesTestSample/Pages/Index.cshtml.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml.cs b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml.cs index b8011e52..8017d6dd 100644 --- a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml.cs +++ b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml.cs @@ -7,6 +7,7 @@ using System.Threading; using System.IO; using System.IO.Compression; +using System.Linq; namespace RazorPagesTestSample.Pages {