Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo code merge #7

Merged
merged 38 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
80e2638
Update `IsAspireHost` property in test projects
spboyer Apr 25, 2024
0128b94
Added new projects, classes, and updated configurations
spboyer Apr 25, 2024
0e9bd20
add workflow for pipeline and azure.yml for config host
spboyer Apr 25, 2024
d8bb945
update workflow to add openai ENV items
spboyer Apr 25, 2024
0fab32f
Configure Azure Developer Pipeline
spboyer Apr 25, 2024
ca67877
change useOpenAI to ENV variable
spboyer Apr 25, 2024
9b0e247
Configure Azure Developer Pipeline
spboyer Apr 25, 2024
1d806dc
fixing openapi flag
spboyer Apr 25, 2024
e924ede
useopenai ENV change
spboyer Apr 25, 2024
a3f72a0
echo env var
spboyer Apr 26, 2024
6905c05
minor fix for format
spboyer Apr 26, 2024
ed9645d
set env at provision step
spboyer Apr 26, 2024
937e1ef
Configuration naming structure with underscore issues
spboyer Apr 26, 2024
ae5210a
Configure Azure Developer Pipeline
spboyer Apr 26, 2024
126158f
Configure Azure Developer Pipeline
spboyer Apr 26, 2024
3701105
save program.cs
spboyer Apr 26, 2024
f84711d
updates from Victor
spboyer Apr 26, 2024
6ca764a
Configure Azure Developer Pipeline
spboyer Apr 26, 2024
7aa5575
Configure Azure Developer Pipeline
spboyer Apr 26, 2024
22b136f
Configure Azure Developer Pipeline
spboyer Apr 26, 2024
937f7be
Configure Azure Developer Pipeline
spboyer Apr 26, 2024
d98be90
... try again
spboyer Apr 26, 2024
538f24a
update ENV workings
spboyer Apr 26, 2024
410bb0f
Configure Azure Developer Pipeline
spboyer Apr 29, 2024
c9474ba
update ENV for connectionstring
spboyer Apr 29, 2024
13b5c50
update more VARS to make it happen
spboyer Apr 29, 2024
866fb2c
update action for azd env set
spboyer Apr 29, 2024
2103ce5
update more VARS to make it happen again
spboyer Apr 29, 2024
cc18b1a
update more VARS to make it happen again again
spboyer Apr 29, 2024
4af3171
env playground
spboyer Apr 29, 2024
3beaa05
create env for azd
spboyer Apr 29, 2024
c463a99
escape quotes
spboyer Apr 29, 2024
9f914a3
misspelling
spboyer Apr 29, 2024
3625d16
quote vars for escaping characters
spboyer Apr 30, 2024
9775a46
Configure Azure Developer Pipeline
spboyer Apr 30, 2024
ba25534
add profiler package for webapp workaround
spboyer Apr 30, 2024
2d2eb18
Revert "add profiler package for webapp workaround"
spboyer Apr 30, 2024
6b71405
add profiler to extension class
spboyer Apr 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .github/workflows/azure-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: eShop Build, Provision, and Deploy to Azure

on:
workflow_dispatch:
push:
# Run when commits are pushed to mainline branch (main or master)
# Set this to the mainline branch you are using
branches:
- shboyer

permissions:
id-token: write
contents: read

jobs:
build:
runs-on: ubuntu-latest
env:
AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
AZURE_OPENAI: "Endpoint=${{ vars.OPEN_ENDPOINT }};Key=${{ secrets.OPENKEY }}"

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install azd
uses: Azure/setup-azd@v0.1.0

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

- name: Log in with Azure (Federated Credentials)
if: ${{ env.AZURE_CLIENT_ID != '' }}
run: |
azd auth login `
--client-id "$Env:AZURE_CLIENT_ID" `
--federated-credential-provider "github" `
--tenant-id "$Env:AZURE_TENANT_ID"
shell: pwsh

- name: Log in with Azure (Client Credentials)
if: ${{ env.AZURE_CREDENTIALS != '' }}
run: |
$info = $Env:AZURE_CREDENTIALS | ConvertFrom-Json -AsHashtable;
Write-Host "::add-mask::$($info.clientSecret)"

azd auth login `
--client-id "$($info.clientId)" `
--client-secret "$($info.clientSecret)" `
--tenant-id "$($info.tenantId)"
shell: pwsh

