-
Notifications
You must be signed in to change notification settings - Fork 881
Pass target platform to DCP for Dockerfile builds #16700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| using System.Net.Sockets; | ||
| using Aspire.Hosting.ApplicationModel; | ||
| using Aspire.Hosting.Dcp.Model; | ||
| using Aspire.Hosting.Publishing; | ||
| using Aspire.Hosting.Utils; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.Hosting; | ||
|
|
@@ -260,7 +261,7 @@ private async Task BuildAndCreateContainerAsync(RenderedModelResource<Container> | |
| var dcpContainer = cr.DcpResource; | ||
| var modelContainer = cr.ModelResource; | ||
|
|
||
| await ApplyBuildArgumentsAsync(dcpContainer, cr.ModelResource, _executionContext.ServiceProvider, cToken).ConfigureAwait(false); | ||
| await ApplyBuildArgumentsAsync(dcpContainer, cr.ModelResource, _executionContext.ServiceProvider, logger, cToken).ConfigureAwait(false); | ||
|
|
||
| var spec = dcpContainer.Spec; | ||
|
|
||
|
|
@@ -732,7 +733,7 @@ await modelResource.ProcessContainerRuntimeArgValues( | |
| return (runArgs, failedToApplyArgs); | ||
| } | ||
|
|
||
| private static async Task ApplyBuildArgumentsAsync(Container dcpContainerResource, IResource modelContainerResource, IServiceProvider serviceProvider, CancellationToken cancellationToken) | ||
| private static async Task ApplyBuildArgumentsAsync(Container dcpContainerResource, IResource modelContainerResource, IServiceProvider serviceProvider, ILogger logger, CancellationToken cancellationToken) | ||
| { | ||
| if (modelContainerResource.Annotations.OfType<DockerfileBuildAnnotation>().SingleOrDefault() is { } dockerfileBuildAnnotation) | ||
| { | ||
|
|
@@ -783,6 +784,18 @@ private static async Task ApplyBuildArgumentsAsync(Container dcpContainerResourc | |
| Args = dcpBuildArgs, | ||
| Secrets = dcpBuildSecrets | ||
| }; | ||
|
|
||
| #pragma warning disable ASPIREPIPELINES003 // ContainerBuildOptions APIs are experimental. | ||
| var buildOptionsContext = await modelContainerResource.ProcessContainerBuildOptionsCallbackAsync( | ||
| serviceProvider, | ||
| logger, | ||
| cancellationToken: cancellationToken).ConfigureAwait(false); | ||
|
|
||
| if (buildOptionsContext.TargetPlatform is { } targetPlatform) | ||
| { | ||
| dcpContainerResource.Spec.Build.Platform = targetPlatform.ToRuntimePlatformString(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm nervous about us overriding the default run time platform to linux/amd64 regardless of the host architecture at run time when building a Dockerfile just because I've seen enough cases where the emulation layers fail. I'd want to consider supporting separate publish and runtime defaults (stick with linux/amd64 as the default publish platform, but continue to use the current machine architecture as the default at runtime. |
||
| } | ||
| #pragma warning restore ASPIREPIPELINES003 | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,6 +126,10 @@ internal sealed class BuildContext | |
| // Optional labels to apply to the built image | ||
| [JsonPropertyName("labels")] | ||
| public List<ContainerLabel>? Labels { get; set; } | ||
|
|
||
| // Optional target platform for the build (e.g. "linux/amd64") | ||
| [JsonPropertyName("platform")] | ||
| public string? Platform { get; set; } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There isn't a platform field in the DCP types (https://github.com/microsoft/dcp/blob/main/api/v1/container_types.go#L140), so any proposed change would need to start there.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opened initial PR -> microsoft/dcp#140 |
||
| } | ||
|
|
||
| internal sealed class BuildContextSecret | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would need to be done in a way that doesn't take a dependency on the publish types in DCP (no Aspire.Hosting.Publishing dependency).