Skip to content

Commit 360df51

Browse files
authored
Merge pull request #39 from codebytes/aspire
Refactor project structure and add initial files
2 parents ad91fb1 + 1dbbdfb commit 360df51

38 files changed

+1072
-0
lines changed

.github/workflows/azure-dev.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
on:
2+
workflow_dispatch:
3+
push:
4+
# Run when commits are pushed to mainline branch (main or master)
5+
# Set this to the mainline branch you are using
6+
branches:
7+
- main
8+
- master
9+
10+
# GitHub Actions workflow to deploy to Azure using azd
11+
# To configure required secrets for connecting to Azure, simply run `azd pipeline config`
12+
13+
# Set up permissions for deploying with secretless Azure federated credentials
14+
# https://learn.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-portal%2Clinux#set-up-azure-login-with-openid-connect-authentication
15+
permissions:
16+
id-token: write
17+
contents: read
18+
19+
jobs:
20+
build:
21+
runs-on: ubuntu-latest
22+
env:
23+
AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }}
24+
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
25+
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
26+
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
27+
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
32+
- name: Install azd
33+
uses: Azure/[email protected]
34+
35+
- name: Log in with Azure (Federated Credentials)
36+
if: ${{ env.AZURE_CLIENT_ID != '' }}
37+
run: |
38+
azd auth login `
39+
--client-id "$Env:AZURE_CLIENT_ID" `
40+
--federated-credential-provider "github" `
41+
--tenant-id "$Env:AZURE_TENANT_ID"
42+
shell: pwsh
43+
44+
- name: Log in with Azure (Client Credentials)
45+
if: ${{ env.AZURE_CREDENTIALS != '' }}
46+
run: |
47+
$info = $Env:AZURE_CREDENTIALS | ConvertFrom-Json -AsHashtable;
48+
Write-Host "::add-mask::$($info.clientSecret)"
49+
50+
azd auth login `
51+
--client-id "$($info.clientId)" `
52+
--client-secret "$($info.clientSecret)" `
53+
--tenant-id "$($info.tenantId)"
54+
shell: pwsh
55+
env:
56+
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
57+
58+
- name: Provision Infrastructure
59+
run: azd provision --no-prompt
60+
env:
61+
AZD_INITIAL_ENVIRONMENT_CONFIG: ${{ secrets.AZD_INITIAL_ENVIRONMENT_CONFIG }}
62+
63+
- name: Deploy Application
64+
run: azd deploy --no-prompt

aspire-sample/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.azure
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
// Add service defaults & Aspire components.
4+
builder.AddServiceDefaults();
5+
6+
// Add services to the container.
7+
builder.Services.AddProblemDetails();
8+
9+
var app = builder.Build();
10+
11+
// Configure the HTTP request pipeline.
12+
app.UseExceptionHandler();
13+
14+
var summaries = new[]
15+
{
16+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
17+
};
18+
19+
app.MapGet("/weatherforecast", () =>
20+
{
21+
var forecast = Enumerable.Range(1, 5).Select(index =>
22+
new WeatherForecast
23+
(
24+
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
25+
Random.Shared.Next(-20, 55),
26+
summaries[Random.Shared.Next(summaries.Length)]
27+
))
28+
.ToArray();
29+
return forecast;
30+
});
31+
32+
app.MapDefaultEndpoints();
33+
34+
app.Run();
35+
36+
record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
37+
{
38+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
39+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"http": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": true,
8+
"launchUrl": "weatherforecast",
9+
"applicationUrl": "http://localhost:5359",
10+
"environmentVariables": {
11+
"ASPNETCORE_ENVIRONMENT": "Development"
12+
}
13+
},
14+
"https": {
15+
"commandName": "Project",
16+
"dotnetRunMessages": true,
17+
"launchBrowser": true,
18+
"launchUrl": "weatherforecast",
19+
"applicationUrl": "https://localhost:7535;http://localhost:5359",
20+
"environmentVariables": {
21+
"ASPNETCORE_ENVIRONMENT": "Development"
22+
}
23+
}
24+
}
25+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "*"
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\aspire-sample.ServiceDefaults\aspire-sample.ServiceDefaults.csproj" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var builder = DistributedApplication.CreateBuilder(args);
2+
3+
var apiService = builder.AddProject<Projects.aspire_sample_ApiService>("apiservice");
4+
5+
builder.AddProject<Projects.aspire_sample_Web>("webfrontend")
6+
.WithExternalHttpEndpoints()
7+
.WithReference(apiService);
8+
9+
builder.Build().Run();
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"https": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": true,
8+
"applicationUrl": "https://localhost:17191;http://localhost:15185",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development",
11+
"DOTNET_ENVIRONMENT": "Development",
12+
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21014",
13+
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22193"
14+
}
15+
},
16+
"http": {
17+
"commandName": "Project",
18+
"dotnetRunMessages": true,
19+
"launchBrowser": true,
20+
"applicationUrl": "http://localhost:15185",
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development",
23+
"DOTNET_ENVIRONMENT": "Development",
24+
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19219",
25+
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20058"
26+
}
27+
}
28+
}
29+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)