Skip to content

Add Docker Compose file hosting integration#1277

Open
curiousvlxd wants to merge 1 commit intoCommunityToolkit:mainfrom
curiousvlxd:main
Open

Add Docker Compose file hosting integration#1277
curiousvlxd wants to merge 1 commit intoCommunityToolkit:mainfrom
curiousvlxd:main

Conversation

@curiousvlxd
Copy link
Copy Markdown

Closes #1276

Overview

Adds a new hosting integration that imports existing Docker Compose files into the Aspire resource graph. Compose services become first-class Aspire resources with full support for WaitFor, dependency management, health checks, and dashboard visibility.

Features

  • Runtime API: builder.AddCompose(".infra/compose.yml") with string-based indexer access
  • Typed API: Source generator creates Compose.* wrapper classes with IntelliSense properties per service
  • Compose format support: v1 (legacy), v2.x, v3.x, and modern Compose Spec (no version field)
  • Service mapping: image, ports (TCP/UDP), environment (map and list syntax), volumes (bind mounts, named, anonymous, read-only), command, entrypoint, container_name, depends_on, healthcheck
  • Health checks: Compose healthcheck definitions mapped to Aspire IHealthCheck with interval/timeout support
  • Dependency conditions: service_started, service_healthy, service_completed_successfully

Usage

<ItemGroup>
    <PackageReference Include="CommunityToolkit.Aspire.Hosting.Compose" />
    <ComposeReference Include=".infra/compose.yml" ComposeName="Infra" />
</ItemGroup>
// Typed API
var infra = builder.AddCompose<Compose.Infra>();
builder.AddProject<Projects.MyApi>("api")
    .WaitFor(infra.Postgres)
    .WaitFor(infra.Redis);

// Runtime API
var infra = builder.AddCompose(".infra/compose.yml");
builder.AddProject<Projects.MyApi>("api")
    .WaitFor(infra["postgres"]);

Project structure

  • CommunityToolkit.Aspire.Hosting.Compose — runtime library (parsing, mapping, extension methods)
  • CommunityToolkit.Aspire.Hosting.Compose.Generator — source generator (shipped as analyzer inside the NuGet package)

PR Checklist

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • PR doesn't include merge commits (always rebase on top of our main, if needed)
  • New integration
    • Docs are written
    • Added description of major feature to project description for NuGet package
  • Tests for the changes have been added (102 tests)
  • Contains NO breaking changes
  • Every new API (including internal ones) has full XML docs
  • Code follows all style conventions

Other information

  • NuGet package verified end-to-end: dotnet pack → install via local feed → <ComposeReference> with source generator → build succeeded
  • Source generator produces wrapper classes with typed properties (infra.Postgres) instead of string constants
  • ComposeConstants centralizes all compose spec keys to avoid hardcoded strings
  • Mapping logic decomposed into single-responsibility classes: PortMapper, EnvironmentMapper, VolumeMapper, CommandMapper, HealthcheckMapper, DependsOnMapper

@github-actions
Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/CommunityToolkit/Aspire/main/eng/scripts/dogfood-pr.sh | bash -s -- 1277

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/CommunityToolkit/Aspire/main/eng/scripts/dogfood-pr.ps1) } 1277"

@curiousvlxd
Copy link
Copy Markdown
Author

@curiousvlxd please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@dotnet-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@dotnet-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@dotnet-policy-service agree company="Microsoft"

Contributor License Agreement

@dotnet-policy-service agree

@curiousvlxd
Copy link
Copy Markdown
Author

curiousvlxd commented Apr 12, 2026

Hi @davidfowl, @danegsta, @isaacrlevin

I wanted to share that I've implemented this feature based on the discussion here: microsoft/aspire#4375 and #1276 issue.

The integration parses existing Docker Compose files and maps services to Aspire container resources with support for all compose format versions, ports, environment, volumes, depends_on, healthchecks, and includes a source generator.

I completely agree with the direction discussed here that this belongs in the Community Toolkit. Would really appreciate any feedback.

@davidfowl
Copy link
Copy Markdown
Contributor

I dont think it does. I think it should be in the core potentially with first class support in dcp.

@curiousvlxd
Copy link
Copy Markdown
Author

I dont think it does. I think it should be in the core potentially with first class support in dcp.

@davidfowl Makes sense. My implementation parses yaml and explodes services into individual Aspire resources. Source generator on top works well too.

Are you working on DCP-level integration already, or should I open a PR against microsoft/aspire?

@davidfowl
Copy link
Copy Markdown
Contributor

Nobody is working on this it needs design, but it shoudn't go into the toolkit.

@curiousvlxd
Copy link
Copy Markdown
Author

Nobody is working on this it needs design, but it shoudn't go into the toolkit.

@davidfowl should the Aspire team handle the design? I can take the implementation.

@davidfowl
Copy link
Copy Markdown
Contributor

Move this proposal to https://github.com/microsoft/aspire as a starting point, we can decide how it works there.

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.

Add Docker Compose file hosting integration

2 participants