Skip to content

Commit 0b672c6

Browse files
Harold-Morgandavidfowlaaronpowell
authored
Add Minio hosting/client integration (#691)
* Minio integration raw draft * Tests draft * Refinement + project structure + tests * Documentation draft * Tests added to tests.yaml * Fix ubuntu build * README.md final draft * DataVolume api added * Password/user/port parameters api changed * Update src/CommunityToolkit.Aspire.Hosting.Minio/MinioContainerResource.cs * Randomize ports fxd + new healthcheck * Fix tests * Fix slnx support * Naming inconsistency fxd * Update src/CommunityToolkit.Aspire.Minio.Client/README.md Co-authored-by: Aaron Powell <me@aaron-powell.com> * Apiservice test timeout * ApiServiceCreateData test now checks file upload/download result * MinioContainerResource.cs class structure revamped --------- Co-authored-by: David Fowler <davidfowl@gmail.com> Co-authored-by: Aaron Powell <me@aaron-powell.com>
1 parent ebfd5be commit 0b672c6

35 files changed

+1962
-268
lines changed

.github/workflows/tests.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
Hosting.SqlServer.Extensions.Tests,
5252
Hosting.Sqlite.Tests,
5353
Hosting.k6.Tests,
54+
Hosting.Minio.Tests,
5455

5556
# Client integration tests
5657
EventStore.Tests,
@@ -61,6 +62,7 @@ jobs:
6162
Microsoft.EntityFrameworkCore.Sqlite.Tests,
6263
OllamaSharp.Tests,
6364
RavenDB.Client.Tests,
65+
Minio.Client.Tests,
6466
]
6567

6668
steps:

CODEOWNERS

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,14 @@
102102
# CommunityToolkit.Aspire.Hosting.SqlServer.Extensions
103103
/src/CommunityToolkit.Aspire.Hosting.SqlServer.Extensions/ @Alirexaa
104104
/tests/CommunityToolkit.Aspire.Hosting.SqlServer.Extensions.Tests/ @Alirexaa
105-
/examples/sqlserver-ext/ @Alirexaa
105+
/examples/sqlserver-ext/ @Alirexaa
106+
107+
# CommunityToolkit.Aspire.Minio.Client
108+
# CommunityToolkit.Aspire.Hosting.Minio
109+
110+
/examples/minio/ @Harold-Morgan
111+
/src/CommunityToolkit.Aspire.Hosting.Minio/ @Harold-Morgan
112+
/tests/CommunityToolkit.Aspire.Hosting.Minio.Tests/ @Harold-Morgan
113+
114+
/src/CommunityToolkit.Aspire.Minio.Client/ @Harold-Morgan
115+
/tests/CommunityToolkit.Aspire.Minio.Client.Tests/ @Harold-Morgan

CommunityToolkit.Aspire.slnx

Lines changed: 239 additions & 230 deletions
Large diffs are not rendered by default.

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<PackageVersion Include="JsonSchema.Net" Version="7.3.4" />
6565
<PackageVersion Include="OllamaSharp" Version="5.1.12" />
6666
<PackageVersion Include="OpenFeature.Contrib.GOFeatureFlag" Version="0.2.1" />
67+
<PackageVersion Include="Minio" Version="6.0.4" />
6768
<PackageVersion Include="MassTransit" Version="8.4.0" />
6869
<PackageVersion Include="MassTransit.ActiveMQ" Version="8.4.0" />
6970
<PackageVersion Include="MassTransit.RabbitMQ" Version="8.4.0" />

README.md

