diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 949135a..fa8bb27 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,24 @@ on: push: branches: - master # Change to your default branch if different - + workflow_dispatch: + inputs: + environment: + description: 'Environment to deploy to' + required: true + default: 'prod' + type: choice + options: + - prod + restart_iis: + description: 'Restart IIS after deployment' + required: true + default: true + type: boolean + create_release: + description: 'Create release' + required: true + default: true jobs: build: runs-on: self-hosted # Ensure your self-hosted runner is configured @@ -31,6 +48,39 @@ jobs: - name: Publish .NET Project run: dotnet publish ./services/bytefy.image/bytefy.image/bytefy.image.csproj --configuration Release --output ./output/dotnet + + - name: Create placeholder appsettings for release + if: ${{ github.event.inputs.create_release != 'false' }} + run: | + $appSettings = @{ + Logging = @{ + LogLevel = @{ + Default = "Information" + "Microsoft.AspNetCore" = "Warning" + } + } + AllowedHosts = "*" + Cors = @{ + AllowedOrigins = @( + "http://localhost:4200" + "https://localhost:4200" + ) + } + Seq = @{ + ServerUrl = ${{ vars.SEQ_URL }} + ApiKey = ${{ secrets.seq_api_key }} + MinimumLevel = "Trace" + LevelOverride = @{ + Microsoft = "Warning" + } + } + } + + $appSettings | ConvertTo-Json -Depth 10 | Set-Content -Path "./output/dotnet/appsettings.json" + Write-Host "Created placeholder appsettings.json successfully" + + + - name: Install Node.js uses: actions/setup-node@v3 with: @@ -63,6 +113,7 @@ jobs: deploy: runs-on: self-hosted # Ensure your self-hosted runner is configured + if: ${{ github.event.inputs.create_release != 'false' }} needs: build steps: @@ -88,3 +139,25 @@ jobs: xcopy ".\output\dotnet\*" "C:\inetpub\applications\bytefy.image" /s /i /y xcopy ".\bytefy.webapp\dist\browser\*" "C:\inetpub\wwwroot\bytefy" /s /i /y + - name: Restart IIS Application Pool + if: ${{ github.event.inputs.restart_iis != 'false' }} + run: | + Import-Module WebAdministration + $appPoolName = "${{ vars.IIS_APP_POOL_NAME }}" + if ([string]::IsNullOrEmpty($appPoolName)) { + $appPoolName = "HomeApi" + } + + Write-Host "Starting application pool: $appPoolName" + + # Check if app pool exists + if (Test-Path "IIS:\AppPools\$appPoolName") { + # Start app pool + Start-WebAppPool -Name $appPoolName + Write-Host "Application pool started successfully" + } else { + Write-Host "Warning: Application pool '$appPoolName' not found. Using IISReset instead." + iisreset /restart + Write-Host "IIS restarted successfully" + } + diff --git a/services/bytefy.image/bytefy.image/Program.cs b/services/bytefy.image/bytefy.image/Program.cs index e8db155..b2ccd19 100644 --- a/services/bytefy.image/bytefy.image/Program.cs +++ b/services/bytefy.image/bytefy.image/Program.cs @@ -7,6 +7,10 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.AddAntiforgery(options => options.HeaderName = "2311d8d8-607d-4747-8939-1bde65643254"); builder.Services.AddSingleton(); builder.Services.AddHostedService(provider => provider.GetRequiredService()); +builder.Services.AddLogging(loggingBuilder => +{ + loggingBuilder.AddSeq(builder.Configuration.GetSection("Seq")); +}); var corsSettings = builder.Configuration.GetSection("Cors").Get(); diff --git a/services/bytefy.image/bytefy.image/appsettings.Development.json b/services/bytefy.image/bytefy.image/appsettings.Development.json index ef9eb20..714c7d8 100644 --- a/services/bytefy.image/bytefy.image/appsettings.Development.json +++ b/services/bytefy.image/bytefy.image/appsettings.Development.json @@ -11,5 +11,13 @@ "http://localhost:4200", "https://localhost:4200" ] + }, + "Seq": { + "ServerUrl": "https://log.azaaxin.com", + "ApiKey": "KEY", + "MinimumLevel": "Trace", + "LevelOverride": { + "Microsoft": "Warning" + } } } diff --git a/services/bytefy.image/bytefy.image/appsettings.json b/services/bytefy.image/bytefy.image/appsettings.json index 6414d74..0800983 100644 --- a/services/bytefy.image/bytefy.image/appsettings.json +++ b/services/bytefy.image/bytefy.image/appsettings.json @@ -10,5 +10,13 @@ "http://bytefy.net", "https://bytefy.net" ] + }, + "Seq": { + "ServerUrl": "https://log.azaaxin.com", + "ApiKey": "KEY", + "MinimumLevel": "Trace", + "LevelOverride": { + "Microsoft": "Warning" + } } } diff --git a/services/bytefy.image/bytefy.image/bytefy.image.csproj b/services/bytefy.image/bytefy.image/bytefy.image.csproj index 28af9cc..9842533 100644 --- a/services/bytefy.image/bytefy.image/bytefy.image.csproj +++ b/services/bytefy.image/bytefy.image/bytefy.image.csproj @@ -18,6 +18,7 @@ +