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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ public interface IOptions
{
bool IsDryRun { get; }
bool IsVerbose { get; }
string GetOption(string name);
}
}
18 changes: 0 additions & 18 deletions src/Microsoft.DotNet.ImageBuilder/src/Commands/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,6 @@ public class Options : IOptions
{
public bool IsDryRun { get; set; }
public bool IsVerbose { get; set; }

public string? GetOption(string name)
{
string? result;

PropertyInfo? propInfo = GetType().GetProperties()
.FirstOrDefault(p => string.Equals(p.Name, name, StringComparison.Ordinal));
if (propInfo != null)
{
result = propInfo.GetValue(this)?.ToString() ?? "";
}
else
{
result = null;
}

return result;
}
}

public class CliOptionsBuilder
Expand Down
16 changes: 1 addition & 15 deletions 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.GetVariableValue);
tagInfo.Name = variableHelper.SubstituteValues(name);
tagInfo.FullyQualifiedName = GetFullyQualifiedName(repoName, tagInfo.Name);

if (model.Syndication != null)
Expand All @@ -55,19 +55,5 @@ 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,12 +13,9 @@ 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 TimeStampVariableName = "TimeStamp";
private const string VariableGroupName = "variable";

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

if (string.Equals(variableType, SystemVariableTypeId, StringComparison.Ordinal))
{
if (string.Equals(variableName, TimeStampVariableName, StringComparison.Ordinal))
{
variableValue = s_timeStamp;
}
else if (getContextBasedSystemValue != null)
{
variableValue = getContextBasedSystemValue(variableType, variableName);
}
else
{
variableValue = Options.GetOption(variableName);
Copy link
Member Author

@MichaelSimons MichaelSimons Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find a usage of system variables being specified as an option. Not 100% certain though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't see any usage of it either.

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