Lines changed: 47 additions & 37 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<ImplicitUsings>enable</ImplicitUsings>
5+
<Nullable>enable</Nullable>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Minio.Client\CommunityToolkit.Aspire.Minio.Client.csproj" />
10+
<ProjectReference Include="..\CommunityToolkit.Aspire.Hosting.Minio.ServiceDefaults\CommunityToolkit.Aspire.Hosting.Minio.ServiceDefaults.csproj" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Minio;
3+
using Minio.DataModel.Args;
4+
5+
var builder = WebApplication.CreateBuilder(args);
6+
7+
builder.AddServiceDefaults();
8+
9+
builder.AddMinioClient("minio");
10+
11+
var app = builder.Build();
12+
13+
app.MapDefaultEndpoints();
14+
15+
app.MapGet("/", () => "Hello World!");
16+
17+
app.MapPut("/buckets/{bucketName}", async (string bucketName, [FromServices] IMinioClient minioClient) =>
18+
{
19+
var mbArgs = new MakeBucketArgs()
20+
.WithBucket(bucketName);
21+
await minioClient.MakeBucketAsync(mbArgs);
22+
23+
return Results.Ok();
24+
});
25+
26+
app.MapGet("/buckets/{bucketName}", async (string bucketName, [FromServices] IMinioClient minioClient) =>
27+
{
28+
var exists = await minioClient.BucketExistsAsync(new BucketExistsArgs().WithBucket(bucketName));
29+
30+
if(exists)
31+
return Results.Ok();
32+
return Results.NotFound();
33+
});
34+
35+
app.MapPost("/buckets/{bucketName}/{fileName}/upload",
36+
async ([FromRoute] string bucketName,
37+
[FromRoute] string fileName,
38+
HttpRequest request,
39+
[FromServices] IMinioClient minioClient) =>
40+
{
41+
var memstream = new MemoryStream();
42+
43+
await request.Body.CopyToAsync(memstream);
44+
45+
var length = memstream.Length;
46+
memstream.Seek(0, SeekOrigin.Begin);
47+
48+
var putObjectArgs = new PutObjectArgs()
49+
.WithObject(fileName)
50+
.WithBucket(bucketName)
51+
.WithStreamData(memstream)
52+
.WithObjectSize(length);
53+
54+
await minioClient.PutObjectAsync(putObjectArgs);
55+
56+
return Results.Ok();
57+
}).DisableAntiforgery();
58+
59+
app.MapGet("/buckets/{bucketName}/{fileName}/download",
60+
async (string bucketName, string fileName, [FromServices] IMinioClient minioClient) =>
61+
{
62+
var memStream = new MemoryStream();
63+
64+
var getObjectArgs = new GetObjectArgs()
65+
.WithBucket(bucketName)
66+
.WithObject(fileName)
67+
.WithCallbackStream(stream =>
68+
{
69+
stream.CopyToAsync(memStream);
70+
});
71+
72+
await minioClient.GetObjectAsync(getObjectArgs);
73+
74+
return Results.File(memStream.ToArray(), "application/octet-stream", fileName);
75+
});
76+
77+
app.Run();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"http": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": true,
8+
"applicationUrl": "http://localhost:52323",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development"
11+
}
12+
},
13+
"https": {
14+
"commandName": "Project",
15+
"dotnetRunMessages": true,
16+
"launchBrowser": true,
17+
"applicationUrl": "https://localhost:7042;http://localhost:52323",
18+
"environmentVariables": {
19+
"ASPNETCORE_ENVIRONMENT": "Development"
20+
}
21+
}
22+
}
23+
}
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Sdk Name="Aspire.AppHost.Sdk" Version="$(AspireAppHostSdkVersion)"/>
3+
4+
<PropertyGroup>
5+
<OutputType>Exe</OutputType>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<IsAspireHost>true</IsAspireHost>
9+
<UserSecretsId>bfe6b134-1a06-4449-a146-ba3cdb0d02a5</UserSecretsId>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Aspire.Hosting.AppHost" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.Minio\CommunityToolkit.Aspire.Hosting.Minio.csproj" IsAspireProjectResource="false" />
18+
<ProjectReference Include="..\CommunityToolkit.Aspire.Hosting.Minio.ApiService\CommunityToolkit.Aspire.Hosting.Minio.ApiService.csproj" />
19+
</ItemGroup>
20+
21+
</Project>

0 commit comments

Comments
 (0)