diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index aaebc05..eb5cc23 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -2,7 +2,7 @@ # [Choice] .NET version: 6.0, 5.0, 3.1, 6.0-bullseye, 5.0-bullseye, 3.1-bullseye, 6.0-focal, 5.0-focal, 3.1-focal ARG VARIANT="6.0-bullseye-slim" -FROM mcr.microsoft.com/vscode/devcontainers/dotnet:0-${VARIANT} +FROM mcr.microsoft.com/devcontainers/dotnet:${VARIANT} # [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 ARG NODE_VERSION="none" diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 1e2ae76..cedd39a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -7,7 +7,7 @@ "args": { // Update 'VARIANT' to pick a .NET Core version: 3.1, 5.0, 6.0 // Append -bullseye or -focal to pin to an OS version. - "VARIANT": "7.0", + "VARIANT": "8.0-jammy", // Options "NODE_VERSION": "lts/*" } @@ -17,7 +17,7 @@ "version": "latest" }, "ghcr.io/devcontainers/features/dotnet": { - "version": "7.0", + "version": "8.0", "additionalVersions": "6.0", "runtimeOnly": false }, @@ -47,7 +47,10 @@ "cschleiden.vscode-github-actions", "ms-azure-devops.azure-pipelines", "github.vscode-github-actions", - "ms-vscode.powershell" + "ms-vscode.powershell", + "ms-dotnettools.csdevkit", + "ms-dotnettools.vscodeintellicode-csharp", + "chneau.resource-monitor" ] } }, diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 24d07ec..c827c6c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,10 +17,13 @@ jobs: - uses: actions/checkout@v2 with: submodules: true + - uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.0.x' - name: Publish Frontend run: dotnet publish -c Release ./src/CZ.Azure.FileExchange/ -o temp/frontend - name: Publish API - run: dotnet publish -c Release ./src/CZ.Azure.FileExchange.Api/ -o temp/api --runtime win-x86 --no-self-contained + run: dotnet publish -c Release ./src/CZ.Azure.FileExchange.Api/ -o temp/api --runtime win-x86 --self-contained - name: zip outputs shell: pwsh run: | @@ -110,5 +113,5 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} continue-on-error: true - name: Deploy - run: './build/deploy.ps1 -Token ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_KINDDUNE004C2C103 }} -appBuildOutput ./temp/frontend/wwwroot/ -apiBuildOutput ./temp/api/ -envrionmentName ${{ github.event.number }} -pullrequestTitle "${{steps.Pr-Title.outputs.pr-title}}" -branchName ${{ github.head_ref }} -apiFramework "dotnetisolated" -apiFrameworkVersion "7.0" -Verbose -Delete' - shell: pwsh \ No newline at end of file + run: './build/deploy.ps1 -Token ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_KINDDUNE004C2C103 }} -appBuildOutput ./temp/frontend/wwwroot/ -apiBuildOutput ./temp/api/ -envrionmentName ${{ github.event.number }} -pullrequestTitle "${{steps.Pr-Title.outputs.pr-title}}" -branchName ${{ github.head_ref }} -apiFramework "dotnetisolated" -apiFrameworkVersion "8.0" -Verbose -Delete' + shell: pwsh diff --git a/.vscode/settings.json b/.vscode/settings.json index cc25882..0298f5f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,6 @@ { "azureFunctions.projectSubpath": "src/CZ.Azure.FileExchange.Api", - "azureFunctions.deploySubpath": "src/CZ.Azure.FileExchange.Api/bin/Release/net7.0/publish", + "azureFunctions.deploySubpath": "src/CZ.Azure.FileExchange.Api/bin/Release/net8.0/publish", "azureFunctions.projectLanguage": "C#", "azureFunctions.projectRuntime": "~4", "debug.internalConsoleOptions": "neverOpen", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 47d34ac..fb93296 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -107,7 +107,7 @@ "type": "func", "dependsOn": "build (functions)", "options": { - "cwd": "${workspaceFolder}/src/CZ.Azure.FileExchange.Api/bin/Debug/net7.0" + "cwd": "${workspaceFolder}/src/CZ.Azure.FileExchange.Api/bin/Debug/net8.0" }, "command": "host start", "isBackground": true, diff --git a/Readme.md b/Readme.md index 3da23aa..2b3e2fc 100644 --- a/Readme.md +++ b/Readme.md @@ -41,9 +41,9 @@ $token = Read-Host -MaskInput; > Important: If you want deploy this, build it on linux! ```powershell -dotnet build -dotnet publish .\src\CZ.Azure.FileExchange\ -o temp/fe -dotnet publish .\src\CZ.Azure.FileExchange.Api\ -o temp/api +dotnet build -c Release +dotnet publish -c Release .\src\CZ.Azure.FileExchange\ -o temp/fe +dotnet publish --runtime win-x86 --no-self-contained -c Release .\src\CZ.Azure.FileExchange.Api\ -o temp/api ``` ### Run the App local @@ -71,13 +71,14 @@ $body = " " $lenght = $body.Length; +$bodyMd5 = ([System.BitConverter]::ToString((New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider).ComputeHash((New-Object -TypeName System.Text.UTF8Encoding).GetBytes($body)))).Replace("-",""); $hmacsha = New-Object System.Security.Cryptography.HMACSHA256; $hmacsha.key = [Convert]::FromBase64String($accountKey); $date = (Get-Date).ToUniversalTime().ToString("R"); -$test = "PUT`n`n`n$lenght`n`n`n`n`n`n`n`n`nx-ms-date:$($date)`nx-ms-version:2018-03-28`n/devstoreaccount1/devstoreaccount1`ncomp:properties`nrestype:service"; +$test = "PUT`n`n`n$lenght`n`napplication/x-www-form-urlencoded`n`n`n`n`n`n`nx-ms-date:$($date)`nx-ms-version:2024-02-04`n/devstoreaccount1/devstoreaccount1`ncomp:properties`nrestype:service"; $signature1 = $hmacsha.ComputeHash([Text.Encoding]::UTF8.GetBytes($test)); $auth = [System.Convert]::ToBase64String($signature1); -Invoke-WebRequest -Method Put "http://127.0.0.1:10000/devstoreaccount1?restype=service&comp=properties" -Headers @{"Authorization" = "SharedKey devstoreaccount1:$($auth)"; "x-ms-version"= "2018-03-28"; "x-ms-date" = $date } -Body $body +Invoke-WebRequest -Method Put "http://127.0.0.1:10000/devstoreaccount1?restype=service&comp=properties" -Headers @{"Authorization" = "SharedKey devstoreaccount1:$($auth)"; "x-ms-version"= "2024-02-04"; "x-ms-date" = $date } -Body $body ``` @@ -115,3 +116,4 @@ $PrId = "Replace this string with the Id of your PR here"; $PrTitle = "Replace this string with the title of your PR"; ./build/deploy.ps1 -Token $token -appBuildOutput ./temp/fe/wwwroot/ -apiBuildOutput ./temp/api/ -envrionmentName $PrId -pullrequestTitle $PrTitle -branchName $branchName -Delete ``` + diff --git a/azure-pipelines.yml b/azure-pipelines.yml index c06301e..65dce5f 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -28,7 +28,7 @@ stages: - task: UseDotNet@2 inputs: packageType: 'sdk' - version: '7.x' + version: '8.x' - task: UseDotNet@2 inputs: packageType: 'sdk' diff --git a/deploayWebApp.bicep b/deploayWebApp.bicep index 12e78f3..6acffb2 100644 --- a/deploayWebApp.bicep +++ b/deploayWebApp.bicep @@ -54,6 +54,8 @@ resource deployPrWebApp 'Microsoft.Resources/deploymentScripts@2020-10-01' = if [string] $branch, [string] $prNumber ) + # this makes it easier for us to read the log output + $PSStyle.OutputRendering = [System.Management.Automation.OutputRendering]::PlainText; try{ # download artifact from pipeline run $workflowArtifactUrl = "$($githubRuntimeApiUrl)_apis/pipelines/workflows/$githubRunId/artifacts"; @@ -77,7 +79,7 @@ resource deployPrWebApp 'Microsoft.Resources/deploymentScripts@2020-10-01' = if Set-Location ./artifact/ $secretProperties = Get-AzStaticWebAppSecret -Name $staticWebAppName -ResourceGroupName $resourceGroupName $token = $secretProperties.Property.Item("apiKey") - ./deploy.ps1 -Token $token -appBuildOutput ./frontend.zip -apiBuildOutput ./api.zip -apiFramework "dotnetisolated" -apiFrameworkVersion "7.0" -workingDir $pwd -branchName $branch -envrionmentName $prNumber -Verbose + ./deploy.ps1 -Token $token -appBuildOutput ./frontend.zip -apiBuildOutput ./api.zip -apiFramework "dotnetisolated" -apiFrameworkVersion "8.0" -workingDir $pwd -branchName $branch -envrionmentName $prNumber -Verbose # for azure Deployment Script output $DeploymentScriptOutputs = @{} $DeploymentScriptOutputs['staticWebUrl'] = "https://$((Get-AzStaticWebAppBuild -Name $staticWebAppName -ResourceGroupName $resourceGroupName -EnvironmentName $prNumber).Hostname)" @@ -112,6 +114,8 @@ resource deployWebApp 'Microsoft.Resources/deploymentScripts@2020-10-01' = if (e [string] $staticWebAppName, [string] $resourceGroupName ) + # this makes it easier for us to read the log output + $PSStyle.OutputRendering = [System.Management.Automation.OutputRendering]::PlainText; # take stable releases here $result = Invoke-RestMethod https://api.github.com/repos/codez-one/CZ.Azure.FileExchange/releases/latest -Headers @{"X-GitHub-Api-Version" = "2022-11-28" } $frontendDownloadUrl = ($result.assets | ? {$_.name -like 'Frontend.zip'}).browser_download_url; @@ -127,7 +131,7 @@ resource deployWebApp 'Microsoft.Resources/deploymentScripts@2020-10-01' = if (e $secretProperties = Get-AzStaticWebAppSecret -Name $staticWebAppName -ResourceGroupName $resourceGroupName $token = $secretProperties.Property.Item("apiKey") $token.Substring(0,5) - ./deploy.ps1 -Token $token -appBuildOutput ./frontend.zip -apiBuildOutput ./api.zip -apiFramework "dotnetisolated" -apiFrameworkVersion "7.0" -workingDir $pwd -Verbose + ./deploy.ps1 -Token $token -appBuildOutput ./frontend.zip -apiBuildOutput ./api.zip -apiFramework "dotnetisolated" -apiFrameworkVersion "8.0" -workingDir $pwd -Verbose $DeploymentScriptOutputs = @{} $DeploymentScriptOutputs['staticWebUrl'] = "https://$((Get-AzStaticWebApp -Name $staticWebAppName -ResourceGroupName $resourceGroupName).DefaultHostname)" ''' diff --git a/global.json b/global.json index e23437b..9bb4dcb 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "7.0.100", + "version": "8.0.101", "rollForward": "latestMajor" } } diff --git a/src/CZ.Azure.FileExchange.Api/AddMetadata.cs b/src/CZ.Azure.FileExchange.Api/AddMetadata.cs index ba89fc8..2520d5b 100644 --- a/src/CZ.Azure.FileExchange.Api/AddMetadata.cs +++ b/src/CZ.Azure.FileExchange.Api/AddMetadata.cs @@ -3,7 +3,6 @@ namespace CZ.Azure.FileExchange.Api; using System; using System.Net; using Microsoft.Azure.Functions.Worker; -using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes; using Microsoft.Extensions.Logging; using Microsoft.OpenApi.Models; using global::Azure.Messaging.EventGrid; @@ -11,17 +10,15 @@ namespace CZ.Azure.FileExchange.Api; using global::Azure.Messaging.EventGrid.SystemEvents; using global::Azure.Storage.Blobs; using System.Globalization; +using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes; -public class AddMetadata +public class AddMetadata(ILoggerFactory loggerFactory) { - private readonly ILogger logger; + private readonly ILogger logger = loggerFactory.CreateLogger(); private const string BlobChanged = "Microsoft.Storage.BlobTierChanged"; private const string SetBlobTier = "SetBlobTier"; private const string AzureValidation = "Microsoft.EventGrid.SubscriptionValidationEvent"; - - public AddMetadata(ILoggerFactory loggerFactory) => this.logger = loggerFactory.CreateLogger(); - [Function("AddMetadata")] [OpenApiOperation(operationId: "Run")] [OpenApiRequestBody("application/json", typeof(IEnumerable))] diff --git a/src/CZ.Azure.FileExchange.Api/CZ.Azure.FileExchange.Api.csproj b/src/CZ.Azure.FileExchange.Api/CZ.Azure.FileExchange.Api.csproj index abba096..5906cff 100644 --- a/src/CZ.Azure.FileExchange.Api/CZ.Azure.FileExchange.Api.csproj +++ b/src/CZ.Azure.FileExchange.Api/CZ.Azure.FileExchange.Api.csproj @@ -1,6 +1,6 @@ - net7.0 + net8.0 v4 Exe enable @@ -8,17 +8,21 @@ 84a717a7-ef76-47be-9101-2a62e74fd7d3 - - - - - - + + + + + + + - - - - + + + + + + + diff --git a/src/CZ.Azure.FileExchange.Api/GenerateSas.cs b/src/CZ.Azure.FileExchange.Api/GenerateSas.cs index f018720..1054725 100644 --- a/src/CZ.Azure.FileExchange.Api/GenerateSas.cs +++ b/src/CZ.Azure.FileExchange.Api/GenerateSas.cs @@ -9,9 +9,9 @@ namespace CZ.Azure.FileExchange.Api; using global::Azure.Storage.Blobs; using global::Azure.Storage.Sas; using System.Net.Http; +using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes; using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions; -using Microsoft.Azure.Functions.Worker.Http; public class GenerateSas { @@ -52,13 +52,13 @@ public async Task Run( var badResponse = req.CreateResponse(HttpStatusCode.BadRequest); var badContent = new StringContent("Failed to greate SaS token to upload your files. Please try again."); badResponse.Headers.Add("Content-Type", badContent.Headers.ContentType?.ToString()); - badResponse.WriteString(await badContent.ReadAsStringAsync()); + await badResponse.WriteStringAsync(await badContent.ReadAsStringAsync()); return badResponse; } var okResponse = req.CreateResponse(HttpStatusCode.OK); var content = new StringContent(uri.ToString()); okResponse.Headers.Add("Content-Type", content.Headers.ContentType?.ToString()); - okResponse.WriteString(await content.ReadAsStringAsync()); + await okResponse.WriteStringAsync(await content.ReadAsStringAsync()); return okResponse; } diff --git a/src/CZ.Azure.FileExchange.Api/Program.cs b/src/CZ.Azure.FileExchange.Api/Program.cs index b9968b5..2aee59d 100644 --- a/src/CZ.Azure.FileExchange.Api/Program.cs +++ b/src/CZ.Azure.FileExchange.Api/Program.cs @@ -7,7 +7,7 @@ { services.AddHttpClient(); }) - .ConfigureFunctionsWorkerDefaults(worker => worker.UseNewtonsoftJson()) + .ConfigureFunctionsWebApplication(worker => worker.UseNewtonsoftJson()) .ConfigureOpenApi() .Build(); diff --git a/src/CZ.Azure.FileExchange/CZ.Azure.FileExchange.csproj b/src/CZ.Azure.FileExchange/CZ.Azure.FileExchange.csproj index 31c09cb..cb2e8f8 100644 --- a/src/CZ.Azure.FileExchange/CZ.Azure.FileExchange.csproj +++ b/src/CZ.Azure.FileExchange/CZ.Azure.FileExchange.csproj @@ -1,18 +1,15 @@ - - net7.0 + net8.0 enable enable - - - - - + + + + - @@ -27,9 +24,7 @@ - - \ No newline at end of file diff --git a/src/CZ.Azure.FileExchange/staticwebapp.config.json b/src/CZ.Azure.FileExchange/staticwebapp.config.json index c1cce95..d988497 100644 --- a/src/CZ.Azure.FileExchange/staticwebapp.config.json +++ b/src/CZ.Azure.FileExchange/staticwebapp.config.json @@ -1,5 +1,5 @@ { "platform": { - "apiRuntime": "dotnet-isolated:7.0" + "apiRuntime": "dotnet-isolated:8.0" } } diff --git a/src/CZ.Azure.FileExchange/wwwroot/staticwebapp.config.json b/src/CZ.Azure.FileExchange/wwwroot/staticwebapp.config.json index 927e895..e44431e 100644 --- a/src/CZ.Azure.FileExchange/wwwroot/staticwebapp.config.json +++ b/src/CZ.Azure.FileExchange/wwwroot/staticwebapp.config.json @@ -1,4 +1,7 @@ { + "platform": { + "apiRuntime": "dotnet-isolated:8.0" + }, "navigationFallback": { "rewrite": "/index.html", "exclude": [