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

Adds Azurite support #410

Merged
merged 3 commits into from
Oct 24, 2023
Merged

Adds Azurite support #410

merged 3 commits into from
Oct 24, 2023

Conversation

bjorkstromm
Copy link
Contributor

I toyed a little with creating resources and thought Azurite would be good for local dev.

@davidfowl
Copy link
Member

This should be part of the azure package. Thanks for the contribution!

@davidfowl
Copy link
Member

This is very cool but we should model this into the AddAzureStorage somehow. Maybe as an overload or as another method.

@bjorkstromm
Copy link
Contributor Author

This is very cool but we should model this into the AddAzureStorage somehow. Maybe as an overload or as another method.

Thanks for the comments. I've integrated it i Aspire.Hosting.Azure now. I added a extension method UseEmulator which registers annotations on the Azure storage resource. I also took measures to ensure emulators are not provisioned using AzureProvisioner.

Example AppHost

var builder = DistributedApplication.CreateBuilder(args);

var azurite = builder.AddAzureStorage("azurite")
                     .UseEmulator();

var blob = azurite.AddBlobs("blobs");
var queue = azurite.AddQueues("queues");
var table = azurite.AddTables("tables");

builder.AddProject<Projects.Web>("web")
       .WithReference(blob)
       .WithReference(queue)
       .WithReference(table);

builder.Build().Run();

Example web api

using Azure.Data.Tables;
using Azure.Storage.Blobs;
using Azure.Storage.Queues;

var builder = WebApplication.CreateBuilder(args);
builder.AddAzureTableService("tables");
builder.AddAzureBlobService("blobs");
builder.AddAzureQueueService("queues");

var app = builder.Build();

app.MapGet("/tables", (TableServiceClient client) => client.Query());
app.MapGet("/blobs", (BlobServiceClient client) => client.GetBlobContainers());
app.MapGet("/queues", (QueueServiceClient client) => client.GetQueues());

app.Run();

@davidfowl
Copy link
Member

This is beautiful, but you have to resolve some merge conflicts 😄

@mitchdenny
Copy link
Member

Agreed. This looks pretty good. I'm somewhat uncomfortable with the IsEmulator property but that is mostly because I don't know how the storage resource type will evolve. For now I think it can stay until we get a good sense on whether it is in the right place or note.

In terms of verbs applied to extension methods we now have WithX, UseX, and AddX. I think it would be good to establish some guidelines around which is appropriate when.

Usage / Verb AddX WithX UseX
App builder Use to add resources and lifecycle hooks to the application model. Not used. Not used.
Resource builder Add sub-resources to an existing resource Use to add annotations (e.g. bindings, references) to a resource. Change underlying hosting model for resource (e.g. container vs. real resource via provisioner).

@davidfowl
Copy link
Member

Good point @mitchdenny. I think Use or As would apply here. UseEmulator/AsEmulator, I think I prefer Use

@davidfowl
Copy link
Member

davidfowl commented Oct 24, 2023

There are some more merge conflicts to fix because of the rename but they shouldn't affect you much. 2 changes you should make:

  1. Add a ShouldProvision to IAzureResourceProvisioner and use it in the main loop, use it from here
    if (provisoner.ConfigureResource(configuration, resource))
    .
  2. Then implement it in the AzureStorageProvisioner

That will allow you to skip provisioning storage when the emulator is changed.

Lets get this merged soon! Sorry for the churn.

- Adds ShouldProvision to IAzureResourceProvisioner, which returns true by default. Will return false if Azurite is used for Azure storage
@bjorkstromm
Copy link
Contributor Author

@davidfowl Thanks for the review comments. I've rebased, fixed merge conflicts and addressed your feedback comments.

Starting AppHost with AzureProvisioning on will now yield the following logs if emulator is used.

info: Aspire.Hosting.Azure.AzureProvisioner[0]
      Skipping azurite because it is not configured to be provisioned.
warn: Aspire.Hosting.Azure.AzureProvisioner[0]
      No provisioner found for AzureBlobStorageResource skipping.
warn: Aspire.Hosting.Azure.AzureProvisioner[0]
      No provisioner found for AzureQueueStorageResource skipping.
warn: Aspire.Hosting.Azure.AzureProvisioner[0]
      No provisioner found for AzureTableStorageResource skipping.

@davidfowl davidfowl merged commit e1bf3ae into dotnet:main Oct 24, 2023
4 checks passed
@davidfowl
Copy link
Member

Very clean, this is a high quality PR 😄. Thanks!

@bjorkstromm bjorkstromm deleted the feature/azurite branch October 24, 2023 15:23
@danmoseley danmoseley added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Nov 16, 2023
@github-actions github-actions bot locked and limited conversation to collaborators May 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants