Skip to content

Commit

Permalink
fix up
Browse files Browse the repository at this point in the history
  • Loading branch information
spboyer committed May 6, 2024
2 parents d505a0b + 3b6e295 commit c035fd7
Show file tree
Hide file tree
Showing 23 changed files with 362 additions and 38 deletions.
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:
- main

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/[email protected]

- 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).
4 changes: 2 additions & 2 deletions src/Catalog.API/Apis/CatalogApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,13 @@ public static Results<Ok<PaginatedItems<CatalogItem>>, BadRequest<string>> GetAl
[AsParameters] PaginationRequest paginationRequest,
[AsParameters] CatalogServices services)
{

// JANK: Just to simulate a slow query
for (int i = 0; i < 500; i++)
{
GetAllItems(paginationRequest, services);
}
return GetAllItems(paginationRequest, services);
return GetAllItems(paginationRequest, services);
}
private static string GetImageMimeTypeFromImageFileExtension(string extension) => extension switch
{
Expand Down
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 eShop.Store.Reviews;

public class BackgroundReviewValidation : 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();
ReviewValidation.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 eShop.Store.Reviews;

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

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

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)
{
ReviewValidation.SanitizeData("Working...", 'X', CultureInfo.CurrentCulture);
}
}

return ReviewValidation.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 eShop.Store.Reviews;

public class ReviewValidation
{
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;
}
}
Loading

0 comments on commit c035fd7

Please sign in to comment.