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

feat: Add Milvus module #1131

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<PackageVersion Include="Microsoft.Azure.Cosmos" Version="3.32.1"/>
<PackageVersion Include="Microsoft.Azure.Kusto.Data" Version="11.3.3"/>
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.1.3"/>
<PackageVersion Include="Milvus.Client" Version="2.2.2-preview.6"/>
<PackageVersion Include="MongoDB.Driver" Version="2.19.0"/>
<PackageVersion Include="MyCouch" Version="7.6.0"/>
<PackageVersion Include="MySqlConnector" Version="2.2.5"/>
Expand Down
14 changes: 14 additions & 0 deletions Testcontainers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Tests", "tes
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.WebDriver.Tests", "tests\Testcontainers.WebDriver.Tests\Testcontainers.WebDriver.Tests.csproj", "{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Milvus", "src\Testcontainers.Milvus\Testcontainers.Milvus.csproj", "{B024E315-831F-429D-92AA-44B839AC10F4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Milvus.Tests", "tests\Testcontainers.Milvus.Tests\Testcontainers.Milvus.Tests.csproj", "{5247DF94-32F3-4ED6-AE71-6AB4F4078E6D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -556,6 +560,14 @@ Global
{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Release|Any CPU.Build.0 = Release|Any CPU
{B024E315-831F-429D-92AA-44B839AC10F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B024E315-831F-429D-92AA-44B839AC10F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B024E315-831F-429D-92AA-44B839AC10F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B024E315-831F-429D-92AA-44B839AC10F4}.Release|Any CPU.Build.0 = Release|Any CPU
{5247DF94-32F3-4ED6-AE71-6AB4F4078E6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5247DF94-32F3-4ED6-AE71-6AB4F4078E6D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5247DF94-32F3-4ED6-AE71-6AB4F4078E6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5247DF94-32F3-4ED6-AE71-6AB4F4078E6D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5365F780-0E6C-41F0-B1B9-7DC34368F80C} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
Expand Down Expand Up @@ -647,5 +659,7 @@ Global
{1A1983E6-5297-435F-B467-E8E1F11277D6} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{27CDB869-A150-4593-958F-6F26E5391E7C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{B024E315-831F-429D-92AA-44B839AC10F4} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{5247DF94-32F3-4ED6-AE71-6AB4F4078E6D} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
EndGlobalSection
EndGlobal
9 changes: 9 additions & 0 deletions src/Testcontainers.Milvus/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

75 changes: 75 additions & 0 deletions src/Testcontainers.Milvus/MilvusBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
namespace Testcontainers.Milvus;

[PublicAPI]
public class MilvusBuilder : ContainerBuilder<MilvusBuilder, MilvusContainer, MilvusConfiguration>
{
public const string MilvusImage = "milvusdb/milvus:v2.3.10";
public const ushort MilvusGrpcPort = 19530;
public const ushort MilvusManagementPort = 9091;

private string? _etcdEndpoint;

public MilvusBuilder() : this(new MilvusConfiguration())
=> DockerResourceConfiguration = Init().DockerResourceConfiguration;

private MilvusBuilder(MilvusConfiguration dockerResourceConfiguration) : base(dockerResourceConfiguration)
=> DockerResourceConfiguration = dockerResourceConfiguration;

public override MilvusContainer Build()
{
Validate();
return new MilvusContainer(DockerResourceConfiguration, TestcontainersSettings.Logger);
}

public MilvusBuilder WithEtcdEndpoint(string? etcdEndpoint)
{
_etcdEndpoint = etcdEndpoint;
return this;
}

protected override MilvusBuilder Init()
{
var builder = base.Init()
.WithImage(MilvusImage)
.WithEnvironment("COMMON_STORAGETYPE", "local")
.WithCommand("milvus", "run", "standalone")
.WithPortBinding(MilvusGrpcPort, true)
.WithPortBinding(MilvusManagementPort, true)
.WithWaitStrategy(
Wait.ForUnixContainer()
.UntilHttpRequestIsSucceeded(h => h
.ForPort(MilvusManagementPort)
.ForPath("/healthz")));

if (_etcdEndpoint is null)
{
const string etcdYaml = """
listen-client-urls: http://0.0.0.0:2379
advertise-client-urls: http://0.0.0.0:2379
""";

builder = builder
.WithResourceMapping(Encoding.UTF8.GetBytes(etcdYaml), "/milvus/configs/embedEtcd.yaml")
.WithEnvironment("ETCD_USE_EMBED", "true")
.WithEnvironment("ETCD_DATA_DIR", "/var/lib/milvus/etcd")
.WithEnvironment("ETCD_CONFIG_PATH", "/milvus/configs/embedEtcd.yaml");
}
else
{
throw new NotImplementedException();
}
HofmeisterAn marked this conversation as resolved.
Show resolved Hide resolved

return builder;
}

protected override MilvusBuilder Clone(IResourceConfiguration<CreateContainerParameters> resourceConfiguration)
=> Merge(DockerResourceConfiguration, new MilvusConfiguration(resourceConfiguration));

protected override MilvusBuilder Merge(MilvusConfiguration oldValue, MilvusConfiguration newValue)
=> new(new MilvusConfiguration(oldValue, newValue));

protected override MilvusConfiguration DockerResourceConfiguration { get; }

protected override MilvusBuilder Clone(IContainerConfiguration resourceConfiguration)
=> Merge(DockerResourceConfiguration, new MilvusConfiguration(resourceConfiguration));
}
56 changes: 56 additions & 0 deletions src/Testcontainers.Milvus/MilvusConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace Testcontainers.Milvus;

public sealed class MilvusConfiguration : ContainerConfiguration
{

/// <summary>
/// Initializes a new instance of the <see cref="MilvusConfiguration" /> class.
/// </summary>
public MilvusConfiguration()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="MilvusConfiguration" /> class.
/// </summary>
/// <param name="resourceConfiguration">The Docker resource configuration.</param>
public MilvusConfiguration(IResourceConfiguration<CreateContainerParameters> resourceConfiguration)
: base(resourceConfiguration)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="MilvusConfiguration" /> class.
/// </summary>
/// <param name="resourceConfiguration">The Docker resource configuration.</param>
public MilvusConfiguration(IContainerConfiguration resourceConfiguration)
: base(resourceConfiguration)
{
// Passes the configuration upwards to the base implementations to create an updated immutable copy.
}

/// <summary>
/// Initializes a new instance of the <see cref="MilvusConfiguration" /> class.
/// </summary>
/// <param name="resourceConfiguration">The Docker resource configuration.</param>
public MilvusConfiguration(MilvusConfiguration resourceConfiguration)
: this(new MilvusConfiguration(), resourceConfiguration)
{
// Passes the configuration upwards to the base implementations to create an updated immutable copy.
}

/// <summary>
/// Initializes a new instance of the <see cref="MilvusConfiguration" /> class.
/// </summary>
/// <param name="oldValue">The old Docker resource configuration.</param>
/// <param name="newValue">The new Docker resource configuration.</param>
public MilvusConfiguration(MilvusConfiguration oldValue, MilvusConfiguration newValue)
: base(oldValue, newValue)
{
}

/// <summary>
/// An optional endpoint for an external etcd service. If <c>null</c>, uses an embedded etcd service.
/// </summary>
public string? EtcdEndpoint { get; }
}
12 changes: 12 additions & 0 deletions src/Testcontainers.Milvus/MilvusContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Testcontainers.Milvus;

public class MilvusContainer(MilvusConfiguration configuration, ILogger logger)
: DockerContainer(configuration, logger)
{
/// <summary>
/// Gets the Milvus endpoint.
/// </summary>
/// <returns>The Milvus endpoint.</returns>
public Uri GetEndpoint()
=> new Uri($"http://{Hostname}:{GetMappedPublicPort(MilvusBuilder.MilvusGrpcPort)}");
}
14 changes: 14 additions & 0 deletions src/Testcontainers.Milvus/Testcontainers.Milvus.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;netstandard2.0;net462</TargetFrameworks>
HofmeisterAn marked this conversation as resolved.
Show resolved Hide resolved
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" VersionOverride="2023.3.0" PrivateAssets="All"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../Testcontainers/Testcontainers.csproj"/>
</ItemGroup>
</Project>
8 changes: 8 additions & 0 deletions src/Testcontainers.Milvus/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
global using System;
global using System.Text;
global using Docker.DotNet.Models;
global using DotNet.Testcontainers.Builders;
global using DotNet.Testcontainers.Configurations;
global using DotNet.Testcontainers.Containers;
global using JetBrains.Annotations;
global using Microsoft.Extensions.Logging;
9 changes: 9 additions & 0 deletions tests/Testcontainers.Milvus.Tests/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

78 changes: 78 additions & 0 deletions tests/Testcontainers.Milvus.Tests/MilvusContainerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using Docker.DotNet.Models;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Commons;
using DotNet.Testcontainers.Containers;
using Milvus.Client;
using Xunit;

namespace Testcontainers.Milvus.Tests;

public class MilvusContainerTests
{
[Fact]
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
public async Task WithDefaultConfig()
{
var container = new MilvusBuilder()
.WithImage("milvusdb/milvus:v2.3.10")
.Build();

try
{
await container.StartAsync();

var client = new MilvusClient(container.GetEndpoint());
var version = await client.GetVersionAsync();

Assert.Equal("v2.3.10", version);
}
finally
{
await container.StopAsync();
}
}

[Fact]
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
public async Task WithExternalEtcd()
{
var network = new NetworkBuilder().Build();
var etcdContainer = new ContainerBuilder()
.WithImage("quay.io/coreos/etcd:v3.5.5")
.WithNetwork(network)
.WithNetworkAliases("etcd")
.WithCommand(
"etcd",
"-advertise-client-urls=http://127.0.0.1:2379",
"-listen-client-urls=http://0.0.0.0:2379",
"--data-dir=/etcd")
.WithEnvironment("ETCD_AUTO_COMPACTION_MODE", "revision")
.WithEnvironment("ETCD_AUTO_COMPACTION_RETENTION", "1000")
.WithEnvironment("ETCD_QUOTA_BACKEND_BYTES", "4294967296")
.WithEnvironment("ETCD_SNAPSHOT_COUNT", "50000")
.WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged(".*ready to serve client requests.*"))
.Build();

var milvusContainer = new MilvusBuilder()
.WithImage("milvusdb/milvus:v2.3.10")
.WithNetwork(network)
.WithEtcdEndpoint("etcd:2379")
.DependsOn(etcdContainer)
.Build();

await milvusContainer.StartAsync();

try
{

var client = new MilvusClient(milvusContainer.GetEndpoint());
var version = await client.GetVersionAsync();

Assert.Equal("v2.3.10", version);
}
finally
{
await milvusContainer.StopAsync();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<IsPublishable>false</IsPublishable>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
<PackageReference Include="coverlet.collector"/>
<PackageReference Include="xunit.runner.visualstudio"/>
<PackageReference Include="xunit"/>
<PackageReference Include="Milvus.Client"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../src/Testcontainers.Milvus/Testcontainers.Milvus.csproj"/>
<ProjectReference Include="../Testcontainers.Commons/Testcontainers.Commons.csproj"/>
</ItemGroup>
</Project>
Loading