diff --git a/.gitignore b/.gitignore index d68f38e043..64aec4c940 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/cli/cli/Commands/Services/ServicesBuildCommand.cs b/cli/cli/Commands/Services/ServicesBuildCommand.cs index 8e7914f8ef..991e02db13 100644 --- a/cli/cli/Commands/Services/ServicesBuildCommand.cs +++ b/cli/cli/Commands/Services/ServicesBuildCommand.cs @@ -470,19 +470,16 @@ public static async Task 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 " + @@ -642,6 +639,30 @@ void PostMessage(BuildkitMessage msg) }; } + /// + /// Returns the base image tag for the given target framework and container family. + /// The value is read from the MSBuild ContainerFamily + /// property and should be either "alpine" or "noble". Defaults to "alpine" when not set or + /// when an unrecognised value is provided. + /// + 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}"; + } + /// /// 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