Skip to content

Commit

Permalink
Merge pull request #6 from thangchung/feat/upgrade-aspire
Browse files Browse the repository at this point in the history
.NET Aspire upgrade
  • Loading branch information
thangchung authored Jun 13, 2024
2 parents 35db012 + 84c8e95 commit 6b066be
Show file tree
Hide file tree
Showing 119 changed files with 6,440 additions and 981 deletions.
11 changes: 4 additions & 7 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0.100-jammy
FROM mcr.microsoft.com/dotnet/sdk:8.0-jammy

# Install make
RUN apt update && apt install -y make
# RUN apt-get update &&
# RUN apt-get update && apt-get install -y make

## https://github.com/dotnet/aspire/blob/main/docs/using-latest-daily.md
RUN dotnet workload update --skip-sign-check --source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json \
&& dotnet workload install aspire --skip-sign-check --source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json

# RUN dotnet workload install aspire
RUN dotnet workload install aspire
3 changes: 3 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"ghcr.io/devcontainers/features/azure-cli:1": {},
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {},
"ghcr.io/rio/features/k3d:1": {},
"ghcr.io/azure/azure-dev/azd:0": { "version": "latest" },
"ghcr.io/prom3theu5/aspirational-manifests/aspirate:latest": {},
"ghcr.io/devcontainers/features/common-utils:2": {
"configureZshAsDefaultShell": true
}
Expand All @@ -37,6 +39,7 @@
"ms-dotnettools.csdevkit",
"ms-azuretools.vscode-docker",
"dunn.redis",
"ms-azuretools.vscode-bicep",
"GitHub.copilot"
]
}
Expand Down
13 changes: 12 additions & 1 deletion .devcontainer/post-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@ while (! kubectl cluster-info ); do
# Docker takes a few seconds to initialize
echo "Waiting for Docker to launch..."
k3d cluster delete
k3d cluster create -p '8081:80@loadbalancer' --k3s-arg '--disable=traefik@server:0'
k3d registry create myregistry.localhost --port 12345
k3d cluster create -p '8081:80@loadbalancer' --k3s-arg '--disable=traefik@server:0' --registry-use k3d-myregistry.localhost:12345
sleep 1
done

# docker pull docker.io/library/postgres:16.2
# docker pull docker.io/library/rabbitmq:3.13-management
# docker pull docker.io/library/redis:7.2

# docker tag docker.io/library/postgres:16.2 k3d-myregistry.localhost:12345/postgres:16.2
# docker tag docker.io/library/rabbitmq:3.13-management k3d-myregistry.localhost:12345/rabbitmq:3.13-management
# docker tag docker.io/library/redis:7.2 k3d-myregistry.localhost:12345/redis:7.2

# docker tag product-api k3d-myregistry.localhost:12345/product-api:latest

## dotnet
dotnet restore

Expand Down
26 changes: 25 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ root = true

# All files
[*]
indent_style = space
indent_style = tab

# Xml files
[*.xml]
Expand Down Expand Up @@ -170,6 +170,23 @@ csharp_space_between_square_brackets = false
# Wrapping preferences
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_style_prefer_null_check_over_type_check = true:suggestion
csharp_style_prefer_local_over_anonymous_function = true:suggestion
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
csharp_style_prefer_tuple_swap = true:suggestion
csharp_style_prefer_utf8_string_literals = true:suggestion
csharp_style_prefer_readonly_struct = true:suggestion
csharp_style_prefer_readonly_struct_member = true:suggestion
csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true:silent
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:silent
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true:silent
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true:silent
csharp_style_prefer_extended_property_pattern = true:suggestion

#### Naming styles ####
[*.{cs,vb}]
Expand Down Expand Up @@ -361,4 +378,11 @@ dotnet_naming_style.s_camelcase.required_prefix = s_
dotnet_naming_style.s_camelcase.required_suffix =
dotnet_naming_style.s_camelcase.word_separator =
dotnet_naming_style.s_camelcase.capitalization = camel_case
tab_width = 4
indent_size = 4
end_of_line = crlf
dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion
dotnet_style_namespace_match_folder = true:suggestion
dotnet_style_allow_multiple_blank_lines_experimental = true:silent
dotnet_style_allow_statement_immediately_after_block_experimental = true:silent

