Skip to content

Conversation

@captainsafia
Copy link
Member

@captainsafia captainsafia commented Oct 31, 2025

demo

This pull request introduces significant improvements to the Docker Compose environment resource handling and environment variable file management in the Aspire Hosting Docker integration. The changes streamline the pipeline steps for Docker Compose operations, refactor the .env file logic for better maintainability and clarity, and remove some legacy build logic. The most important updates are grouped below:

Pipeline Step Management and Docker Compose Operations:

  • Refactored DockerComposeEnvironmentResource to define asynchronous pipeline steps for publishing, preparing, deploying (docker-compose up), and shutting down (docker-compose down). These steps are now dynamically created and properly wired up for resource dependencies.
  • Added robust implementations for DockerComposeUpAsync, DockerComposeDownAsync, and PrepareAsync, including improved environment variable handling and process execution with logging and error reporting.

Environment Variable File Handling:

  • Refactored the EnvFile class to use a sorted dictionary of strongly-typed entries, preserving comments and supporting both value-included and key-only .env file writing. This improves the clarity and maintainability of environment variable management. [1] [2] [3]
  • Updated environment variable capture and saving logic in both the pipeline and publishing context to use the new EnvFile structure, ensuring comments are preserved and values are handled consistently.

Build Logic and Resource Configuration:

  • Removed the BuildContainerImages property and associated logic from DockerComposeEnvironmentResource and the publishing context, simplifying image build management and delegating build step dependencies to the pipeline configuration. [1] [2] [3]
  • Updated the container build target platform in ProjectResource to use AllLinux for broader compatibility.

Project Structure and Code Organization:

  • Added shared process utility files (ProcessResult.cs, ProcessSpec.cs, ProcessUtil.cs) to the project for improved process management and code reuse.

Dependency Injection and Logging:

  • Integrated additional using statements for logging and shared process utilities to support new features and improve diagnostics.

These changes collectively enhance the reliability, maintainability, and clarity of the Docker Compose integration and environment management in Aspire Hosting Docker.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 31, 2025

🚀 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/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12548

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12548"

@captainsafia captainsafia force-pushed the safia/dcd branch 8 times, most recently from 777d882 to 6c85567 Compare October 31, 2025 20:59
@captainsafia captainsafia marked this pull request as ready for review October 31, 2025 21:23
Copilot AI review requested due to automatic review settings October 31, 2025 21:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors Docker Compose publishing to introduce a multi-step pipeline architecture with separate prepare and publish phases, and enhances container image building to support multiple target platforms via the new Flags enum pattern on ContainerTargetPlatform.

Key changes:

  • Separated Docker Compose publishing into distinct pipeline steps (prepare, publish, docker-compose-up, docker-compose-down) for better orchestration
  • Changed ContainerTargetPlatform enum to use [Flags] attribute with explicit values, enabling multi-platform builds via the new AllLinux combined value
  • Refactored .env file generation to save without values during publish step, with values populated in separate prepare step
  • Removed BuildContainerImages property from DockerComposeEnvironmentResource as image building is now handled via pipeline steps

