Skip to content

Expose Dockerfile builder APIs to polyglot apphosts#15867

Open
sebastienros wants to merge 3 commits intomainfrom
sebros/issue-15858-dockerfile-polyglot
Open

Expose Dockerfile builder APIs to polyglot apphosts#15867
sebastienros wants to merge 3 commits intomainfrom
sebros/issue-15858-dockerfile-polyglot

Conversation

@sebastienros
Copy link
Copy Markdown
Contributor

Description

Expose the programmatic Dockerfile builder flow to polyglot AppHosts.

  • Re-enable AddDockerfileBuilder and WithDockerfileBuilder for ATS/code generation and export the Dockerfile builder callback surface needed by TypeScript, Python, and Java.
  • Add curated Dockerfile DSL wrapper exports, including container-files helper wrappers, and fix code generation issues around duplicate type IDs and capability naming collisions.
  • Update the real polyglot validation apphosts and refresh the affected TypeScript, Python, and Java snapshots.

Validation:

  • ./dotnet.sh test tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests.csproj -- --filter-method "*Scanner_HostingAssembly_ContainerResourceCapabilities" --filter-method "*TwoPassScanning_GeneratesWithEnvironmentOnTestRedisBuilder" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"
  • ./dotnet.sh test tests/Aspire.Hosting.CodeGeneration.Python.Tests/Aspire.Hosting.CodeGeneration.Python.Tests.csproj -- --filter-method "*TwoPassScanning_GeneratesWithEnvironmentOnTestRedisBuilder" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"
  • ./dotnet.sh test tests/Aspire.Hosting.CodeGeneration.Java.Tests/Aspire.Hosting.CodeGeneration.Java.Tests.csproj -- --filter-method "*TwoPassScanning_GeneratesWithEnvironmentOnTestRedisBuilder" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"
  • aspire restore --non-interactive --apphost apphost.ts && npx tsc --noEmit --project tsconfig.json in tests/PolyglotAppHosts/Aspire.Hosting/TypeScript
  • aspire restore --non-interactive --apphost apphost.py plus Python compile in tests/PolyglotAppHosts/Aspire.Hosting/Python
  • aspire restore --non-interactive --apphost AppHost.java && javac --enable-preview --source 25 -d .java-build @.modules/sources.txt AppHost.java in tests/PolyglotAppHosts/Aspire.Hosting/Java

Fixes #15858

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

Re-enable the Dockerfile builder callback surface for TypeScript, Python, and Java apphosts through ATS-safe wrapper exports.

Also add curated container-files wrapper exports, fix generator handling for duplicate handle/builder type IDs and run-capability naming, update the real polyglot validation apphosts, and refresh the affected codegen snapshots.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 3, 2026 22:43
Copy link
Copy Markdown
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 exposes the programmatic Dockerfile builder flow to polyglot AppHosts (TypeScript/Python/Java) by exporting the needed ATS callback context and adding curated Dockerfile DSL wrapper exports, then updates polyglot validation fixtures and regenerates language snapshots to cover the new surface.

Changes:

  • Export AddDockerfileBuilder / WithDockerfileBuilder (async callback overloads) to ATS and export DockerfileBuilderCallbackContext + Dockerfile DSL handles.
  • Add curated ATS exports for the Dockerfile DSL (builder/stage statements + container-files helpers) while keeping internal helper extensions hidden from polyglot.
  • Fix codegen edge cases around duplicate type IDs / capability collisions and refresh TS/Python/Java generated snapshots + validation AppHosts.

Reviewed changes

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

