Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ user-token.json
/microservice/unityEngineStubs.addressables/bin/
/microservice/unityEngineStubs.addressables/obj/
/microservice/unityEngineStubs.addressables/.idea/
/microservice/unityenginestubs.addressables/bin/
/microservice/unityenginestubs.addressables/obj/
/microservice/unityenginestubs.addressables/.idea/
/microservice/microservice/bin/
/microservice/microservice/obj/
/microservice/microserviceTests/bin/
Expand Down
35 changes: 28 additions & 7 deletions cli/cli/Commands/Services/ServicesBuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,19 +470,16 @@ public static async Task<BuildImageOutput> Build(
message = "starting docker build..."
});

var defaultBaseImageTag = "8.0-alpine";
var targetFramework = http.Metadata.msbuildProject.GetPropertyValue("TargetFramework");
if (targetFramework.Contains("net10.0"))
{
defaultBaseImageTag = "10.0-alpine";
}
var containerFamily = http.Metadata.msbuildProject.GetPropertyValue("ContainerFamily");
var baseImageTag = GetBaseImageTag(targetFramework, containerFamily);

var tagString = string.Join(" ", tags.Select(tag => $"-t {id.ToLowerInvariant()}:{tag}"));
var fullDockerfilePath = http.AbsoluteDockerfilePath;
var tagString = string.Join(" ", tags.Select(tag => $"-t {id.ToLowerInvariant()}:{tag}"));
var argString = $"buildx build {fullContextPath.EnquotePath()} -f {fullDockerfilePath.EnquotePath()} " +
$"{tagString} " +
$"--progress rawjson " +
$"--build-arg BEAM_DOTNET_VERSION={defaultBaseImageTag} " +
$"--build-arg BEAM_DOTNET_VERSION={baseImageTag} " +
$"--build-arg BEAM_SUPPORT_SRC_PATH={Path.GetRelativePath(dockerContextPath, report.outputDirSupport).Replace("\\", "/")} " +
$"--build-arg BEAM_APP_SRC_PATH={Path.GetRelativePath(dockerContextPath,report.outputDirApp).Replace("\\", "/")} " +
$"--build-arg BEAM_APP_DEST=/beamApp/{definition.BeamoId}.dll " +
Expand Down Expand Up @@ -642,6 +639,30 @@ void PostMessage(BuildkitMessage msg)
};
}

/// <summary>
/// Returns the base image tag for the given target framework and container family.
/// The <paramref name="containerFamily"/> value is read from the MSBuild <c>ContainerFamily</c>
/// property and should be either "alpine" or "noble". Defaults to "alpine" when not set or
/// when an unrecognised value is provided.
/// </summary>
public static string GetBaseImageTag(string targetFramework, string containerFamily)
{
// Validate containerFamily against known supported values; fall back to "alpine".
var knownFamilies = new[] { "alpine", "noble" };
var family = knownFamilies.Contains(containerFamily, StringComparer.OrdinalIgnoreCase)
? containerFamily
: "alpine";

// Extract the dotnet version number from strings like "net8.0", "net10.0", etc.
// The TargetFramework moniker starts with "net" followed by the version number.
const string prefix = "net";
var version = targetFramework.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)
? targetFramework.Substring(prefix.Length)
: targetFramework;

return $"{version}-{family}";
}

/// <summary>
/// From observation, the structure of the rawjson mostly follows the proto definition,
/// https://github.com/moby/buildkit/blob/master/api/services/control/control.proto#L115
Expand Down