- name: Set azd ENV
run: |
azd env new ${{ vars.AZURE_ENV_NAME }} --location ${{ vars.AZURE_LOCATION }} --subscription ${{ vars.AZURE_SUBSCRIPTION_ID }} --no-prompt
azd env set OPENAI_CONNECTIONSTRING "${{ env.AZURE_OPENAI }}" --no-prompt


- name: Provision Infrastructure
run: azd provision --no-prompt
env:
#AZD_INITIAL_ENVIRONMENT_CONFIG: ${{ secrets.AZD_INITIAL_ENVIRONMENT_CONFIG }}
ConnectionStrings__OpenAi: "${{ env.AZURE_OPENAI }}"

- name: Deploy Application
run: |
azd env set OPENAI_CONNECTIONSTRING "${{ env.AZURE_OPENAI }}" --no-prompt
azd deploy --no-prompt
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,4 @@ $RECYCLE.BIN/
/playwright/.auth/
/user.json
.azure
/src/eShop.AppHost/Properties/launchSettings.json
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<PackageVersion Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.StackExchange.Redis" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Azure.AI.OpenAI" Version="$(AspireVersion)" />
<PackageVersion Include="Microsoft.ApplicationInsights.Profiler.AspNetCore" Version="2.7.1" />
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="$(AspireVersion)" />
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery.Yarp" Version="$(AspireVersion)" />
<!-- Version together with ASP.NET -->
Expand Down
8 changes: 8 additions & 0 deletions azure.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json