Reviewed Changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Aspire.Hosting/Publishing/ResourceContainerImageBuilder.cs Added [Flags] to ContainerTargetPlatform enum with explicit values, added AllLinux combined value, refactored extension methods to support multiple platforms, changed MSBuild parameter from ContainerRuntimeIdentifier to RuntimeIdentifiers
src/Aspire.Hosting/ContainerResourceBuilderExtensions.cs Changed default platform from LinuxAmd64 to AllLinux for multi-platform support
src/Aspire.Hosting/ApplicationModel/ProjectResource.cs Changed default platform from LinuxAmd64 to AllLinux for project containers
src/Aspire.Hosting/CompatibilitySuppressions.xml Added compatibility suppressions for enum value changes on all ContainerTargetPlatform fields
src/Aspire.Hosting.Docker/EnvFile.cs Refactored to use SortedDictionary with EnvEntry records for better structure, added Save(path, includeValues) overload to support saving keys without values
src/Aspire.Hosting.Docker/DockerComposePublishingContext.cs Modified to save .env file without values during publish step, storing shared EnvFile instance for later population
src/Aspire.Hosting.Docker/DockerComposeEnvironmentResource.cs Added pipeline steps for prepare, docker-compose-up, and docker-compose-down; added PrepareAsync to populate env file values; removed BuildContainerImages property
src/Aspire.Hosting.Docker/Aspire.Hosting.Docker.csproj Added linked files for process execution utilities to support docker-compose command execution
tests/Aspire.Hosting.Docker.Tests/DockerComposePublisherTests.cs Updated test for image building behavior, added tests for prepare step with different environment names, added TestHostEnvironment helper class
tests/Aspire.Hosting.Docker.Tests/Snapshots/*.env Updated snapshot files to reflect env files with empty values (keys only) during publish phase

@captainsafia
Copy link
Member Author

@copilot Address the feedback from Copilot.

Copy link
Contributor

Copilot AI commented Oct 31, 2025

@captainsafia I've opened a new pull request, #12575, to work on those changes. Once the pull request is ready, I'll request review from you.

@captainsafia
Copy link
Member Author

@copilot

  • Update the implementation so that the env files are in the form .env.{environmentName} instead of {environmentName}.env
  • There is a duplicate log when the compose file is successfully written. Reduce the log level from Info to Debug.
image
  • When the docker-compose-up-env step completes successfully add more details to the success message indicating that the service is running with with docker compose locally.

Copy link
Contributor

Copilot AI commented Oct 31, 2025

@captainsafia I've opened a new pull request, #12580, to work on those changes. Once the pull request is ready, I'll request review from you.

captainsafia and others added 4 commits October 31, 2025 18:17
* Initial plan

* Address Copilot feedback: Remove duplicate registration and simplify EnvFile logic

Co-authored-by: captainsafia <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: captainsafia <[email protected]>
… status messages (#12580)

* Initial plan

* Address PR feedback: Update env file naming, reduce log verbosity, and enhance success message

Co-authored-by: captainsafia <[email protected]>

* Fix log verbosity: Move completion message to Debug level instead of task creation

Co-authored-by: captainsafia <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: captainsafia <[email protected]>
@captainsafia captainsafia merged commit 3ec0e7a into main Nov 1, 2025
296 checks passed
@captainsafia captainsafia deleted the safia/dcd branch November 1, 2025 01:53
@captainsafia
Copy link
Member Author

/backport to release/13.0

@dotnet-policy-service dotnet-policy-service bot added this to the 13.1 milestone Nov 1, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 1, 2025

Started backporting to release/13.0: https://github.com/dotnet/aspire/actions/runs/18989559753

@github-actions
Copy link
Contributor

github-actions bot commented Nov 1, 2025

@captainsafia backporting to "release/13.0" failed, the patch most likely resulted in conflicts:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Add deploy support for Docker Compose
.git/rebase-apply/patch:1058: new blank line at EOF.
+
.git/rebase-apply/patch:1073: new blank line at EOF.
+
.git/rebase-apply/patch:1091: new blank line at EOF.
+
warning: 3 lines add whitespace errors.
Using index info to reconstruct a base tree...
M	src/Aspire.Hosting.Docker/DockerComposePublishingContext.cs
M	src/Aspire.Hosting.Docker/EnvFile.cs
M	src/Aspire.Hosting/CompatibilitySuppressions.xml
Falling back to patching base and 3-way merge...
Auto-merging src/Aspire.Hosting.Docker/DockerComposePublishingContext.cs
Auto-merging src/Aspire.Hosting.Docker/EnvFile.cs
CONFLICT (content): Merge conflict in src/Aspire.Hosting.Docker/EnvFile.cs
Auto-merging src/Aspire.Hosting/CompatibilitySuppressions.xml
CONFLICT (content): Merge conflict in src/Aspire.Hosting/CompatibilitySuppressions.xml
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Add deploy support for Docker Compose
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

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.

3 participants