-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perform explicit Rid-to-Docker-Platform mapping and support solution-…
…level pushes
- Loading branch information
Showing
8 changed files
with
415 additions
and
30 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
src/Containers/Microsoft.NET.Build.Containers/PlatformMapping.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Microsoft.NET.Build.Containers; | ||
|
||
/// <summary> | ||
/// Handles mapping between .NET RIDs and Docker platform names/structures | ||
/// </summary> | ||
public static class PlatformMapping { | ||
|
||
public static bool TryGetRidForDockerPlatform(string golangPlatform, bool isMuslBased, [NotNullWhen(true)] out string? runtimeIdentifier) { | ||
runtimeIdentifier = null; | ||
|
||
runtimeIdentifier = golangPlatform.Split('/') switch { | ||
["linux", "amd64"] when isMuslBased => "linux-musl-x64", | ||
["linux", "amd64"] => "linux-x64", | ||
|
||
["linux", "amd64", var _amd64Version] when isMuslBased => "linux-musl-x64", | ||
["linux", "amd64", var _amd64Version] => "linux-x64", | ||
|
||
["linux", "arm64"] when isMuslBased => "linux-musl-arm64", | ||
["linux", "arm64"] => "linux-arm64", | ||
|
||
["linux", "arm64", var _arm64Version ] when isMuslBased => "linux-musl-arm64", | ||
["linux", "arm64", var _arm64Version ] => "linux-arm64", | ||
|
||
["linux", "arm" ] or ["linux", "arm", "v7" ] when isMuslBased => "linux-musl-arm", | ||
["linux", "arm" ] or ["linux", "arm", "v7" ] => "linux-arm", | ||
|
||
["linux", "arm", "v6" ] when isMuslBased => "linux-musl-armv6", | ||
["linux", "arm", "v6" ] => "linux-armv6", | ||
|
||
["linux", "riscv64" ] when isMuslBased => "linux-musl-riscv64", | ||
["linux", "riscv64" ] => "linux-riscv64", | ||
|
||
["linux", "ppc64le" ] when isMuslBased => "linux-musl-ppc64le", | ||
["linux", "ppc64le" ] => "linux-ppc64le", | ||
|
||
["linux", "s390x" ] when isMuslBased => "linux-musl-s390x", | ||
["linux", "s390x" ] => "linux-s390x", | ||
|
||
["linux", "386" ] when isMuslBased => "linux-musl-x86", | ||
["linux", "386" ] => "linux-x86", | ||
|
||
["windows", "amd64"] => "win-x64", | ||
["windows", "arm64"] => "win-arm64", | ||
|
||
_ => null // other golang platforms are not supported | ||
}; | ||
return runtimeIdentifier != null; | ||
} | ||
|
||
public static bool TryGetDockerPlatformForRid(string runtimeIdentifier, [NotNullWhen(true)] out string? dockerPlatform) { | ||
dockerPlatform = null; | ||
|
||
runtimeIdentifier = runtimeIdentifier.Replace("-musl-", "-"); // we lose musl information in the docker platform name | ||
|
||
dockerPlatform = runtimeIdentifier.Split('-') switch { | ||
["linux", "x64"] => "linux/amd64", | ||
["linux", "arm64"] => "linux/arm64", | ||
["linux", "arm"] => "linux/arm/v7", | ||
["linux", "armv6"] => "linux/arm/v6", | ||
["linux", "riscv64"] => "linux/riscv64", | ||
["linux", "ppc64le"] => "linux/ppc64le", | ||
["linux", "s390x"] => "linux/s390x", | ||
["linux", "x86"] => "linux/386", | ||
["win", "x64"] => "windows/amd64", | ||
["win", "arm64"] => "windows/arm64", | ||
_ => null | ||
}; | ||
return dockerPlatform != null; | ||
} | ||
|
||
public static bool TryGetDockerImageTagForRid(string runtimeIdentifier, [NotNullWhen(true)] out string? dockerPlatformTag) { | ||
dockerPlatformTag = null; | ||
|
||
runtimeIdentifier = runtimeIdentifier.Replace("-musl-", "-"); // we lose musl information in the docker platform name | ||
|
||
dockerPlatformTag = runtimeIdentifier.Split('-') switch { | ||
["linux", "x64"] => "amd64", | ||
["linux", "arm64"] => "arm64v8", | ||
["linux", "arm"] => "arm32v7", | ||
["linux", "armv6"] => "arm32v6", | ||
["linux", "riscv64"] => "riscv64", | ||
["linux", "ppc64le"] => "ppc64le", | ||
["linux", "s390x"] => "s390x", | ||
["linux", "x86"] => "386", | ||
_ => null // deliberately not trying to make tag names for windows containers | ||
}; | ||
return dockerPlatformTag != null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/Containers/Microsoft.NET.Build.Containers/Tasks/MapRidToDockerPlatform.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.Build.Framework; | ||
|
||
namespace Microsoft.NET.Build.Containers.Tasks; | ||
|
||
public sealed class MapRidToDockerPlatform : Microsoft.Build.Utilities.Task | ||
{ | ||
[Required] | ||
public ITaskItem[] RuntimeIdentifiers { get; set; } | ||
|
||
[Output] | ||
public ITaskItem[] ModifiedRuntimeIdentifiers { get; set; } | ||
|
||
public MapRidToDockerPlatform() | ||
{ | ||
RuntimeIdentifiers = Array.Empty<ITaskItem>(); | ||
ModifiedRuntimeIdentifiers = Array.Empty<ITaskItem>(); | ||
} | ||
public override bool Execute() | ||
{ | ||
bool result = true; | ||
var modifiedRuntimeIdentifiers = new List<ITaskItem>(RuntimeIdentifiers.Length); | ||
foreach (ITaskItem rid in RuntimeIdentifiers) { | ||
if (PlatformMapping.TryGetDockerImageTagForRid(rid.ItemSpec, out string? dockerPlatform)) | ||
{ | ||
rid.SetMetadata("DockerPlatformTag", dockerPlatform); | ||
modifiedRuntimeIdentifiers.Add(rid); | ||
} | ||
else { | ||
Log.LogError($"No Docker platform mapping found for RuntimeIdentifier '{rid.ItemSpec}'"); | ||
result = false; | ||
} | ||
} | ||
ModifiedRuntimeIdentifiers = modifiedRuntimeIdentifiers.ToArray(); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.