name: eShopOnAzure
services:
app:
language: dotnet
project: .\src\eShop.AppHost\eShop.AppHost.csproj
host: containerapp
3 changes: 2 additions & 1 deletion eShop.Web.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
"src\\EventBus\\EventBus.csproj",
"src\\IntegrationEventLogEF\\IntegrationEventLogEF.csproj",
"src\\Mobile.Bff.Shopping\\Mobile.Bff.Shopping.csproj",
"src\\Ordering.API\\Ordering.API.csproj",
"src\\OrderProcessor\\OrderProcessor.csproj",
"src\\Ordering.API\\Ordering.API.csproj",
"src\\Ordering.Domain\\Ordering.Domain.csproj",
"src\\Ordering.Infrastructure\\Ordering.Infrastructure.csproj",
"src\\PaymentProcessor\\PaymentProcessor.csproj",
"src\\Performance\\Performance.csproj",
"src\\WebAppComponents\\WebAppComponents.csproj",
"src\\WebApp\\WebApp.csproj",
"src\\WebhookClient\\WebhookClient.csproj",
Expand Down
12 changes: 12 additions & 0 deletions eShop.sln
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientApp", "src\ClientApp\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientApp.UnitTests", "tests\ClientApp.UnitTests\ClientApp.UnitTests.csproj", "{02878FFB-F4DA-4996-B4A6-308851A837C6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Performance", "src\Performance\Performance.csproj", "{71667539-C845-46D8-8E43-E686D1B184B1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{3673B22C-778B-46B0-AB34-338C6F52BBDF}"
ProjectSection(SolutionItems) = preProject
.github\workflows\azure-dev.yml = .github\workflows\azure-dev.yml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -169,6 +176,10 @@ Global
{02878FFB-F4DA-4996-B4A6-308851A837C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{02878FFB-F4DA-4996-B4A6-308851A837C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{02878FFB-F4DA-4996-B4A6-308851A837C6}.Release|Any CPU.Build.0 = Release|Any CPU
{71667539-C845-46D8-8E43-E686D1B184B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{71667539-C845-46D8-8E43-E686D1B184B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{71667539-C845-46D8-8E43-E686D1B184B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{71667539-C845-46D8-8E43-E686D1B184B1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -198,6 +209,7 @@ Global
{66275483-5364-42F9-B7E6-410E6A1B5ECF} = {932D8224-11F6-4D07-B109-DA28AD288A63}
{938803BB-4F6F-4108-BDD1-2AD0180BBDC1} = {932D8224-11F6-4D07-B109-DA28AD288A63}
{02878FFB-F4DA-4996-B4A6-308851A837C6} = {A857AD10-40FF-4303-BEC2-FF1C58D5735E}
{3673B22C-778B-46B0-AB34-338C6F52BBDF} = {3AF739CD-81D8-428D-A08A-0A58372DEBF6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {25728519-5F0F-4973-8A64-0A81EB4EA8D9}
Expand Down
69 changes: 69 additions & 0 deletions next-steps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Next Steps after `azd init`

## Table of Contents

1. [Next Steps](#next-steps)
2. [What was added](#what-was-added)
3. [Billing](#billing)
4. [Troubleshooting](#troubleshooting)

## Next Steps

### Provision infrastructure and deploy application code

Run `azd up` to provision your infrastructure and deploy to Azure in one step (or run `azd provision` then `azd deploy` to accomplish the tasks separately). Visit the service endpoints listed to see your application up-and-running!

To troubleshoot any issues, see [troubleshooting](#troubleshooting).

### Configure CI/CD pipeline

1. Create a workflow pipeline file locally. The following starters are available:
- [Deploy with GitHub Actions](https://github.com/Azure-Samples/azd-starter-bicep/blob/main/.github/workflows/azure-dev.yml)
- [Deploy with Azure Pipelines](https://github.com/Azure-Samples/azd-starter-bicep/blob/main/.azdo/pipelines/azure-dev.yml)
2. Run `azd pipeline config -e <environment name>` to configure the deployment pipeline to connect securely to Azure. An environment name is specified here to configure the pipeline with a different environment for isolation purposes. Run `azd env list` and `azd env set` to reselect the default environment after this step.

## What was added

### Infrastructure configuration

To describe the infrastructure and application, an `azure.yaml` was added with the following directory structure:

```yaml
- azure.yaml # azd project configuration
```

This file contains a single service, which references your project's App Host. When needed, `azd` generates the required infrastructure as code in memory and uses it.

If you would like to see or modify the infrastructure that `azd` uses, run `azd infra synth` to persist it to disk.

If you do this, some additional directories will be created:

```yaml
- infra/ # Infrastructure as Code (bicep) files
- main.bicep # main deployment module
- resources.bicep # resources shared across your application's services
```

In addition, for each project resource referenced by your app host, a `containerApp.tmpl.yaml` file will be created in a directory named `manifests` next the project file. This file contains the infrastructure as code for running the project on Azure Container Apps.

*Note*: Once you have synthesized your infrastructure to disk, changes made to your App Host will not be reflected in the infrastructure. You can re-generate the infrastructure by running `azd infra synth` again. It will prompt you before overwriting files. You can pass `--force` to force `azd infra synth` to overwrite the files without prompting.

*Note*: `azd infra synth` is currently an alpha feature and must be explicitly enabled by running `azd config set alpha.infraSynth on`. You only need to do this once.

## Billing

Visit the *Cost Management + Billing* page in Azure Portal to track current spend. For more information about how you're billed, and how you can monitor the costs incurred in your Azure subscriptions, visit [billing overview](https://learn.microsoft.com/azure/developer/intro/azure-developer-billing).

## Troubleshooting

Q: I visited the service endpoint listed, and I'm seeing a blank or error page.

A: Your service may have failed to start or misconfigured. To investigate further:

1. Click on the resource group link shown to visit Azure Portal.
2. Navigate to the specific Azure Container App resource for the service.
3. Select *Monitoring -> Log stream* under the navigation pane.
4. Observe the log output to identify any errors.
5. If logs are written to disk, examine the local logs or debug the application by using the *Console* to connect to a shell within the running container.

For additional information about setting up your `azd` project, visit our official [docs](https://learn.microsoft.com/azure/developer/azure-developer-cli/make-azd-compatible?pivots=azd-convert).
30 changes: 30 additions & 0 deletions src/Performance/BackgroudScrubber.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Diagnostics;
using System.Globalization;

namespace Store.Checkout.Services;

public class BackgroundScrubber : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
TimeSpan waitTime = TimeSpan.FromSeconds(5);
TimeSpan burnTime = TimeSpan.FromSeconds(5);
try
{
// Just wastes CPU
while (true)
{
await Task.Delay(waitTime, stoppingToken);
Stopwatch stopwatch = Stopwatch.StartNew();
do
{
stoppingToken.ThrowIfCancellationRequested();
Scrubber.SanitizeData($"The secret word is {stopwatch.ElapsedMilliseconds}", '*', CultureInfo.InvariantCulture);
} while (stopwatch.Elapsed < burnTime);
}
}
catch (OperationCanceledException)
{
}
}
}
9 changes: 9 additions & 0 deletions src/Performance/Performance.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
34 changes: 34 additions & 0 deletions src/Performance/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Globalization;
namespace Store.Checkout.Services;

internal class Program
{
private static int Main(string[] args)
{

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHostedService<BackgroundScrubber>();

var app = builder.Build();

app.MapGet("/scrub", () =>
{
string x = Math.PI.ToString();
for (int i = 0; i < 1000; i++)
{
x = x + Random.Shared.Next(0, 10).ToString();
if (i % 50 == 0)
{
Scrubber.SanitizeData("Working...", 'X', CultureInfo.CurrentCulture);
}
}

return Scrubber.SanitizeData($"PI is {x}", 'X', CultureInfo.CurrentCulture);
});

app.MapGet("/", () => "Hello World! V2");
app.Run();

return 0;
}
}
38 changes: 38 additions & 0 deletions src/Performance/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:29073",
"sslPort": 44335
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5097",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7049;http://localhost:5097",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
23 changes: 23 additions & 0 deletions src/Performance/Scrubber.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Globalization;

namespace Store.Checkout.Services;

public class Scrubber
{
internal record LocalizedWord(string Text, CultureInfo Culture);

private static IEnumerable<LocalizedWord> DisallowedWords { get; } = ScrubberHelpers.LoadDisallowedWords();

public static string SanitizeData(string data, char replacementChar, CultureInfo culture)
{
List<string> wordList = DisallowedWords
.Where(word => culture.Equals(CultureInfo.InvariantCulture) || culture.Equals(word.Culture))
.Select(word => word.Text).ToList();

foreach (string word in wordList)
{
data = data.Replace(word, replacementChar.ToString(), ignoreCase: true, culture);
}
return data;
}
}
34 changes: 34 additions & 0 deletions src/Performance/ScrubberHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Globalization;
using static Store.Checkout.Services.Scrubber;

internal static class ScrubberHelpers
{

public static IEnumerable<LocalizedWord> LoadDisallowedWords()
{
// Generate fake data. Could be loaded from resources, file on disk or external service.

var cultures = new CultureInfo[]
{
CultureInfo.GetCultureInfo("en-US"),
CultureInfo.GetCultureInfo("en-GB"),
CultureInfo.GetCultureInfo("fr-FR"),
};

for (int i = 0; i < 3000; i++)
{
yield return new LocalizedWord(Text: DeserializeLocalizedTerm(), Culture: cultures[Random.Shared.Next(0, cultures.Length)]);
}

static string DeserializeLocalizedTerm()
{
Span<char> text = stackalloc char[Random.Shared.Next(4, 12)];
for (int i = 0; i < text.Length; i++)
{
text[i] = (char)Random.Shared.Next('a', 'z' + 1);
}

return new string(text);
}
}
}
8 changes: 8 additions & 0 deletions src/Performance/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
Loading
Loading