Skip to content

Commit

Permalink
Merge branch 'main' into support-other-arch-and-os
Browse files Browse the repository at this point in the history
  • Loading branch information
baronfel authored Jan 19, 2023
2 parents 18ccb52 + cb86a38 commit af582c5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageVersion Include="Microsoft.Build.Locator" Version="1.5.5" />
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="17.3.1" />
<PackageVersion Include="Microsoft.Build" Version="17.3.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageVersion Include="Microsoft.VisualStudioEng.MicroBuild.Core" Version="1.0.0" />
<PackageVersion Include="MSTest.TestAdapter" Version="2.3.0-preview-20220810-02" />
<PackageVersion Include="MSTest.TestFramework" Version="2.2.10" />
Expand Down
4 changes: 2 additions & 2 deletions Microsoft.NET.Build.Containers/ContainerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.NET.Build.Containers;

public static class ContainerBuilder
{
public static async Task Containerize(DirectoryInfo folder, string workingDir, string registryName, string baseName, string baseTag, string[] entrypoint, string[] entrypointArgs, string imageName, string[] imageTags, string outputRegistry, string[] labels, Port[] exposedPorts, string[] envVars, string containerRuntimeIdentifier, string ridGraphPath)
public static async Task Containerize(DirectoryInfo folder, string workingDir, string registryName, string baseName, string baseTag, string[] entrypoint, string[] entrypointArgs, string imageName, string[] imageTags, string? outputRegistry, string[] labels, Port[] exposedPorts, string[] envVars, string containerRuntimeIdentifier, string ridGraphPath)
{
var isDockerPull = String.IsNullOrEmpty(registryName);
if (isDockerPull) {
Expand All @@ -34,7 +34,7 @@ public static async Task Containerize(DirectoryInfo folder, string workingDir, s
img.SetEntrypoint(entrypoint, entrypointArgs);

var isDockerPush = String.IsNullOrEmpty(outputRegistry);
Registry? outputReg = isDockerPush ? null : new Registry(ContainerHelpers.TryExpandRegistryToUri(outputRegistry));
Registry? outputReg = isDockerPush ? null : new Registry(ContainerHelpers.TryExpandRegistryToUri(outputRegistry!));

foreach (var label in labels)
{
Expand Down
5 changes: 4 additions & 1 deletion Microsoft.NET.Build.Containers/ContainerHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public static class ContainerHelpers

public const string HostObjectPass = "SDK_CONTAINER_REGISTRY_PWORD";

private static Regex envVarRegex = new Regex(@"^[a-zA-Z_]+$");
/// <summary>
/// Matches an environment variable name - must start with a letter or underscore, and can only contain letters, numbers, and underscores.
/// </summary>
private static Regex envVarRegex = new Regex(@"^[a-zA-Z_]{1,}[a-zA-Z0-9_]*$");

/// <summary>
/// DefaultRegistry is the canonical representation of something that lives in the local docker daemon. It's used as the inferred registry for repositories
Expand Down
2 changes: 1 addition & 1 deletion Microsoft.NET.Build.Containers/CreateNewImageToolTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected override string GenerateCommandLineCommands()
" --baseregistry " + BaseRegistry +
" --baseimagename " + BaseImageName +
" --baseimagetag " + BaseImageTag +
" --outputregistry " + OutputRegistry +
(OutputRegistry is not null ? " --outputregistry " + OutputRegistry : "") +
" --imagename " + ImageName +
" --workingdirectory " + WorkingDirectory +
(Entrypoint.Length > 0 ? " --entrypoint " + String.Join(" ", Entrypoint.Select((i) => i.ItemSpec)) : "") +
Expand Down
14 changes: 14 additions & 0 deletions Test.Microsoft.NET.Build.Containers/ContainerHelpersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,18 @@ public void CanParsePort(string input, bool shouldParse, int? expectedPortNumber
Assert.AreEqual(expectedError, errors);
}
}

[TestMethod]
[DataRow("FOO", true)]
[DataRow("foo_bar", true)]
[DataRow("foo-bar", false)]
[DataRow("foo.bar", false)]
[DataRow("foo bar", false)]
[DataRow("1_NAME", false)]
[DataRow("ASPNETCORE_URLS", true)]
[DataRow("ASPNETCORE_URLS2", true)]
public void CanRecognizeEnvironmentVariableNames(string envVarName, bool isValid) {
var success = ContainerHelpers.IsValidEnvironmentVariable(envVarName);
Assert.AreEqual(isValid, success, $"Expected {envVarName} to be {(isValid ? "valid" : "invalid")}");
}
}
4 changes: 2 additions & 2 deletions containerize/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
name: "--outputregistry",
description: "The registry to push to.")
{
IsRequired = true
IsRequired = false
};

var imageNameOpt = new Option<string>(
Expand Down Expand Up @@ -180,7 +180,7 @@
string _baseReg = context.ParseResult.GetValueForOption(baseRegistryOpt) ?? "";
string _baseName = context.ParseResult.GetValueForOption(baseImageNameOpt) ?? "";
string _baseTag = context.ParseResult.GetValueForOption(baseImageTagOpt) ?? "";
string _outputReg = context.ParseResult.GetValueForOption(outputRegistryOpt) ?? "";
string? _outputReg = context.ParseResult.GetValueForOption(outputRegistryOpt);
string _name = context.ParseResult.GetValueForOption(imageNameOpt) ?? "";
string[] _tags = context.ParseResult.GetValueForOption(imageTagsOpt) ?? Array.Empty<string>();
string _workingDir = context.ParseResult.GetValueForOption(workingDirectoryOpt) ?? "";
Expand Down

0 comments on commit af582c5

Please sign in to comment.