Fix errors when update-dependencies only updates Ubuntu Chisel tool (#4724)

This commit is contained in:
Logan Bussell 2023-07-13 09:45:40 -07:00
Родитель f959c2c9ae
Коммит 97c316ed78
9 изменённых файлов: 117 добавлений и 42 удалений

Просмотреть файл

@ -1,8 +1,13 @@
{{
set dotnetVersion to join(slice(split(PRODUCT_VERSION, "."), 0, 2), ".") ^
set osVersionBase to match(OS_VERSION, ".+(?=.*-)")[0] ^
set osVersionNumber to split(OS_ARCH_HYPHENATED, "-")[1] ^
set chiselDir to "/opt/chisel" ^
set chiselUrl to VARIABLES[cat("chisel|", dotnetVersion, "|url")] ^
set chiselRef to VARIABLES[cat("chisel|", dotnetVersion, "|ref")] ^
set rocksToolboxDir to "/opt/rocks-toolbox" ^
set rocksToolboxUrl to VARIABLES[cat("rocks-toolbox|", dotnetVersion, "|url")] ^
set rocksToolboxRef to VARIABLES[cat("rocks-toolbox|", dotnetVersion, "|ref")] ^
set username to "app" ^
set uid to 1654 ^
set gid to uid
@ -14,14 +19,14 @@ RUN apt-get update \
file
RUN {{InsertTemplate("../Dockerfile.git-clone", [
"url": VARIABLES["chisel|url"],
"ref": VARIABLES["chisel|ref"],
"url": chiselUrl,
"ref": chiselRef,
"dir": chiselDir
], " ")}} \
\
&& {{InsertTemplate("../Dockerfile.git-clone", [
"url": VARIABLES["rocks-toolbox|url"],
"ref": VARIABLES["rocks-toolbox|ref"],
"url": rocksToolboxUrl,
"ref": rocksToolboxRef,
"dir": rocksToolboxDir
], " ")}}

Просмотреть файл

@ -1,25 +0,0 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using System.Linq;
using Microsoft.DotNet.VersionTools.Dependencies;
#nullable enable
namespace Dotnet.Docker;
internal class BasicVariableUpdater : VariableUpdaterBase
{
private readonly string _newValue;
public BasicVariableUpdater(string repoRoot, string variableName, string newValue) : base(repoRoot, variableName)
{
_newValue = newValue;
}
protected sealed override string TryGetDesiredValue(IEnumerable<IDependencyInfo> dependencyInfos, out IEnumerable<IDependencyInfo> usedDependencyInfos)
{
usedDependencyInfos = Enumerable.Empty<IDependencyInfo>();
return _newValue;
}
}

Просмотреть файл

@ -0,0 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#nullable enable
namespace Dotnet.Docker;
internal class ChiselRefUpdater : ChiselToolUpdater
{
public ChiselRefUpdater(string repoRoot, string dockerfileVersion, string newRef)
: base(repoRoot, $"chisel|{dockerfileVersion}|ref", dockerfileVersion, newRef) { }
}

Просмотреть файл

@ -0,0 +1,53 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using System.Linq;
using Microsoft.DotNet.VersionTools.Dependencies;
#nullable enable
namespace Dotnet.Docker;
internal class ChiselToolUpdater : VariableUpdaterBase
{
private readonly string _dockerfileVersion;
private readonly string _newValue;
public ChiselToolUpdater(string repoRoot, string variableName, string dockerfileVersion, string newRef) : base(repoRoot, variableName)
{
_dockerfileVersion = dockerfileVersion;
_newValue = newRef;
}
protected sealed override string TryGetDesiredValue(IEnumerable<IDependencyInfo> dependencyInfos, out IEnumerable<IDependencyInfo> usedDependencyInfos)
{
IDependencyInfo? runtimeDependencyInfo = dependencyInfos.FirstOrDefault(info => info.SimpleName == "runtime");
usedDependencyInfos = Enumerable.Empty<IDependencyInfo>();
string currentChiselToolVersion = ManifestHelper.TryGetVariableValue(VariableName, ManifestVariables.Value);
if (string.IsNullOrEmpty(currentChiselToolVersion))
{
return "";
}
// Avoid updating the chisel tooling if we are updating a runtime
// version that doesn't ship chiseled images
if (runtimeDependencyInfo is null)
{
return currentChiselToolVersion;
}
// Avoid updating chisel tooling unless we already know we are
// rebuilding at least the runtime images, since changing the chisel
// tool shouldn't make a difference in the output image.
string runtimeVariableName = ManifestHelper.GetVersionVariableName(VersionType.Build, "runtime", _dockerfileVersion);
string currentRuntimeVersion = ManifestHelper.GetVariableValue(runtimeVariableName, ManifestVariables.Value);
if (runtimeDependencyInfo.SimpleVersion == currentRuntimeVersion)
{
return currentChiselToolVersion;
}
usedDependencyInfos = new[] { runtimeDependencyInfo };
return _newValue;
}
}

Просмотреть файл

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
//
using System;
using System.IO;
using System.Text.RegularExpressions;
using Newtonsoft.Json.Linq;
@ -36,13 +37,28 @@ public static class ManifestHelper
return $"base-url|{version}|{branch}";
}
public static string GetVersionVariableName(VersionType versionType, string productName, string dockerfileVersion) =>
$"{productName}|{dockerfileVersion}|{versionType.ToString().ToLowerInvariant()}-version";
/// <summary>
/// Gets the value of a manifest variable, returns an empty string if it is not defined.
/// </summary>
/// <param name="variableName">Name of the variable.</param>
/// <param name="variables">JSON object of the variables from the manifest.</param>
public static string TryGetVariableValue(string variableName, JObject variables)
=> variables.ContainsKey(variableName) ? GetVariableValue(variableName, variables) : "";
/// <summary>
/// Gets the value of a manifest variable.
/// </summary>
/// <param name="variableName">Name of the variable.</param>
/// <param name="variables">JSON object of the variables from the manifest.</param>
public static string GetVariableValue(string variableName, JObject variables) =>
ResolveVariables((string)variables[variableName], variables);
public static string GetVariableValue(string variableName, JObject variables)
{
string variableValue = (string?) variables[variableName]
?? throw new ArgumentException($"Manifest does not contain a value for {variableName}");
return ResolveVariables(variableValue, variables);
}
/// <summary>
/// Loads the manifest from the given filename.

Просмотреть файл

@ -0,0 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#nullable enable
namespace Dotnet.Docker;
internal class RocksToolboxRefUpdater : ChiselToolUpdater
{
public RocksToolboxRefUpdater(string repoRoot, string dockerfileVersion, string newRef)
: base(repoRoot, $"rocks-toolbox|{dockerfileVersion}|ref", dockerfileVersion, newRef) { }
}

Просмотреть файл

@ -418,8 +418,11 @@ namespace Dotnet.Docker
new BaseUrlUpdater(RepoRoot, Options),
new MinGitUrlUpdater(RepoRoot, minGitRelease),
new MinGitShaUpdater(RepoRoot, minGitRelease),
new BasicVariableUpdater(RepoRoot, "chisel|ref", chiselRef),
new BasicVariableUpdater(RepoRoot, "rocks-toolbox|ref", rocksToolboxRef)
// Chisel updaters must be listed before runtime version
// updaters because they check the manifest for whether the
// runtime versions are being updated or not
new ChiselRefUpdater(RepoRoot, Options.DockerfileVersion, chiselRef),
new RocksToolboxRefUpdater(RepoRoot, Options.DockerfileVersion, rocksToolboxRef)
};
foreach (string productName in Options.ProductVersions.Keys)

Просмотреть файл

@ -29,7 +29,7 @@ namespace Dotnet.Docker
_productName = productName;
_options = options;
_versionType = versionType;
string versionVariableName = GetVersionVariableName(versionType, productName, dockerfileVersion);
string versionVariableName = ManifestHelper.GetVersionVariableName(versionType, productName, dockerfileVersion);
Trace.TraceInformation($"Updating {versionVariableName}");
@ -63,7 +63,7 @@ namespace Dotnet.Docker
productName = "sdk";
}
string versionVariableName = GetVersionVariableName(VersionType.Build, productName, dockerfileVersion);
string versionVariableName = ManifestHelper.GetVersionVariableName(VersionType.Build, productName, dockerfileVersion);
Regex regex = GetVersionVariableRegex(versionVariableName);
Match match = regex.Match(variables);
if (!match.Success)
@ -103,9 +103,6 @@ namespace Dotnet.Docker
ManifestHelper.GetManifestVariableRegex(
versionVariableName,
$"(?<{s_versionGroupName}>[\\d]+.[\\d]+.[\\d]+(-[\\w]+(.[\\d]+)*)?)");
private static string GetVersionVariableName(VersionType versionType, string productName, string dockerfileVersion) =>
$"{productName}|{dockerfileVersion}|{versionType.ToString().ToLowerInvariant()}-version";
}
}
#nullable disable

