Skip to content
Merged
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
16 changes: 15 additions & 1 deletion src/Microsoft.DotNet.ImageBuilder/src/ViewModel/TagInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static TagInfo Create(
Model = model,
BuildContextPath = buildContextPath
};
tagInfo.Name = variableHelper.SubstituteValues(name);
tagInfo.Name = variableHelper.SubstituteValues(name, tagInfo.GetVariableValue);
tagInfo.FullyQualifiedName = GetFullyQualifiedName(repoName, tagInfo.Name);

if (model.Syndication != null)
Expand All @@ -55,5 +55,19 @@ public static string GetFullyQualifiedName(string repoName, string tagName)
{
return $"{repoName}:{tagName}";
}

private string GetVariableValue(string variableType, string variableName)
{
string variableValue = null;

if (string.Equals(variableType, VariableHelper.SystemVariableTypeId, StringComparison.Ordinal)
&& string.Equals(variableName, VariableHelper.DockerfileGitCommitShaVariableName, StringComparison.Ordinal)
&& BuildContextPath != null)
{
variableValue = GitHelper.GetCommitSha(BuildContextPath);
}

return variableValue;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ namespace Microsoft.DotNet.ImageBuilder.ViewModel
public class VariableHelper
{
private const char BuiltInDelimiter = ':';
public const string DockerfileGitCommitShaVariableName = "DockerfileGitCommitSha";
public const string McrTagsYmlRepoTypeId = "McrTagsYmlRepo";
public const string McrTagsYmlTagGroupTypeId = "McrTagsYmlTagGroup";
public const string RepoVariableTypeId = "Repo";
public const string SystemVariableTypeId = "System";
private const string VariableGroupName = "variable";

private static readonly string s_tagVariablePattern = $"\\$\\((?<{VariableGroupName}>[\\w:\\-.| ]+)\\)";
Expand Down Expand Up @@ -105,7 +107,14 @@ public VariableHelper(Manifest manifest, IManifestOptionsInfo options, Func<stri
string variableType = variableNameParts[0];
variableName = variableNameParts[1];

if (string.Equals(variableType, RepoVariableTypeId, StringComparison.Ordinal))
if (string.Equals(variableType, SystemVariableTypeId, StringComparison.Ordinal))
{
if (getContextBasedSystemValue != null)
{
variableValue = getContextBasedSystemValue(variableType, variableName);
}
}
else if (string.Equals(variableType, RepoVariableTypeId, StringComparison.Ordinal))
{
variableValue = GetRepoById(variableName)?.QualifiedName;
}
Expand Down
Loading