forked from Azure-Samples/eShopOnAzure
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
362 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -491,3 +491,4 @@ $RECYCLE.BIN/ | |
/playwright/.auth/ | ||
/user.json | ||
.azure | ||
/src/eShop.AppHost/Properties/launchSettings.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.