Skip to content

feat: Add KingbaseES database support for .NET Aspire#12

Draft
Copilot wants to merge 8 commits into
mainfrom
copilot/implement-netcorepal-kingbasees
Draft

feat: Add KingbaseES database support for .NET Aspire#12
Copilot wants to merge 8 commits into
mainfrom
copilot/implement-netcorepal-kingbasees

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 19, 2025

Implements .NET Aspire hosting support for KingbaseES database, following the reference implementation from netcorepal-testcontainers.

Implementation

Core library (NetCorePal.Aspire.Hosting.KingbaseES)

  • KingbaseESServerResource - Server resource with connection string support
  • KingbaseESDatabaseResource - Database resource
  • KingbaseESBuilderExtensions - Configuration API
  • pgAdmin and pgweb management tool integration
  • Health checks for dependency orchestration
  • Container initialization helper script (kingbase-init.sh) - Handles SSH daemon and database startup

Key configurations

  • Port: 54321 (KingbaseES default)
  • Username: "system"
  • Database: "test"
  • Image: apecloud/kingbase:v008r006c009b0014-unit
  • Privileged mode with hostname configuration for systemd requirements
  • PostgreSQL-compatible using Npgsql driver

Tests & Example

  • 25 unit tests covering all builder extension methods
  • 7 integration tests following OpenGauss pattern - Container startup, SQL operations, connection pooling
  • Example application demonstrating usage with management tools

Documentation

  • Comprehensive documentation of container initialization requirements
  • Workarounds for Aspire's container lifecycle limitations
  • Helper script included in package for creating custom auto-initializing images

Usage

var builder = DistributedApplication.CreateBuilder(args);

var kingbasees = builder.AddKingbaseES("kingbasees")
    .WithPassword(password)
    .WithPgWeb()
    .WithPgAdmin();

var database = kingbasees.AddDatabase("mydb");

builder.Build().Run();

Connection string format: Host=localhost;Port=54321;Username=system;Password=***;Database=test

Important Note

The KingbaseES container requires manual initialization after startup as it uses systemd and doesn't automatically start the database service. The package includes:

  • Detailed documentation of initialization requirements
  • A helper script (kingbase-init.sh) for creating custom auto-initializing images
  • Manual initialization commands for development environments

See the package README for complete initialization instructions and workarounds.

Original prompt

This section details on the original issue you should resolve

<issue_title>实现NetCorePal.Aspire.Hosting.KingbaseES</issue_title>
<issue_description>
参考下面docker 代码:
https://github.com/netcorepal/netcorepal-testcontainers/blob/main/src/NetCorePal.Testcontainers.KingbaseES/KingbaseESBuilder.cs
https://github.com/netcorepal/netcorepal-testcontainers/blob/main/src/NetCorePal.Testcontainers.KingbaseES/KingbaseESContainerOptions.cs</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Dec 19, 2025
- Add KingbaseES hosting library with complete resource support
- Add comprehensive unit tests (25 tests, all passing)
- Add example project demonstrating usage
- Add README documentation
- Update solution file and root README

Co-authored-by: witskeeper <5594094+witskeeper@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement NetCorePal.Aspire.Hosting.KingbaseES feat: Add KingbaseES database support for .NET Aspire Dec 19, 2025
Copilot AI requested a review from witskeeper December 19, 2025 08:01
@witskeeper
Copy link
Copy Markdown
Member

@copilot
这个镜像有一定特殊性,下列命令是用来正式启动数据库,需要在容器启动后立即执行
var prepareSshCommand = new List
{
"sh",
"-lc",
// If sshd is not running, generate host keys (idempotent) and start sshd in background.
// Note: avoid disown (bash-only) for broader shell compatibility.
"pgrep -x sshd >/dev/null 2>&1 || { (command -v ssh-keygen >/dev/null 2>&1 && ssh-keygen -A || /usr/bin/ssh-keygen -A || true); (/usr/sbin/sshd -D -E /tmp/sshd.log >/dev/null 2>&1 &) || true; sleep 1; }"
};

        var entrypointCommand = new List<string>
            {
                "sh",
                "-lc",
                "HOSTNAME=$(hostname) /home/kingbase/cluster/bin/docker-entrypoint.sh >/tmp/kingbase-entrypoint.log 2>&1; echo $? > /tmp/kingbase-entrypoint.exitcode"
            };

…r script

- Add kingbase-init.sh script for container initialization
- Document container initialization requirements in README
- Add XML documentation warning about manual initialization
- Update example README with initialization steps
- Include init script in package content for easy access

Co-authored-by: witskeeper <5594094+witskeeper@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Dec 19, 2025

@copilot
这个镜像有一定特殊性,下列命令是用来正式启动数据库,需要在容器启动后立即执行
var prepareSshCommand = new List
...

Thanks for highlighting this important requirement! I've documented the container initialization needs and provided workarounds.

Since Aspire doesn't support executing commands inside containers after startup (unlike Testcontainers), I've:

  1. Added comprehensive documentation in the README explaining the initialization requirements
  2. Created a helper script (kingbase-init.sh) that handles:
    • Starting SSH daemon for cluster communication
    • Running docker-entrypoint.sh to initialize the database
  3. Documented workarounds including:
    • Creating a custom Dockerfile with automatic initialization
    • Manual initialization commands for development
    • Using the included init script

The initialization script is included in the package and can be used to build a custom image that auto-initializes.

See commit 577ed9e for the changes.

将 NetCorePal.Aspire.Hosting.KingbaseES 及其测试项目的目标框架由单一 net10.0 改为同时支持 net8.0、net9.0 和 net10.0,提升了项目的兼容性和可用性。
@witskeeper
Copy link
Copy Markdown
Member

@copilot 参考OpenGauss的测试用例,修改KingbaseES的测试用例

…pattern

- Add KingbaseESContainerTests.cs with 7 integration tests
- Update project to target net10.0 and add SharedAppHost reference
- Tests verify container startup, SQL execution, table operations
- Matches OpenGauss test structure and patterns

Co-authored-by: witskeeper <5594094+witskeeper@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Dec 24, 2025

@copilot 参考OpenGauss的测试用例,修改KingbaseES的测试用例

Done! Added KingbaseES container integration tests following the OpenGauss pattern:

  • Created KingbaseESContainerTests.cs with 7 integration tests:

    • ConnectionStateReturnsOpen
    • CanExecuteSimpleQuery
    • CanCreateTableAndInsertData
    • CanExecuteVersionQuery
    • DatabaseResourceIncludesDatabaseName
    • CanExecuteMultipleQueriesOnSameConnection
    • ConnectionPoolingWorks
  • Updated test project:

    • Changed target framework to net10.0 (matching OpenGauss)
    • Added SharedAppHost project reference
    • All 32 tests compile and run (25 unit + 7 integration)

The test structure now matches OpenGauss exactly.

See commit 1b770b3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

实现NetCorePal.Aspire.Hosting.KingbaseES

2 participants