Show a summary per file
File Description
tests/PolyglotAppHosts/Aspire.Hosting/TypeScript/apphost.ts Exercises the new Dockerfile builder callback surface in the TypeScript polyglot validation AppHost.
tests/PolyglotAppHosts/Aspire.Hosting/Python/apphost.py Exercises the new Dockerfile builder callback surface in the Python polyglot validation AppHost.
tests/PolyglotAppHosts/Aspire.Hosting/Java/AppHost.java Exercises the new Dockerfile builder callback surface in the Java polyglot validation AppHost.
tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts Updates the TypeScript generated SDK snapshot to include Dockerfile builder/stage/context APIs and capabilities.
tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/HostingContainerResourceCapabilities.verified.txt Updates the TS capability snapshot to include withDockerfileBuilder.
tests/Aspire.Hosting.CodeGeneration.Python.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.py Updates the Python generated SDK snapshot to include Dockerfile builder/stage/context APIs and capabilities.
tests/Aspire.Hosting.CodeGeneration.Java.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.java Updates the Java generated SDK snapshot to include Dockerfile builder/stage/context APIs and capabilities.
src/Aspire.Hosting/ContainerResourceBuilderExtensions.cs Re-enables ATS export for async Dockerfile builder APIs and adjusts polyglot availability remarks.
src/Aspire.Hosting/Ats/DockerfileBuilderExports.cs Adds curated ATS exports for Dockerfile DSL statements and container-files helpers.
src/Aspire.Hosting/ApplicationModel/DockerfileBuilderCallbackContext.cs Marks the callback context as ATS-exported (property exposure enabled) for polyglot callbacks.
src/Aspire.Hosting/ApplicationModel/Docker/DockerfileStage.cs Marks Dockerfile stage type as ATS-exported so it can flow through polyglot handles.
src/Aspire.Hosting/ApplicationModel/Docker/DockerfileBuilder.cs Marks Dockerfile builder type as ATS-exported so it can flow through polyglot handles.
src/Aspire.Hosting/ApplicationModel/Docker/ContainerFilesExtensions.cs Hides raw container-files extension exports in favor of curated ATS wrappers.
src/Aspire.Hosting.CodeGeneration.Python/AtsPythonCodeGenerator.cs Deduplicates builder models by TypeId to prevent duplicate type/capability issues in Python generation.
src/Aspire.Hosting.CodeGeneration.Java/AtsJavaCodeGenerator.cs Resolves duplicate handle types by AtsTypeId, preferring resource-builder variants when present.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

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

Or

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

sebastienros and others added 2 commits April 3, 2026 16:04
Update the Go and Rust two-pass generated Aspire snapshots after the Dockerfile builder polyglot export changes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Update the AspireExportIgnore reasons on the synchronous Dockerfile builder overloads to reflect that only the async callback overload is exported to polyglot apphosts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

🎬 CLI E2E Test Recordings — 55 recordings uploaded (commit 7d032ff)

View recordings
Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AllPublishMethodsBuildDockerImages ▶️ View Recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
Banner_NotDisplayedWithNoLogoFlag ▶️ View Recording
CertificatesClean_RemovesCertificates ▶️ View Recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View Recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View Recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunEmptyAppHostProject ▶️ View Recording
CreateAndRunJavaEmptyAppHostProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptEmptyAppHostProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateJavaAppHostWithViteApp ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View Recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View Recording
GlobalMigration_PreservesAllValueTypes ▶️ View Recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View Recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LegacySettingsMigration_AdjustsRelativeAppHostPath ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RestoreSupportsConfigOnlyHelperPackageAndCrossPackageTypes ▶️ View Recording
RunFromParentDirectory_UsesExistingConfigNearAppHost ▶️ View Recording
RunWithMissingAwaitShowsHelpfulError ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording

📹 Recordings uploaded automatically from CI run #23965587141

.GroupBy(t => t.AtsTypeId, StringComparer.Ordinal)
.ToDictionary(
g => g.Key,
g => g.OrderByDescending(t => t.IsResourceBuilder).First(),
Copy link
Copy Markdown
Member

@JamesNK JamesNK Apr 5, 2026

Choose a reason for hiding this comment

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

Why is it safe to use the first here? The PY code below does a bunch of work to merge duplicates together.

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.

WithDockerfileBuilder not available in polyglot apphosts, and no publishAsDockerfile metho exists

3 participants