diff --git a/.autover/changes/f3bdd1b8-155d-416d-b4ff-0d1bcf119e45.json b/.autover/changes/f3bdd1b8-155d-416d-b4ff-0d1bcf119e45.json
new file mode 100644
index 000000000..5cf1f81f0
--- /dev/null
+++ b/.autover/changes/f3bdd1b8-155d-416d-b4ff-0d1bcf119e45.json
@@ -0,0 +1,11 @@
+{
+ "Projects": [
+ {
+ "Name": "AWS.Deploy.CLI",
+ "Type": "Minor",
+ "ChangelogMessages": [
+ "Fix an issue causing container deployments to fail when run on an ARM-based system"
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/AWS.Deploy.CLI/AWS.Deploy.CLI.csproj b/src/AWS.Deploy.CLI/AWS.Deploy.CLI.csproj
index 1822d33f2..118420548 100644
--- a/src/AWS.Deploy.CLI/AWS.Deploy.CLI.csproj
+++ b/src/AWS.Deploy.CLI/AWS.Deploy.CLI.csproj
@@ -30,7 +30,7 @@
-
+
diff --git a/src/AWS.Deploy.CLI/ServerMode/AwsCredentialsAuthenticationHandler.cs b/src/AWS.Deploy.CLI/ServerMode/AwsCredentialsAuthenticationHandler.cs
index 4a9c26398..0d3545b16 100644
--- a/src/AWS.Deploy.CLI/ServerMode/AwsCredentialsAuthenticationHandler.cs
+++ b/src/AWS.Deploy.CLI/ServerMode/AwsCredentialsAuthenticationHandler.cs
@@ -76,7 +76,7 @@ protected override Task HandleAuthenticateAsync()
return Task.FromResult(AuthenticateResult.Fail("Missing Authorization header"));
}
- return Task.FromResult(ProcessAuthorizationHeader(value, _encryptionProvider));
+ return Task.FromResult(ProcessAuthorizationHeader(value.ToString(), _encryptionProvider));
}
public static AuthenticateResult ProcessAuthorizationHeader(string authorizationHeaderValue, IEncryptionProvider encryptionProvider)
diff --git a/src/AWS.Deploy.DockerEngine/AWS.Deploy.DockerEngine.csproj b/src/AWS.Deploy.DockerEngine/AWS.Deploy.DockerEngine.csproj
index f921b7e2b..50bedcf4b 100644
--- a/src/AWS.Deploy.DockerEngine/AWS.Deploy.DockerEngine.csproj
+++ b/src/AWS.Deploy.DockerEngine/AWS.Deploy.DockerEngine.csproj
@@ -9,10 +9,12 @@
+
+
diff --git a/src/AWS.Deploy.DockerEngine/DockerEngine.cs b/src/AWS.Deploy.DockerEngine/DockerEngine.cs
index 5937b2000..ce7809365 100644
--- a/src/AWS.Deploy.DockerEngine/DockerEngine.cs
+++ b/src/AWS.Deploy.DockerEngine/DockerEngine.cs
@@ -81,7 +81,7 @@ public void GenerateDockerFile(Recommendation recommendation)
DetermineHTTPPortEnvironmentVariable(recommendation, recommendation.DeploymentBundle.DockerfileHttpPort));
var projectDirectory = Path.GetDirectoryName(_projectPath) ?? "";
var projectList = GetProjectList();
- dockerFile.WriteDockerFile(projectDirectory, projectList);
+ dockerFile.WriteDockerFile(projectDirectory, projectList, recommendation.ProjectDefinition.TargetFramework);
}
///
@@ -192,7 +192,7 @@ public void DetermineDockerExecutionDirectory(Recommendation recommendation)
if (string.IsNullOrEmpty(recommendation.DeploymentBundle.DockerExecutionDirectory))
{
var projectFilename = Path.GetFileName(recommendation.ProjectPath);
-
+
if (DockerUtilities.TryGetAbsoluteDockerfile(recommendation, _fileManager, _directoryManager, out var dockerFilePath))
{
using (var stream = File.OpenRead(dockerFilePath))
diff --git a/src/AWS.Deploy.DockerEngine/DockerFile.cs b/src/AWS.Deploy.DockerEngine/DockerFile.cs
index 2b6ab44a8..be34c053b 100644
--- a/src/AWS.Deploy.DockerEngine/DockerFile.cs
+++ b/src/AWS.Deploy.DockerEngine/DockerFile.cs
@@ -48,9 +48,9 @@ public DockerFile(ImageMapping imageMapping, string projectName, string? assembl
///
/// Writes a docker file based on project information
///
- public void WriteDockerFile(string projectDirectory, List? projectList)
+ public void WriteDockerFile(string projectDirectory, List? projectList, string? targetFramework)
{
- var dockerFileTemplate = ProjectUtilities.ReadTemplate();
+ var dockerFileTemplate = ProjectUtilities.ReadTemplate(targetFramework);
var projects = "";
var projectPath = "";
var projectFolder = "";
@@ -99,7 +99,7 @@ public void WriteDockerFile(string projectDirectory, List? projectList)
dockerFile = dockerFile
.Replace("{http-port-env-variable}", string.Empty);
}
- // For all other ports, it is up to the user to expose the HTTPS port in the dockerfile.
+ // For all other ports, it is up to the user to expose the HTTPS port in the dockerfile.
else
{
dockerFile = dockerFile
@@ -119,7 +119,7 @@ public void WriteDockerFile(string projectDirectory, List? projectList)
.Replace("{non-root-user}", "\r\nUSER app");
}
- // ProjectDefinitionParser will have transformed projectDirectory to an absolute path,
+ // ProjectDefinitionParser will have transformed projectDirectory to an absolute path,
// and DockerFileName is static so traversal should not be possible here.
// nosemgrep: csharp.lang.security.filesystem.unsafe-path-combine.unsafe-path-combine
File.WriteAllText(Path.Combine(projectDirectory, Constants.Docker.DefaultDockerfileName), dockerFile);
diff --git a/src/AWS.Deploy.DockerEngine/ProjectUtilities.cs b/src/AWS.Deploy.DockerEngine/ProjectUtilities.cs
index 79946b4f6..9ebb87645 100644
--- a/src/AWS.Deploy.DockerEngine/ProjectUtilities.cs
+++ b/src/AWS.Deploy.DockerEngine/ProjectUtilities.cs
@@ -1,7 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
-using System.IO;
using System.Reflection;
using AWS.Deploy.Common;
using AWS.Deploy.Common.Extensions;
@@ -12,6 +11,7 @@ public class ProjectUtilities
{
private const string DockerFileConfig = "AWS.Deploy.DockerEngine.Properties.DockerFileConfig.json";
private const string DockerfileTemplate = "AWS.Deploy.DockerEngine.Templates.Dockerfile.template";
+ private const string DockerfileTemplate_Net6 = "AWS.Deploy.DockerEngine.Templates.Dockerfile.Net6.template";
///
/// Retrieves the Docker File Config
@@ -31,9 +31,22 @@ internal static string ReadDockerFileConfig()
///
/// Reads dockerfile template file
///
- internal static string ReadTemplate()
+ internal static string ReadTemplate(string? targetFramework)
{
- var template = Assembly.GetExecutingAssembly().ReadEmbeddedFile(DockerfileTemplate);
+ string templateLocation;
+ switch (targetFramework)
+ {
+ case "net6.0":
+ case "net5.0":
+ case "netcoreapp3.1":
+ templateLocation = DockerfileTemplate_Net6;
+ break;
+
+ default:
+ templateLocation = DockerfileTemplate;
+ break;
+ }
+ var template = Assembly.GetExecutingAssembly().ReadEmbeddedFile(templateLocation);
if (string.IsNullOrWhiteSpace(template))
{
diff --git a/src/AWS.Deploy.DockerEngine/Templates/Dockerfile.Net6.template b/src/AWS.Deploy.DockerEngine/Templates/Dockerfile.Net6.template
new file mode 100644
index 000000000..c3e6628d8
--- /dev/null
+++ b/src/AWS.Deploy.DockerEngine/Templates/Dockerfile.Net6.template
@@ -0,0 +1,26 @@
+FROM {docker-base-image} AS base{non-root-user}
+WORKDIR /app
+{exposed-ports}
+
+FROM {docker-build-image} AS build
+WORKDIR /src
+{project-path-list}
+RUN dotnet restore "{project-path}"
+COPY . .
+WORKDIR "/src/{project-folder}"
+RUN dotnet build "{project-name}" -c Release -o /app/build
+
+FROM build AS publish
+RUN apt-get update -yq \
+ && apt-get install -yq ca-certificates curl gnupg \
+ && mkdir -p /etc/apt/keyrings \
+ && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
+ && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
+ && apt-get update -yq \
+ && apt-get install nodejs -yq
+RUN dotnet publish "{project-name}" -c Release -o /app/publish
+
+FROM base AS final{http-port-env-variable}
+WORKDIR /app
+COPY --from=publish /app/publish .
+ENTRYPOINT ["dotnet", "{assembly-name}.dll"]
diff --git a/src/AWS.Deploy.DockerEngine/Templates/Dockerfile.template b/src/AWS.Deploy.DockerEngine/Templates/Dockerfile.template
index c3e6628d8..964dee173 100644
--- a/src/AWS.Deploy.DockerEngine/Templates/Dockerfile.template
+++ b/src/AWS.Deploy.DockerEngine/Templates/Dockerfile.template
@@ -2,13 +2,14 @@ FROM {docker-base-image} AS base{non-root-user}
WORKDIR /app
{exposed-ports}
-FROM {docker-build-image} AS build
+FROM --platform=$BUILDPLATFORM {docker-build-image} AS build
+ARG TARGETARCH
WORKDIR /src
{project-path-list}
-RUN dotnet restore "{project-path}"
+RUN dotnet restore "{project-path}" -a $TARGETARCH
COPY . .
WORKDIR "/src/{project-folder}"
-RUN dotnet build "{project-name}" -c Release -o /app/build
+RUN dotnet build "{project-name}" -c Release -o /app/build -a $TARGETARCH
FROM build AS publish
RUN apt-get update -yq \
@@ -18,7 +19,7 @@ RUN apt-get update -yq \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
&& apt-get update -yq \
&& apt-get install nodejs -yq
-RUN dotnet publish "{project-name}" -c Release -o /app/publish
+RUN dotnet publish "{project-name}" -c Release -o /app/publish -a $TARGETARCH
FROM base AS final{http-port-env-variable}
WORKDIR /app
diff --git a/src/AWS.Deploy.Orchestration/AWS.Deploy.Orchestration.csproj b/src/AWS.Deploy.Orchestration/AWS.Deploy.Orchestration.csproj
index daa2fc8ab..b2fc3f645 100644
--- a/src/AWS.Deploy.Orchestration/AWS.Deploy.Orchestration.csproj
+++ b/src/AWS.Deploy.Orchestration/AWS.Deploy.Orchestration.csproj
@@ -7,10 +7,6 @@
AWS.Deploy.Orchestration
-
-
-
-
@@ -31,7 +27,7 @@
-
+
@@ -39,6 +35,7 @@
+
diff --git a/src/AWS.Deploy.Orchestration/DeploymentBundleHandler.cs b/src/AWS.Deploy.Orchestration/DeploymentBundleHandler.cs
index a23669d60..237548dec 100644
--- a/src/AWS.Deploy.Orchestration/DeploymentBundleHandler.cs
+++ b/src/AWS.Deploy.Orchestration/DeploymentBundleHandler.cs
@@ -74,6 +74,11 @@ public async Task BuildDockerImage(CloudApplication cloudApplication, Recommenda
DockerUtilities.TryGetAbsoluteDockerfile(recommendation, _fileManager, _directoryManager, out var dockerFile);
var dockerBuildCommand = $"docker build -t {imageTag} -f \"{dockerFile}\"{buildArgs} .";
+ if (RuntimeInformation.OSArchitecture != Architecture.X64)
+ {
+ dockerBuildCommand = $"docker buildx build --platform linux/amd64 -t {imageTag} -f \"{dockerFile}\"{buildArgs} .";
+ }
+
_interactiveService.LogInfoMessage($"Docker Execution Directory: {Path.GetFullPath(dockerExecutionDirectory)}");
_interactiveService.LogInfoMessage($"Docker Build Command: {dockerBuildCommand}");
diff --git a/src/AWS.Deploy.Orchestration/TemplateEngine.cs b/src/AWS.Deploy.Orchestration/TemplateEngine.cs
index ddeb0dc54..1b5da0975 100644
--- a/src/AWS.Deploy.Orchestration/TemplateEngine.cs
+++ b/src/AWS.Deploy.Orchestration/TemplateEngine.cs
@@ -41,7 +41,7 @@ public void GenerateCDKProjectFromTemplate(Recommendation recommendation, Orches
{
throw new InvalidOperationException($"{nameof(recommendation.Recipe.CdkProjectTemplateId)} cannot be null or an empty string");
}
-
+
//The location of the base template that will be installed into the templating engine
var cdkProjectTemplateDirectory = Path.Combine(
Path.GetDirectoryName(recommendation.Recipe.RecipePath) ??
@@ -67,7 +67,7 @@ public void GenerateCDKProjectFromTemplate(Recommendation recommendation, Orches
var templateParameters = new Dictionary {
// CDK Template projects can parameterize the version number of the AWS.Deploy.Recipes.CDK.Common package. This avoid
// projects having to be modified every time the package version is bumped.
- { "AWSDeployRecipesCDKCommonVersion", FileVersionInfo.GetVersionInfo(typeof(Constants.CloudFormationIdentifier).Assembly.Location).ProductVersion
+ { "AWSDeployRecipesCDKCommonVersion", FileVersionInfo.GetVersionInfo(typeof(AWS.Deploy.Recipes.CDK.Common.CDKRecipeSetup).Assembly.Location).ProductVersion
?? throw new InvalidAWSDeployRecipesCDKCommonVersionException(DeployToolErrorCode.InvalidAWSDeployRecipesCDKCommonVersion, "The version number of the AWS.Deploy.Recipes.CDK.Common package is invalid.") }
};
diff --git a/test/AWS.Deploy.CLI.UnitTests/DeploymentBundleHandlerTests.cs b/test/AWS.Deploy.CLI.UnitTests/DeploymentBundleHandlerTests.cs
index 91c1018eb..d23c56328 100644
--- a/test/AWS.Deploy.CLI.UnitTests/DeploymentBundleHandlerTests.cs
+++ b/test/AWS.Deploy.CLI.UnitTests/DeploymentBundleHandlerTests.cs
@@ -91,8 +91,16 @@ public async Task BuildDockerImage_DockerExecutionDirectoryNotSet()
var expectedDockerFile = Path.GetFullPath(Path.Combine(".", "Dockerfile"), recommendation.GetProjectDirectory());
var dockerExecutionDirectory = Directory.GetParent(Path.GetFullPath(recommendation.ProjectPath)).Parent.Parent;
- Assert.Equal($"docker build -t {imageTag} -f \"{expectedDockerFile}\" .",
- _commandLineWrapper.CommandsToExecute.First().Command);
+ if (RuntimeInformation.OSArchitecture.Equals(Architecture.X64))
+ {
+ Assert.Equal($"docker build -t {imageTag} -f \"{expectedDockerFile}\" .",
+ _commandLineWrapper.CommandsToExecute.First().Command);
+ }
+ else
+ {
+ Assert.Equal($"docker buildx build --platform linux/amd64 -t {imageTag} -f \"{expectedDockerFile}\" .",
+ _commandLineWrapper.CommandsToExecute.First().Command);
+ }
Assert.Equal(dockerExecutionDirectory.FullName,
_commandLineWrapper.CommandsToExecute.First().WorkingDirectory);
}
@@ -116,8 +124,16 @@ public async Task BuildDockerImage_DockerExecutionDirectorySet()
var expectedDockerFile = Path.GetFullPath(Path.Combine(".", "Dockerfile"), recommendation.GetProjectDirectory());
- Assert.Equal($"docker build -t {imageTag} -f \"{expectedDockerFile}\" .",
- _commandLineWrapper.CommandsToExecute.First().Command);
+ if (RuntimeInformation.OSArchitecture.Equals(Architecture.X64))
+ {
+ Assert.Equal($"docker build -t {imageTag} -f \"{expectedDockerFile}\" .",
+ _commandLineWrapper.CommandsToExecute.First().Command);
+ }
+ else
+ {
+ Assert.Equal($"docker buildx build --platform linux/amd64 -t {imageTag} -f \"{expectedDockerFile}\" .",
+ _commandLineWrapper.CommandsToExecute.First().Command);
+ }
Assert.Equal(projectPath,
_commandLineWrapper.CommandsToExecute.First().WorkingDirectory);
}
@@ -144,9 +160,16 @@ public async Task BuildDockerImage_AlternativeDockerfilePathSet()
var cloudApplication = new CloudApplication("ConsoleAppTask", string.Empty, CloudApplicationResourceType.CloudFormationStack, recommendation.Recipe.Id);
var imageTag = "imageTag";
await _deploymentBundleHandler.BuildDockerImage(cloudApplication, recommendation, imageTag);
-
- Assert.Equal($"docker build -t {imageTag} -f \"{dockerfilePath}\" .",
- _commandLineWrapper.CommandsToExecute.First().Command);
+ if (RuntimeInformation.OSArchitecture.Equals(Architecture.X64))
+ {
+ Assert.Equal($"docker build -t {imageTag} -f \"{dockerfilePath}\" .",
+ _commandLineWrapper.CommandsToExecute.First().Command);
+ }
+ else
+ {
+ Assert.Equal($"docker buildx build --platform linux/amd64 -t {imageTag} -f \"{dockerfilePath}\" .",
+ _commandLineWrapper.CommandsToExecute.First().Command);
+ }
Assert.Equal(expectedDockerExecutionDirectory.FullName,
_commandLineWrapper.CommandsToExecute.First().WorkingDirectory);
}
diff --git a/test/AWS.Deploy.CLI.UnitTests/DockerTests.cs b/test/AWS.Deploy.CLI.UnitTests/DockerTests.cs
index 5b58811cd..c188865b0 100644
--- a/test/AWS.Deploy.CLI.UnitTests/DockerTests.cs
+++ b/test/AWS.Deploy.CLI.UnitTests/DockerTests.cs
@@ -64,10 +64,15 @@ public void DockerFileConfigExists()
Assert.False(string.IsNullOrWhiteSpace(dockerFileConfig));
}
- [Fact]
- public void DockerfileTemplateExists()
+ [Theory]
+ [InlineData("net8.0")]
+ [InlineData("net7.0")]
+ [InlineData("net6.0")]
+ [InlineData("net5.0")]
+ [InlineData("netcoreapp3.1")]
+ public void DockerfileTemplateExists(string targetFramework)
{
- var dockerFileTemplate = ProjectUtilities.ReadTemplate();
+ var dockerFileTemplate = ProjectUtilities.ReadTemplate(targetFramework);
Assert.False(string.IsNullOrWhiteSpace(dockerFileTemplate));
}
diff --git a/testapps/docker/WebAppNet7/Dockerfile b/testapps/docker/WebAppNet7/Dockerfile
index 74e72e8a5..2ffa8d437 100644
--- a/testapps/docker/WebAppNet7/Dockerfile
+++ b/testapps/docker/WebAppNet7/Dockerfile
@@ -1,15 +1,16 @@
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
-EXPOSE 80
+EXPOSE 80
EXPOSE 443
-FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
+FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:7.0 AS build
+ARG TARGETARCH
WORKDIR /src
COPY ["WebAppNet7.csproj", ""]
-RUN dotnet restore "WebAppNet7.csproj"
+RUN dotnet restore "WebAppNet7.csproj" -a $TARGETARCH
COPY . .
WORKDIR "/src/"
-RUN dotnet build "WebAppNet7.csproj" -c Release -o /app/build
+RUN dotnet build "WebAppNet7.csproj" -c Release -o /app/build -a $TARGETARCH
FROM build AS publish
RUN apt-get update -yq \
@@ -19,7 +20,7 @@ RUN apt-get update -yq \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
&& apt-get update -yq \
&& apt-get install nodejs -yq
-RUN dotnet publish "WebAppNet7.csproj" -c Release -o /app/publish
+RUN dotnet publish "WebAppNet7.csproj" -c Release -o /app/publish -a $TARGETARCH
FROM base AS final
WORKDIR /app
diff --git a/testapps/docker/WebAppNet7/ReferenceDockerfile b/testapps/docker/WebAppNet7/ReferenceDockerfile
index 74e72e8a5..4910f075e 100644
--- a/testapps/docker/WebAppNet7/ReferenceDockerfile
+++ b/testapps/docker/WebAppNet7/ReferenceDockerfile
@@ -3,13 +3,14 @@ WORKDIR /app
EXPOSE 80
EXPOSE 443
-FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
+FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:7.0 AS build
+ARG TARGETARCH
WORKDIR /src
COPY ["WebAppNet7.csproj", ""]
-RUN dotnet restore "WebAppNet7.csproj"
+RUN dotnet restore "WebAppNet7.csproj" -a $TARGETARCH
COPY . .
WORKDIR "/src/"
-RUN dotnet build "WebAppNet7.csproj" -c Release -o /app/build
+RUN dotnet build "WebAppNet7.csproj" -c Release -o /app/build -a $TARGETARCH
FROM build AS publish
RUN apt-get update -yq \
@@ -19,7 +20,7 @@ RUN apt-get update -yq \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
&& apt-get update -yq \
&& apt-get install nodejs -yq
-RUN dotnet publish "WebAppNet7.csproj" -c Release -o /app/publish
+RUN dotnet publish "WebAppNet7.csproj" -c Release -o /app/publish -a $TARGETARCH
FROM base AS final
WORKDIR /app
diff --git a/testapps/docker/WebAppNet8/Dockerfile b/testapps/docker/WebAppNet8/Dockerfile
index 60bf53e05..b2b83948e 100644
--- a/testapps/docker/WebAppNet8/Dockerfile
+++ b/testapps/docker/WebAppNet8/Dockerfile
@@ -1,16 +1,17 @@
-FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
+FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
-EXPOSE 8080
+EXPOSE 8080
EXPOSE 8081
-FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
+FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
+ARG TARGETARCH
WORKDIR /src
COPY ["WebAppNet8.csproj", ""]
-RUN dotnet restore "WebAppNet8.csproj"
+RUN dotnet restore "WebAppNet8.csproj" -a $TARGETARCH
COPY . .
WORKDIR "/src/"
-RUN dotnet build "WebAppNet8.csproj" -c Release -o /app/build
+RUN dotnet build "WebAppNet8.csproj" -c Release -o /app/build -a $TARGETARCH
FROM build AS publish
RUN apt-get update -yq \
@@ -20,7 +21,7 @@ RUN apt-get update -yq \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
&& apt-get update -yq \
&& apt-get install nodejs -yq
-RUN dotnet publish "WebAppNet8.csproj" -c Release -o /app/publish
+RUN dotnet publish "WebAppNet8.csproj" -c Release -o /app/publish -a $TARGETARCH
FROM base AS final
WORKDIR /app
diff --git a/testapps/docker/WebAppNet8/ReferenceDockerfile b/testapps/docker/WebAppNet8/ReferenceDockerfile
index 60bf53e05..1933f8754 100644
--- a/testapps/docker/WebAppNet8/ReferenceDockerfile
+++ b/testapps/docker/WebAppNet8/ReferenceDockerfile
@@ -4,13 +4,14 @@ WORKDIR /app
EXPOSE 8080
EXPOSE 8081
-FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
+FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
+ARG TARGETARCH
WORKDIR /src
COPY ["WebAppNet8.csproj", ""]
-RUN dotnet restore "WebAppNet8.csproj"
+RUN dotnet restore "WebAppNet8.csproj" -a $TARGETARCH
COPY . .
WORKDIR "/src/"
-RUN dotnet build "WebAppNet8.csproj" -c Release -o /app/build
+RUN dotnet build "WebAppNet8.csproj" -c Release -o /app/build -a $TARGETARCH
FROM build AS publish
RUN apt-get update -yq \
@@ -20,7 +21,7 @@ RUN apt-get update -yq \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
&& apt-get update -yq \
&& apt-get install nodejs -yq
-RUN dotnet publish "WebAppNet8.csproj" -c Release -o /app/publish
+RUN dotnet publish "WebAppNet8.csproj" -c Release -o /app/publish -a $TARGETARCH
FROM base AS final
WORKDIR /app