From 713702ba027d1d6fda071d23d0209e05f1a5ccc4 Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Tue, 30 Apr 2024 14:13:42 +0100 Subject: [PATCH] Add Aspire host (#2377) Add an Aspire app host with CosmosDB emulator for local development. --- .github/dependabot.yml | 3 +++ .github/workflows/build.yml | 4 ++++ .github/workflows/codeql-analysis.yml | 7 +++++++ Directory.Packages.props | 5 ++++- LondonTravel.Site.sln | 7 +++++++ README.md | 5 +++++ .../LondonTravel.Site.AppHost.csproj | 14 ++++++++++++++ src/LondonTravel.Site.AppHost/Program.cs | 14 ++++++++++++++ .../Properties/launchSettings.json | 17 +++++++++++++++++ .../appsettings.Development.json | 8 ++++++++ src/LondonTravel.Site.AppHost/appsettings.json | 9 +++++++++ src/LondonTravel.Site/LondonTravel.Site.csproj | 1 + src/LondonTravel.Site/Program.cs | 2 ++ 13 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 src/LondonTravel.Site.AppHost/LondonTravel.Site.AppHost.csproj create mode 100644 src/LondonTravel.Site.AppHost/Program.cs create mode 100644 src/LondonTravel.Site.AppHost/Properties/launchSettings.json create mode 100644 src/LondonTravel.Site.AppHost/appsettings.Development.json create mode 100644 src/LondonTravel.Site.AppHost/appsettings.json diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 97edccca3..f05853984 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -11,6 +11,9 @@ updates: - package-ecosystem: nuget directory: "/" groups: + Aspire: + patterns: + - Aspire.* OpenTelemetry: patterns: - OpenTelemetry* diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6e9ae87d2..0285ceff5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -96,6 +96,10 @@ jobs: ~/.cache/ms-playwright ~/Library/Caches/ms-playwright + - name: Install .NET Workloads + shell: pwsh + run: dotnet workload restore + - name: Build, test and publish shell: pwsh run: ./build.ps1 diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 9392cec67..61293d076 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -77,6 +77,13 @@ jobs: - name: Autobuild uses: github/codeql-action/autobuild@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3 + if: matrix.language != 'csharp' + + - name: Build .NET code + if: matrix.language == 'csharp' + run: | + dotnet workload restore + dotnet build --configuration Release - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3 diff --git a/Directory.Packages.props b/Directory.Packages.props index 06fd0b026..cf6c61daa 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,9 +1,12 @@ - + + + + diff --git a/LondonTravel.Site.sln b/LondonTravel.Site.sln index d6d9176a8..c2a56691c 100644 --- a/LondonTravel.Site.sln +++ b/LondonTravel.Site.sln @@ -64,6 +64,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{ .github\workflows\ossf-scorecard.yml = .github\workflows\ossf-scorecard.yml EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LondonTravel.Site.AppHost", "src\LondonTravel.Site.AppHost\LondonTravel.Site.AppHost.csproj", "{4C191691-65C5-4C8A-85AD-D8C55E6AD6C4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -78,6 +80,10 @@ Global {0106CA34-73B0-4F30-8BDF-AF8D7AB22A4A}.Debug|Any CPU.Build.0 = Debug|Any CPU {0106CA34-73B0-4F30-8BDF-AF8D7AB22A4A}.Release|Any CPU.ActiveCfg = Release|Any CPU {0106CA34-73B0-4F30-8BDF-AF8D7AB22A4A}.Release|Any CPU.Build.0 = Release|Any CPU + {4C191691-65C5-4C8A-85AD-D8C55E6AD6C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4C191691-65C5-4C8A-85AD-D8C55E6AD6C4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4C191691-65C5-4C8A-85AD-D8C55E6AD6C4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4C191691-65C5-4C8A-85AD-D8C55E6AD6C4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -89,6 +95,7 @@ Global {4F53FEF1-66BC-45ED-B563-A619E9A193B7} = {DD7EA67A-4FE1-4D4F-825E-51FF842107AB} {4AD9EC06-329C-47FB-8549-1A1EDE980130} = {DD7EA67A-4FE1-4D4F-825E-51FF842107AB} {22736F26-BC95-4792-915C-B6E61FEB523A} = {4F53FEF1-66BC-45ED-B563-A619E9A193B7} + {4C191691-65C5-4C8A-85AD-D8C55E6AD6C4} = {0EED3EF2-37DE-4E6E-B766-3E641D163515} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {612E5D09-113B-4494-BEE6-0376224726FE} diff --git a/README.md b/README.md index 221aeb65f..aacf0d5c1 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,11 @@ To build and test the website run the following commands from your terminal of c ```powershell git clone https://github.com/martincostello/alexa-london-travel-site.git cd alexa-london-travel-site + +# Restore Aspire workload on first usage (requires elevation on Windows if not installed) +dotnet workload restore + +# Build and test the application ./build.ps1 ``` diff --git a/src/LondonTravel.Site.AppHost/LondonTravel.Site.AppHost.csproj b/src/LondonTravel.Site.AppHost/LondonTravel.Site.AppHost.csproj new file mode 100644 index 000000000..ecb1467d1 --- /dev/null +++ b/src/LondonTravel.Site.AppHost/LondonTravel.Site.AppHost.csproj @@ -0,0 +1,14 @@ + + + true + Exe + net8.0 + + + + + + + + + diff --git a/src/LondonTravel.Site.AppHost/Program.cs b/src/LondonTravel.Site.AppHost/Program.cs new file mode 100644 index 000000000..a918e8113 --- /dev/null +++ b/src/LondonTravel.Site.AppHost/Program.cs @@ -0,0 +1,14 @@ +// Copyright (c) Martin Costello, 2017. All rights reserved. +// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information. + +var builder = DistributedApplication.CreateBuilder(args); + +var cosmos = builder.AddAzureCosmosDB("Cosmos") + .RunAsEmulator(); + +builder.AddProject("LondonTravelSite") + .WithReference(cosmos); + +var app = builder.Build(); + +app.Run(); diff --git a/src/LondonTravel.Site.AppHost/Properties/launchSettings.json b/src/LondonTravel.Site.AppHost/Properties/launchSettings.json new file mode 100644 index 000000000..fcecff21e --- /dev/null +++ b/src/LondonTravel.Site.AppHost/Properties/launchSettings.json @@ -0,0 +1,17 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "AppHost": { + "commandName": "Project", + "applicationUrl": "https://localhost:15292;http://localhost:15293", + "dotnetRunMessages": true, + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "DOTNET_ENVIRONMENT": "Development", + "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:16099", + "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:17037" + } + } + } +} diff --git a/src/LondonTravel.Site.AppHost/appsettings.Development.json b/src/LondonTravel.Site.AppHost/appsettings.Development.json new file mode 100644 index 000000000..0c208ae91 --- /dev/null +++ b/src/LondonTravel.Site.AppHost/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/src/LondonTravel.Site.AppHost/appsettings.json b/src/LondonTravel.Site.AppHost/appsettings.json new file mode 100644 index 000000000..4c6bccc43 --- /dev/null +++ b/src/LondonTravel.Site.AppHost/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Aspire.Hosting.Dcp": "Warning", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/src/LondonTravel.Site/LondonTravel.Site.csproj b/src/LondonTravel.Site/LondonTravel.Site.csproj index 73cf33628..cd6f8fff1 100644 --- a/src/LondonTravel.Site/LondonTravel.Site.csproj +++ b/src/LondonTravel.Site/LondonTravel.Site.csproj @@ -23,6 +23,7 @@ noble-chiseled-extra + diff --git a/src/LondonTravel.Site/Program.cs b/src/LondonTravel.Site/Program.cs index e82c1176a..11167ed4e 100644 --- a/src/LondonTravel.Site/Program.cs +++ b/src/LondonTravel.Site/Program.cs @@ -167,6 +167,8 @@ builder.Services.AddSingleton(TimeProvider.System); builder.Services.AddSingleton(); + +builder.AddAzureCosmosDBClient("Cosmos"); builder.Services.AddSingleton(DocumentHelpers.CreateClient); builder.Services.TryAddSingleton(); builder.Services.TryAddSingleton();