46 changes: 46 additions & 0 deletions .github/workflows/dotnet-code-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: .NET Coverage

on:
push:
branches:
- main
- feat/*

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x

- name: Install .NET Aspire workload
run: dotnet workload install aspire

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --no-restore

- name: Test
run: dotnet test --no-build --settings tests.runsettings --results-directory ./coverage

- name: Publish coverage
uses: irongut/[email protected]
with:
filename: coverage/**/coverage.cobertura.xml
badge: true
format: markdown

- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
path: code-coverage-results.md
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,5 @@ MigrationBackup/
.ionide/
.idea/
tmp/
.env
.env
coverage/
118 changes: 75 additions & 43 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,45 +1,77 @@
<Project>

<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0"/>
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0" PrivateAssets="all"/>
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0"/>
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0"/>
<PackageVersion Include="Microsoft.OpenApi" Version="1.6.10"/>
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0"/>
<PackageVersion Include="Yarp.ReverseProxy" Version="2.1.0"/>
<PackageVersion Include="MediatR" Version="12.2.0"/>
<PackageVersion Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageVersion Include="MassTransit" Version="8.1.2" />
<PackageVersion Include="MassTransit.RabbitMQ" Version="8.1.2" />
</ItemGroup>

<ItemGroup>
<!-- <PackageVersion Include="Aspire.Hosting" Version="8.0.0-preview.3.23614.7" />
<PackageVersion Include="Aspire.Hosting.Dapr" Version="8.0.0-preview.3.23614.7" /> -->
<PackageVersion Include="Aspire.Hosting" Version="8.0.0-preview.1.23557.2" />

<!-- <PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="8.0.0-preview.3.23614.7" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.7.0-alpha.1" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.7.0-alpha.1" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.6.0-beta.2" />
<PackageVersion Include="OpenTelemetry.Instrumentation.GrpcNetClient" Version="1.6.0-beta.2" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.6.0-beta.2" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.5.1" /> -->

<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="8.0.0-preview.1.23557.2" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.7.0-alpha.1" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.7.0-alpha.1" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.6.0-beta.2" />
<PackageVersion Include="OpenTelemetry.Instrumentation.GrpcNetClient" Version="1.6.0-beta.2" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.6.0-beta.2" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.5.1" />
</ItemGroup>

<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
<AspnetVersion>8.0.5</AspnetVersion>
<MicrosoftExtensionsVersion>8.4.0</MicrosoftExtensionsVersion>
<EfVersion>8.0.4</EfVersion>
<AspireVersion>8.0.1</AspireVersion>
<AspirantVersion>0.0.4</AspirantVersion>
<HealthCheckVersion>8.0.1</HealthCheckVersion>
<AspVersioningVersion>8.1.0</AspVersioningVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.AspNet.WebApi.Core" Version="5.3.0" />
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.6" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="$(AspnetVersion)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="$(EfVersion)" PrivateAssets="all" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="$(EfVersion)" />
<PackageVersion Include="Microsoft.OpenApi" Version="1.6.10" />
<PackageVersion Include="Asp.Versioning.Http" Version="$(AspVersioningVersion)" />
<PackageVersion Include="Asp.Versioning.Mvc.ApiExplorer" Version="$(AspVersioningVersion)" />
<PackageVersion Include="Asp.Versioning.Http.Client" Version="$(AspVersioningVersion)" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="MediatR" Version="12.2.0" />
<PackageVersion Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageVersion Include="FluentValidation" Version="11.9.1" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="Riok.Mapperly" Version="3.5.1" ExcludeAssets="runtime" PrivateAssets="all" />
<PackageVersion Include="MassTransit" Version="8.1.2" />
<PackageVersion Include="MassTransit.RabbitMQ" Version="8.1.2" />
<PackageVersion Include="Marten.AspNetCore" Version="7.10.1" />
<PackageVersion Include="Marten" Version="7.10.1" />
<PackageVersion Include="Yarp.ReverseProxy" Version="2.1.0" />
</ItemGroup>
<ItemGroup>
<!-- Aspire -->
<PackageVersion Include="Aspire.Hosting" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.AppHost" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.PostgreSQL" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.RabbitMQ" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.Redis" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.Testing" Version="$(AspireVersion)" />
<PackageVersion Include="Aspirant.Hosting" Version="$(AspirantVersion)" />
<PackageVersion Include="Aspirant.Hosting.Yarp" Version="$(AspirantVersion)" />
<PackageVersion Include="Aspirant.Hosting.Testing" Version="$(AspirantVersion)" />
<PackageVersion Include="Fredi.Aspire.Hosting.WireMock" Version="0.0.1" />
<!-- Aspire Custom Extensions -->
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="$(MicrosoftExtensionsVersion)" />
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="$(AspireVersion)" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.8.1" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.8.1" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.8.1" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.8.1" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.8.0" />
<PackageVersion Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.3.0-beta.2" />
<PackageVersion Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.2.0-beta.4" />
</ItemGroup>
<ItemGroup>
<!-- Healthchecks -->
<PackageVersion Include="AspNetCore.HealthChecks.Uris" Version="$(HealthCheckVersion)" />
<PackageVersion Include="AspNetCore.HealthChecks.NpgSql" Version="$(HealthCheckVersion)" />
<PackageVersion Include="AspNetCore.HealthChecks.Rabbitmq" Version="$(HealthCheckVersion)" />
<PackageVersion Include="AspNetCore.HealthChecks.Redis" Version="$(HealthCheckVersion)" />
</ItemGroup>
<ItemGroup>
<!-- Testing -->
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="xunit" Version="2.5.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageVersion Include="MSTest" Version="3.2.0" />
<PackageVersion Include="ReportGenerator" Version="5.3.6" />