Просмотреть файл

@ -63,8 +63,10 @@
"base-url|8.0-monitor|main": "$(base-url|public|main)",
"base-url|8.0-monitor|nightly": "$(base-url|public|nightly)",
"chisel|url": "https://github.com/canonical/chisel",
"chisel|ref": "00f796f17323422704241517aa0386ded5e0fba1",
"chisel|6.0|url": "https://github.com/canonical/chisel",
"chisel|8.0|url": "$(chisel|6.0|url)",
"chisel|6.0|ref": "00f796f17323422704241517aa0386ded5e0fba1",
"chisel|8.0|ref": "00f796f17323422704241517aa0386ded5e0fba1",
"dotnet|6.0|product-version": "6.0.20",
"dotnet|7.0|product-version": "7.0.9",
@ -145,8 +147,10 @@
"powershell|8.0|Linux|x64|sha": "a311864c219ba4a6b2b87dce61240545bf3a62a426462cf43999dc6ea7168e09a2799cffe79219bbe1fcae67b1baece105c4bbee6bcbd13d357586ab6ca57e7a",
"powershell|8.0|Windows|x64|sha": "e1c97f48e5de1b38dfaf60be1085c3f6c996c61a5ce1a20dec0a9e50bb747cccf816c6778f77951cff7f3b24095d7e7f849bc9b222e139ef07c7b90381a4b21b",
"rocks-toolbox|url": "https://github.com/canonical/rocks-toolbox",
"rocks-toolbox|ref": "e92d18b733647e77b6829968c91f8a16d25c1f2d",
"rocks-toolbox|6.0|url": "https://github.com/canonical/rocks-toolbox",
"rocks-toolbox|8.0|url": "$(rocks-toolbox|6.0|url)",
"rocks-toolbox|6.0|ref": "e92d18b733647e77b6829968c91f8a16d25c1f2d",
"rocks-toolbox|8.0|ref": "e92d18b733647e77b6829968c91f8a16d25c1f2d",
"runtime|6.0|build-version": "6.0.20",
"runtime|6.0|targeting-pack-version": "$(runtime|6.0|build-version)",