Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 15, 2025

Description

Enables passing arbitrary arguments to docker buildx build and podman build commands via a new AdditionalArguments property. This allows users to configure BuildKit cache backends (--cache-from, --cache-to) and other advanced features not exposed by existing properties.

API Changes

  • Added ContainerBuildOptionsCallbackContext.AdditionalArguments (List<string>, initialized to empty list)
  • Added ContainerImageBuildOptions.AdditionalArguments (List<string>?)
  • Arguments are appended to build command after build args/secrets/stage, before context path

Usage

var container = builder.AddDockerfile("myapp", "./src", "./Dockerfile")
    .WithContainerBuildOptions(ctx =>
    {
        ctx.AdditionalArguments.Add("--cache-from");
        ctx.AdditionalArguments.Add("type=registry,ref=myregistry.io/cache");
        ctx.AdditionalArguments.Add("--cache-to");
        ctx.AdditionalArguments.Add("type=registry,ref=myregistry.io/cache,mode=max");
    });

Testing

  • Additional arguments flow correctly to Docker/Podman runtimes
  • Empty list handled properly (null not passed)
  • Interoperability with existing build arguments verified

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
    • No
  • Does the change require an update in our Aspire docs?
    • Yes
    • No

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • westus2.data.mcr.microsoft.com
    • Triggering command: /usr/share/dotnet/dotnet dotnet publish /home/REDACTED/work/aspire/aspire/tests/testproject/TestProject.ServiceA/TestProject.ServiceA.csproj --configuration Release /t:PublishContainer /p:ContainerRepository=servicea /p:ContainerImageTag=latest /p:RuntimeIdentifier=linux-x64 /p:ContainerRuntimeIdentifier=linux-x64 k/aspire/aspire/--exclude-standard grep -l ldOptions ng/PackageVersionProvider.cs /home/REDACTED/.cargo/bin/grep ldOptions s ndor/bin/grep grep (dns block)
    • Triggering command: /usr/share/dotnet/dotnet dotnet publish /home/REDACTED/work/aspire/aspire/tests/testproject/TestProject.ServiceA/TestProject.ServiceA.csproj --configuration Release /t:PublishContainer /p:ContainerRepository=servicea /p:ContainerImageTag=latest /p:ContainerArchiveOutputPath=/tmp/test-output /p:ContainerImageFormat=OCI /p:RuntimeIdentifier=linux-x64 /p:ContainerRuntimeIdentifier=linux-x64 -l ldOptions ng/Lifecycle/IDistributedApplicationLifecycleHook.cs grep ldOptions cs /home/REDACTED/.ca. /tmp/MSBuildTempQVNV7J/tmp130a2ac8db0f4fac8baf7265292a271f.exec.cmd grep (dns block)
    • Triggering command: /usr/bin/buildkitd buildkitd --allow-insecure-entitlement=network.host nfig/composer/ve--exclude-standard grep -l ldOptions ng/PackageVersionProvider.cs k/aspire/aspire/.dotnet//grep ldOptions s ep grep -l ldOptions ng/IDistributedApplicationBuilder.cs ndor/bin/grep ldOptions ions.cs k/aspire/aspire/--version grep (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>BuildKit caching arguments</issue_title>
<issue_description>### Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I am trying to persist the npm cache for my JavaScript app across CI builds. The default image created by AddJavaScriptApp uses the internal BuildKit cache (RUN --mount=type=cache,target=/root/.npm). To be able to reuse the cache across pipeline runes, I'd like to use a different backend, e.g. a local directory on an Azure Pipelines build agent in combination with the Cache task.
In order to do that, I would need to add additional arguments (--cache-to and cache-from) to the docker buildx build call in the container runtime, but while there is an option for build arguments, I couldn't find a way to add arguments to the call itself (see DockerContainerRuntime for example).

Describe the solution you'd like

I'd like to either have a possibility to control these caching arguments directly, or a generic way to add additional arguments to the image building call.

Additional context

This is not only about build performance. We use Font Awesome which bills us for the bandwidth used during package loads.</issue_description>

<agent_instructions>Update the ContainerBuildOptions class to take an AdditionalArguments property that will be relied to the docker build call. Model this API as a list of strings and initialize it to a non-empty list. Add tests that validate that additional properties flow correctly to the ContainerRuntime implementation.</agent_instructions>

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

@captainsafia @Skleni Thanks for filing this issue!

Right now, our API for customizing the arguments that are passed to the build command is the ContainerBuildOptions which exposes a small surface area of what is fully-supported in the Docker CLI.

A thought here is to expose an AdditionalArguments property that would allow the user to provide arbitrary arguments that aren't supported by the existing properties on ContainerBuildOptions. That should allow you to set these additional arguments on the call using the existing APIs for customizing ContainerBuildOptions:

builder.AddProject("api", "../api.csproj")
  .WithContainerBuildOptions(ctx =>
  {
      ctx.AdditionalArguments.Add("--cache-from", "type=registry");
  });
```</body></comment_new>
</comments>

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits December 15, 2025 19:29
…t caching

- Added AdditionalArguments property to ContainerBuildOptionsCallbackContext
- Added AdditionalArguments property to ContainerImageBuildOptions
- Updated DockerContainerRuntime to pass additional arguments to docker build
- Updated PodmanContainerRuntime to pass additional arguments to podman build
- Updated FakeContainerRuntime to capture additional arguments for testing
- Added tests to validate additional arguments flow correctly

Co-authored-by: captainsafia <[email protected]>
Copilot AI changed the title [WIP] Add BuildKit caching arguments for npm Add AdditionalArguments property to ContainerBuildOptions for BuildKit cache configuration Dec 15, 2025
Copilot AI requested a review from captainsafia December 15, 2025 19:35
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.

BuildKit caching arguments

2 participants