Skip to content
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

fix: fix an issue causing container deployments to fail when run on an ARM-based system #861

Merged
merged 1 commit into from
Sep 26, 2024

Conversation

philasmar
Copy link
Contributor

@philasmar philasmar commented Sep 18, 2024

Issue #, if available:
DOTNET-7715

Description of changes:

  • Updated the default Dockerfile template to include a fix for the hanging dotnet restore in docker build. This follows the following Microsoft blog https://devblogs.microsoft.com/dotnet/improving-multiplatform-container-support/. This fix only applies to .NET7 and newer since the -a argument was added in .NET7.
  • Added a 2nd Dockerfile template which maintains the current behavior for .NET6 and older.
  • Fixed an issue where the correct version of AWS.Deploy.Recipes.CDK.Common is not used in the CDK projects which was broken after we dropped Nerdback.GitVersioning. This issue does not currently exist in production. It is localized to the dev branch.
  • This update will change the behavior of existing customers with generated dockerfiles. If they used the deploy tool to generate a dockerfile, if they try to build that image on an ARM-based system, the docker build will hang. As opposed to the previous behavior where the docker build succeeds but the deployment fails. This change does not break an existing use case, but changes where the issue occurs. The fix is to simply delete the dockerfile and let the deploy tool generate a new one.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@philasmar philasmar marked this pull request as draft September 18, 2024 16:35
Copy link

codecov bot commented Sep 18, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 62.39%. Comparing base (da8b3eb) to head (4299917).
Report is 1 commits behind head on dev.

Files with missing lines Patch % Lines
...WS.Deploy.Orchestration/DeploymentBundleHandler.cs 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #861      +/-   ##
==========================================
+ Coverage   62.36%   62.39%   +0.02%     
==========================================
  Files         279      279              
  Lines       10900    10905       +5     
  Branches     1513     1515       +2     
==========================================
+ Hits         6798     6804       +6     
+ Misses       3566     3564       -2     
- Partials      536      537       +1     
Flag Coverage Δ
62.39% <80.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@philasmar philasmar force-pushed the asmarp/fix-docker-on-arm branch 5 times, most recently from 62dbba8 to 86e102f Compare September 19, 2024 17:05
{
var template = Assembly.GetExecutingAssembly().ReadEmbeddedFile(DockerfileTemplate);
string templateLocation;
switch (targetFramework)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am specifically checking the following target framework to maintain consistency with other parts of the codebase that also have the same check for different purposes.

@@ -0,0 +1,26 @@
FROM {docker-base-image} AS base{non-root-user}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The fix to container deployments only applies to .NET 7 and newer, so this dockerfile template is the version we currently use and will continue to be used for .NET6 and older targets.

@@ -7,10 +7,6 @@
<RootNamespace>AWS.Deploy.Orchestration</RootNamespace>
</PropertyGroup>

<ItemGroup>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a project reference to AWS.Deploy.Recipes.CDK.Common so this reference is no longer needed.

@@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't currently support running tests on non X64 architectures, so this code path will not be tested in our CI. However, this code path is covered using existing tests when run on ARM.

@@ -67,7 +67,7 @@ public void GenerateCDKProjectFromTemplate(Recommendation recommendation, Orches
var templateParameters = new Dictionary<string, string> {
// 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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we dropped Nerdbank.GitVersioning, this code was bugged as it always returned 1.0.0. This is because Constants.CloudFormationIdentifier is part of AWS.Deploy.Orchestration which is not versioned. This is why I added a project reference to AWS.Deploy.Recipes.CDK.Common and used AWS.Deploy.Recipes.CDK.Common.CDKRecipeSetup which is versioned by AutoVer.

@philasmar philasmar requested review from normj and 96malhar September 20, 2024 15:29
@philasmar philasmar marked this pull request as ready for review September 20, 2024 15:29
@philasmar philasmar force-pushed the asmarp/fix-docker-on-arm branch from 86e102f to 4299917 Compare September 20, 2024 16:34
@philasmar philasmar merged commit aeef93d into dev Sep 26, 2024
11 checks passed
@philasmar philasmar deleted the asmarp/fix-docker-on-arm branch September 26, 2024 17:20
@philasmar philasmar restored the asmarp/fix-docker-on-arm branch September 26, 2024 17:20
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