</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<configuration>
<packageSources>
<clear />
<add key="dotnet8" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json" />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

The coffeeshop apps on .NET Aspire

![Counter API-Code Coverage](https://img.shields.io/badge/Code%20Coverage-73%25-yellow?style=flat)

## Prerequisites

If you run on `Windows 11`:
Expand All @@ -19,6 +21,21 @@ If you run on `Windows 11`:
# http://localhost:5019
```

## Generate manifest file (powershell)

```sh
dotnet run --project app-host\CoffeeShop.AppHost.csproj `
-- `
--publisher manifest `
--output-path ../aspire-manifest.json
```

## Deploy to Kubernetes

```sh
dotnet tool install -g aspirate --prerelease
```

## Run with Justfile (cross-platform)

```sh
Expand All @@ -34,3 +51,8 @@ On Windows 11 - WSL2 Ubuntu 22 integrated, we can use `Podman Desktop` to replac
> make run
# http://localhost:5019
```

```sh
dotnet publish "/workspaces/coffeeshop-aspire/app-host/../product-api/CoffeeShop.ProductApi.csproj" -p:PublishProfile="DefaultContainer" -p:PublishSingleFile="true"
-p:PublishTrimmed="false" --self-contained "true" --verbosity "quiet" --nologo -r "linux-x64" -p:ContainerRegistry="k3d-myregistry.localhost:12345" -p:ContainerRepository="product-api" -p:ContainerImageTag="latest"
```
37 changes: 37 additions & 0 deletions app-host/CoffeeShop.AppHost.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting" />
<PackageReference Include="Aspire.Hosting.AppHost" />
<PackageReference Include="Aspire.Hosting.PostgreSQL" />
<PackageReference Include="Aspire.Hosting.Redis" />
<PackageReference Include="Aspire.Hosting.RabbitMQ" />
<PackageReference Include="Aspirant.Hosting" />
<PackageReference Include="Aspirant.Hosting.Yarp" />
<PackageReference Include="Yarp.ReverseProxy" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" />
<PackageReference Include="AspNetCore.HealthChecks.Rabbitmq" />
<PackageReference Include="AspNetCore.HealthChecks.Redis" />
<PackageReference Include="AspNetCore.HealthChecks.Uris" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\order-summary\CoffeeShop.OrderSummary.csproj" />
<ProjectReference Include="..\product-api\CoffeeShop.ProductApi.csproj" />
<ProjectReference Include="..\counter-api\CoffeeShop.CounterApi.csproj" />
<ProjectReference Include="..\barista-api\CoffeeShop.BaristaApi.csproj" />
<ProjectReference Include="..\kitchen-api\CoffeeShop.KitchenApi.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit 6b066be

Please sign in to comment.