Skip to content

Commit

Permalink
Merge pull request #155 from rasmus/container-fixes
Browse files Browse the repository at this point in the history
Fix a few issues related to containers
  • Loading branch information
rasmus authored Dec 11, 2022
2 parents e06c146 + b267be1 commit 7f3499b
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 19 deletions.
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# 0.19-beta

* New: Clean `v|version` prefix for semantic versions
* New: Now possible to control the container name for .NET service using
a `bake.yaml` file
* New: `DOTNET_ROLL_FORWARD` now defaults to `LatestMajor`
* Fixed: Container paths that contain `/` are now valid

# 0.18-beta

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task Run()
{
// Arrange
var version = SemVer.Random.ToString();
var expectedImage = $"bake.local/netcore-service:{version}";
var expectedImage = $"bake.local/awesome-net-core-service:{version}";

// Act
var returnCode = await ExecuteAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ protected override IServiceCollection Configure(IServiceCollection serviceCollec
.AddSingleton(TestEnvironmentVariables.None)
.AddTransient<IConventionInterpreter, ConventionInterpreter>()
.AddTransient<IDotNetTfmParser, DotNetTfmParser>()
.AddTransient<IDockerLabels, DockerLabels>();
.AddTransient<IDockerLabels, DockerLabels>()
.AddTransient<IBakeProjectParser, BakeProjectParser>()
.AddTransient<IYaml, Yaml>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public class ContainerTagParserTests : TestFor<ContainerTagParser>
"",
"image",
"v1.2.3")]
[TestCase(
"containers.example.org/my-org/my-path/somecontainer:v1.2.3",
"containers.example.org",
"my-org/my-path",
"somecontainer",
"v1.2.3")]
public void SuccessTryParse(
string image,
string expectedHostAndPort,
Expand Down
30 changes: 28 additions & 2 deletions Source/Bake/Cooking/Composers/DotNetComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class DotNetComposer : Composer
private readonly IDefaults _defaults;
private readonly IDockerLabels _dockerLabels;
private readonly IDescriptionLimiter _descriptionLimiter;
private readonly IBakeProjectParser _bakeProjectParser;

public DotNetComposer(
ILogger<DotNetComposer> logger,
Expand All @@ -80,7 +81,8 @@ public DotNetComposer(
IConventionInterpreter conventionInterpreter,
IDefaults defaults,
IDockerLabels dockerLabels,
IDescriptionLimiter descriptionLimiter)
IDescriptionLimiter descriptionLimiter,
IBakeProjectParser bakeProjectParser)
{
_logger = logger;
_fileSystem = fileSystem;
Expand All @@ -89,6 +91,7 @@ public DotNetComposer(
_defaults = defaults;
_dockerLabels = dockerLabels;
_descriptionLimiter = descriptionLimiter;
_bakeProjectParser = bakeProjectParser;
}

public override async Task<IReadOnlyCollection<Recipe>> ComposeAsync(
Expand Down Expand Up @@ -145,8 +148,31 @@ private async Task<VisualStudioProject> LoadVisualStudioProjectAsync(
projectPath,
cancellationToken);

var bakeProjectFilePath = Path.Combine(
Path.GetDirectoryName(projectPath)!,
"bake.yaml");
string preferredName = null;

if (_fileSystem.FileExists(bakeProjectFilePath))
{
var yaml = await _fileSystem.ReadAllTextAsync(bakeProjectFilePath, cancellationToken);
var bakeProject = await _bakeProjectParser.ParseAsync(yaml, cancellationToken);
if (!string.IsNullOrEmpty(bakeProject.Name))
{
preferredName = bakeProject.Name;
}
}

var name = Path.GetFileNameWithoutExtension(projectPath);
if (string.IsNullOrEmpty(preferredName))
{
preferredName = name;
}

return new VisualStudioProject(
projectPath,
name,
preferredName,
csProj);
}

Expand Down Expand Up @@ -249,7 +275,7 @@ private IEnumerable<Recipe> CreateRecipe(
moniker,
labels,
new DockerFileArtifact(
visualStudioProject.Name,
visualStudioProject.PreferredName,
Path.Combine(visualStudioProject.Directory, "Dockerfile")));
}

Expand Down
2 changes: 2 additions & 0 deletions Source/Bake/Core/Defaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class Defaults : IDefaults
public string GitHubUserRegistry { get; private set; } = "ghcr.io/{USER}/";
public bool DockerBuildCompress { get; private set; } = true;
public string GoLdFlags { get; private set; } = "-s -w";
public string DotNetRollForward { get; private set; } = "LatestMajor";

public Defaults(
IEnvironmentVariables environmentVariables)
Expand All @@ -59,6 +60,7 @@ public async Task InitializeAsync(
DockerHubUserRegistry = GetString(e, "dockerhub_user_url", DockerHubUserRegistry);
DockerBuildCompress = GetBool(e, "docker_build_compress", true);
GoLdFlags = GetString(e, "go_ldflags", GoLdFlags);
DotNetRollForward = GetString(e, "dotnet_roll_forward", DotNetRollForward);
}

private static bool GetBool(
Expand Down
1 change: 1 addition & 0 deletions Source/Bake/Core/IDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public interface IDefaults

bool DockerBuildCompress { get; }
string GoLdFlags { get; }
string DotNetRollForward { get; }

Task InitializeAsync(
CancellationToken cancellationToken);
Expand Down
2 changes: 1 addition & 1 deletion Source/Bake/Services/ContainerTagParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ContainerTagParser : IContainerTagParser
private static readonly Regex ImageParser = new(
@"^
(?<hostAndPort>[a-z\-0-9\.]+(:[0-9]+){0,1}/){0,1}
(?<path>[a-z\-0-9]+/){0,1}
(?<path>[a-z\-0-9/]+/){0,1}
(?<name>[a-z\-0-9]+)
(:(?<label>[a-z\-0-9\.]+)){0,1}
$",
Expand Down
4 changes: 2 additions & 2 deletions Source/Bake/Services/CsProjParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@
// SOFTWARE.

using System;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.Xml.XPath;
using Bake.ValueObjects.DotNet;
using File = System.IO.File;

namespace Bake.Services
{
public class CsProjParser : ICsProjParser
{
private readonly IDotNetTfmParser _dotNetTfmParser;

public CsProjParser(
IDotNetTfmParser dotNetTfmParser)
{
Expand Down
28 changes: 18 additions & 10 deletions Source/Bake/Services/Tools/DotNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,28 @@ namespace Bake.Services.Tools
{
public class DotNet : IDotNet
{
private static readonly IReadOnlyDictionary<string, string> DotNetEnvironmentVariable = new ConcurrentDictionary<string, string>
{
["DOTNET_CLI_TELEMETRY_OPTOUT"] = "true",
["DOTNET_NOLOGO"] = "true",
["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "true",
["NUGET_XMLDOC_MODE"] = "skip",
["NUGET_EXE_NO_PROMPT"] = "true"
};
private readonly IReadOnlyDictionary<string, string> DotNetEnvironmentVariable;
private readonly IRunnerFactory _runnerFactory;
private readonly ICredentials _credentials;

public DotNet(
IRunnerFactory runnerFactory,
ICredentials credentials)
ICredentials credentials,
IDefaults defaults)
{
_runnerFactory = runnerFactory;
_credentials = credentials;

DotNetEnvironmentVariable = new ConcurrentDictionary<string, string>
{
["DOTNET_CLI_TELEMETRY_OPTOUT"] = "true",
["DOTNET_NOLOGO"] = "true",
["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "true",
["NUGET_XMLDOC_MODE"] = "skip",
["NUGET_EXE_NO_PROMPT"] = "true",

["DOTNET_ROLL_FORWARD"] = defaults.DotNetRollForward,
};
}

public async Task<IToolResult> ClearNuGetLocalsAsync(
Expand Down Expand Up @@ -257,7 +262,10 @@ public async Task<IToolResult> PublishAsync(

if (argument.Platform.Os != ExecutableOperatingSystem.Any)
{
arguments.AddRange(new []{"--runtime", argument.Platform.GetDotNetRuntimeIdentifier()});
arguments.AddRange(new []
{
"--runtime", argument.Platform.GetDotNetRuntimeIdentifier()
});
}

AddIf(!argument.Build, arguments, "--no-build");
Expand Down
8 changes: 6 additions & 2 deletions Source/Bake/ValueObjects/DotNet/VisualStudioProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,24 @@ public class VisualStudioProject
public string Path { get; }
public CsProj CsProj { get; }
public string Directory { get; }
public string Name { get; set; }
public string Name { get; }
public string PreferredName { get; }
public string AssemblyName => string.IsNullOrEmpty(CsProj.AssemblyName) ? Name : CsProj.AssemblyName;

public bool ShouldBePacked => CsProj.IsPackable || CsProj.PackAsTool;
public bool ShouldBePushed => CsProj.IsPackable || CsProj.PackAsTool;

public VisualStudioProject(
string path,
string name,
string preferredName,
CsProj csProj)
{
Path = path;
CsProj = csProj;
Name = name;
PreferredName = preferredName;
Directory = System.IO.Path.GetDirectoryName(path);
Name = System.IO.Path.GetFileNameWithoutExtension(path);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: awesome-net-core-service

0 comments on commit 7f3499b

Please sign in to comment.