forked from dotnet/aspire
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding bicep resource type (dotnet#2056)
* Added bicep resource primitive for azure resources - Added new resource types to aid in the transition to the new bicep resource primitive - Updated a BicepProvisioner to AzureProvisioning - Added lots of bicep files --------- Co-authored-by: Mitch Denny <midenn@microsoft.com>
- Loading branch information
1 parent
e86957f
commit 55c1921
Showing
56 changed files
with
3,356 additions
and
10 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
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
21 changes: 21 additions & 0 deletions
21
playground/bicep/BicepSample.ApiService/BicepSample.ApiService.csproj
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,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\Components\Aspire.Azure.Data.Tables\Aspire.Azure.Data.Tables.csproj" /> | ||
<ProjectReference Include="..\..\..\src\Components\Aspire.Azure.Messaging.ServiceBus\Aspire.Azure.Messaging.ServiceBus.csproj" /> | ||
<ProjectReference Include="..\..\..\src\Components\Aspire.Azure.Storage.Blobs\Aspire.Azure.Storage.Blobs.csproj" /> | ||
<ProjectReference Include="..\..\..\src\Components\Aspire.Azure.Storage.Queues\Aspire.Azure.Storage.Queues.csproj" /> | ||
<ProjectReference Include="..\..\..\src\Components\Aspire.Microsoft.Azure.Cosmos\Aspire.Microsoft.Azure.Cosmos.csproj" /> | ||
<ProjectReference Include="..\..\..\src\Components\Aspire.Microsoft.EntityFrameworkCore.SqlServer\Aspire.Microsoft.EntityFrameworkCore.SqlServer.csproj" /> | ||
<ProjectReference Include="..\..\..\src\Components\Aspire.Npgsql.EntityFrameworkCore.PostgreSQL\Aspire.Npgsql.EntityFrameworkCore.PostgreSQL.csproj" /> | ||
<ProjectReference Include="..\..\..\src\Components\Aspire.StackExchange.Redis\Aspire.StackExchange.Redis.csproj" /> | ||
<ProjectReference Include="..\..\Playground.ServiceDefaults\Playground.ServiceDefaults.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
6 changes: 6 additions & 0 deletions
6
playground/bicep/BicepSample.ApiService/BicepSample.ApiService.http
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,6 @@ | ||
@CosmosEndToEnd.ApiService_HostAddress = http://localhost:5193 | ||
|
||
GET {{SqlServerEndToEnd.ApiService_HostAddress}}/weatherforecast/ | ||
Accept: application/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Text.Json; | ||
using Azure.Data.Tables; | ||
using Azure.Messaging.ServiceBus; | ||
using Azure.Storage.Blobs; | ||
using Azure.Storage.Queues; | ||
using Microsoft.Azure.Cosmos; | ||
using Microsoft.EntityFrameworkCore; | ||
using StackExchange.Redis; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.AddServiceDefaults(); | ||
|
||
builder.AddSqlServerDbContext<MyDbContext>("db"); | ||
builder.AddNpgsqlDbContext<MyPgDbContext>("db2"); | ||
builder.AddAzureCosmosDB("db3", settings => settings.IgnoreEmulatorCertificate = true); | ||
builder.AddRedis("redis"); | ||
builder.AddAzureBlobService("blob"); | ||
builder.AddAzureTableService("table"); | ||
builder.AddAzureQueueService("queue"); | ||
builder.AddAzureServiceBus("sb"); | ||
|
||
var app = builder.Build(); | ||
|
||
app.MapGet("/", async (MyDbContext context) => | ||
{ | ||
// You wouldn't normally do this on every call, | ||
// but doing it here just to make this simple. | ||
context.Database.EnsureCreated(); | ||
var entry = new Entry(); | ||
await context.Entries.AddAsync(entry); | ||
await context.SaveChangesAsync(); | ||
var entries = await context.Entries.ToListAsync(); | ||
return new | ||
{ | ||
totalEntries = entries.Count, | ||
entries = entries | ||
}; | ||
}); | ||
|
||
app.MapGet("/pg", async (MyPgDbContext context) => | ||
{ | ||
// You wouldn't normally do this on every call, | ||
// but doing it here just to make this simple. | ||
context.Database.EnsureCreated(); | ||
var entry = new Entry(); | ||
await context.Entries.AddAsync(entry); | ||
await context.SaveChangesAsync(); | ||
var entries = await context.Entries.ToListAsync(); | ||
return new | ||
{ | ||
totalEntries = entries.Count, | ||
entries = entries | ||
}; | ||
}); | ||
|
||
app.MapGet("/cosmos", async (CosmosClient cosmosClient) => | ||
{ | ||
var db = (await cosmosClient.CreateDatabaseIfNotExistsAsync("db3")).Database; | ||
var container = (await db.CreateContainerIfNotExistsAsync("entries", "/Id")).Container; | ||
// Add an entry to the database on each request. | ||
var newEntry = new Entry(); | ||
await container.CreateItemAsync(newEntry); | ||
var entries = new List<Entry>(); | ||
var iterator = container.GetItemQueryIterator<Entry>(requestOptions: new QueryRequestOptions() { MaxItemCount = 5 }); | ||
var batchCount = 0; | ||
while (iterator.HasMoreResults) | ||
{ | ||
batchCount++; | ||
var batch = await iterator.ReadNextAsync(); | ||
foreach (var entry in batch) | ||
{ | ||
entries.Add(entry); | ||
} | ||
} | ||
return new | ||
{ | ||
batchCount = batchCount, | ||
totalEntries = entries.Count, | ||
entries = entries | ||
}; | ||
}); | ||
|
||
app.MapGet("/redis", async (IConnectionMultiplexer connection) => | ||
{ | ||
var database = connection.GetDatabase(); | ||
var entry = new Entry(); | ||
// Add an entry to the list on each request. | ||
await database.ListRightPushAsync("entries", JsonSerializer.SerializeToUtf8Bytes(entry)); | ||
var entries = new List<Entry>(); | ||
var list = await database.ListRangeAsync("entries"); | ||
foreach (var item in list) | ||
{ | ||
entries.Add(JsonSerializer.Deserialize<Entry>((string)item!)!); | ||
} | ||
return entries; | ||
}); | ||
|
||
app.MapGet("/blobs", async (BlobServiceClient blobServiceClient) => | ||
{ | ||
var container = blobServiceClient.GetBlobContainerClient("blobs"); | ||
await container.CreateIfNotExistsAsync(); | ||
var entry = new Entry(); | ||
var blob = container.GetBlobClient(entry.Id.ToString()); | ||
// Add an entry to the blob on each request. | ||
await blob.UploadAsync(new BinaryData(entry)); | ||
var entries = new List<Entry>(); | ||
await foreach (var item in container.GetBlobsAsync()) | ||
{ | ||
var client = container.GetBlobClient(item.Name); | ||
using var content = await client.OpenReadAsync(); | ||
entries.Add(JsonSerializer.Deserialize<Entry>(content)!); | ||
} | ||
return entries; | ||
}); | ||
|
||
app.MapGet("/tables", async (TableServiceClient tableServiceClient) => | ||
{ | ||
var table = tableServiceClient.GetTableClient("entries"); | ||
await table.CreateIfNotExistsAsync(); | ||
var entry = new Entry(); | ||
var tableEntry = new TableEntity(entry.Id.ToString(), entry.Id.ToString()) | ||
{ | ||
{ "data", JsonSerializer.Serialize(entry) } | ||
}; | ||
// Add an entry to the table on each request. | ||
await table.AddEntityAsync(tableEntry); | ||
var entries = new List<Entry>(); | ||
await foreach (var item in table.QueryAsync<TableEntity>()) | ||
{ | ||
entries.Add(JsonSerializer.Deserialize<Entry>((string)item["data"])!); | ||
} | ||
return entries; | ||
}); | ||
|
||
app.MapGet("/queues", async (QueueServiceClient queueServiceClient, CancellationToken cancellationToken) => | ||
{ | ||
var queue = queueServiceClient.GetQueueClient("entries"); | ||
await queue.CreateIfNotExistsAsync(cancellationToken: cancellationToken); | ||
var entry = new Entry(); | ||
// Add an entry to the queue on each request. | ||
await queue.SendMessageAsync(new BinaryData(entry), cancellationToken: cancellationToken); | ||
var entries = new List<Entry>(); | ||
var message = await queue.ReceiveMessageAsync(cancellationToken: cancellationToken); | ||
if (message != null) | ||
{ | ||
entries.Add(message.Value.Body.ToObjectFromJson<Entry>()); | ||
} | ||
return entries; | ||
}); | ||
|
||
app.MapGet("/servicebus", async (ServiceBusClient serviceBusClient, CancellationToken cancellationToken) => | ||
{ | ||
await using var sender = serviceBusClient.CreateSender("queue1"); | ||
var entry = new Entry(); | ||
// Add an entry to the queue on each request. | ||
await sender.SendMessageAsync(new ServiceBusMessage(new BinaryData(entry)), cancellationToken); | ||
var entries = new List<Entry>(); | ||
await using var receiver = serviceBusClient.CreateReceiver("queue1"); | ||
var message = await receiver.ReceiveMessageAsync(cancellationToken: cancellationToken); | ||
if (message != null) | ||
{ | ||
entries.Add(message.Body.ToObjectFromJson<Entry>()); | ||
} | ||
return entries; | ||
}); | ||
|
||
app.Run(); | ||
|
||
public class MyPgDbContext(DbContextOptions<MyPgDbContext> options) : DbContext(options) | ||
{ | ||
public DbSet<Entry> Entries { get; set; } | ||
} | ||
|
||
public class MyDbContext(DbContextOptions<MyDbContext> options) : DbContext(options) | ||
{ | ||
public DbSet<Entry> Entries { get; set; } | ||
} | ||
|
||
public class Entry | ||
{ | ||
[Newtonsoft.Json.JsonProperty("id")] | ||
public Guid Id { get; set; } = Guid.NewGuid(); | ||
} |
14 changes: 14 additions & 0 deletions
14
playground/bicep/BicepSample.ApiService/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "http://localhost:5180", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
playground/bicep/BicepSample.ApiService/appsettings.Development.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
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 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
23 changes: 23 additions & 0 deletions
23
playground/bicep/BicepSample.AppHost/BicepSample.AppHost.csproj
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 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsAspireHost>true</IsAspireHost> | ||
<UserSecretsId>dafae173-3ac0-4100-8cab-602852cb28dd</UserSecretsId> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="$(SharedDir)KnownResourceNames.cs" Link="KnownResourceNames.cs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\Aspire.Dashboard\Aspire.Dashboard.csproj" /> | ||
<ProjectReference Include="..\..\..\src\Aspire.Hosting.Azure.Provisioning\Aspire.Hosting.Azure.Provisioning.csproj" IsAspireProjectResource="false" /> | ||
|
||
<ProjectReference Include="..\BicepSample.ApiService\BicepSample.ApiService.csproj" /> | ||
</ItemGroup> | ||
|
||
</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,8 @@ | ||
<Project> | ||
|
||
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" /> | ||
|
||
<!-- NOTE: This line is only required because we are using P2P references, not NuGet. It will not exist in real apps. --> | ||
<Import Project="../../../src/Aspire.Hosting/build/Aspire.Hosting.props" /> | ||
|
||
</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,9 @@ | ||
<Project> | ||
|
||
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" /> | ||
|
||
<!-- NOTE: These lines are only required because we are using P2P references, not NuGet. They will not exist in real apps. --> | ||
<Import Project="..\..\..\src\Aspire.Hosting\build\Aspire.Hosting.targets" /> | ||
<Import Project="..\..\..\src\Aspire.Hosting.Sdk\SDK\Sdk.targets" /> | ||
|
||
</Project> |
Oops, something went wrong.