Skip to content

Commit

Permalink
(build) cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
arturcic committed Dec 28, 2023
1 parent f63757d commit 4722a7e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 41 deletions.
2 changes: 1 addition & 1 deletion build/.run/Artifacts MsBuildCore Test.run.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Artifacts MsBuildCore Test" type="DotNetProject" factoryName=".NET Project" folderName="Artifacts">
<option name="EXE_PATH" value="$PROJECT_DIR$/../run/artifacts.exe" />
<option name="PROGRAM_PARAMETERS" value="--target=ArtifactsMsBuildCoreTest --arch=amd64 --docker_dotnetversion=6.0 --docker_distro=alpine.3.12-x64" />
<option name="PROGRAM_PARAMETERS" value="--target=ArtifactsMsBuildCoreTest --arch=amd64 --docker_dotnetversion=6.0 --docker_distro=alpine.3.17" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/.." />
<option name="PASS_PARENT_ENVS" value="1" />
<envs>
Expand Down
2 changes: 1 addition & 1 deletion build/.run/Artifacts Native Test.run.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Artifacts Native Test" type="DotNetProject" factoryName=".NET Project" folderName="Artifacts">
<option name="EXE_PATH" value="$PROJECT_DIR$/../run/artifacts.exe" />
<option name="PROGRAM_PARAMETERS" value="--target=ArtifactsNativeTest --arch=amd64 --docker_dotnetversion=6.0 --docker_distro=alpine.3.12-x64" />
<option name="PROGRAM_PARAMETERS" value="--target=ArtifactsNativeTest --arch=amd64 --docker_dotnetversion=6.0 --docker_distro=alpine.3.17" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/.." />
<option name="PASS_PARENT_ENVS" value="1" />
<envs>
Expand Down
2 changes: 1 addition & 1 deletion build/.run/Artifacts Prepare.run.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Artifacts Prepare" type="DotNetProject" factoryName=".NET Project" folderName="Artifacts">
<option name="EXE_PATH" value="$PROJECT_DIR$/../run/artifacts.exe" />
<option name="PROGRAM_PARAMETERS" value="--target=ArtifactsPrepare --docker_dotnetversion=6.0 --docker_distro=alpine.3.12-x64" />
<option name="PROGRAM_PARAMETERS" value="--target=ArtifactsPrepare --docker_dotnetversion=6.0 --docker_distro=alpine.3.17" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/.." />
<option name="PASS_PARENT_ENVS" value="1" />
<envs>
Expand Down
2 changes: 1 addition & 1 deletion build/.run/Artifacts Test.run.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Artifacts Test" type="DotNetProject" factoryName=".NET Project" folderName="Artifacts">
<option name="EXE_PATH" value="$PROJECT_DIR$/../run/artifacts.exe" />
<option name="PROGRAM_PARAMETERS" value="--target=ArtifactsTest --docker_dotnetversion=6.0 --docker_distro=alpine.3.12-x64" />
<option name="PROGRAM_PARAMETERS" value="--target=ArtifactsTest --docker_dotnetversion=6.0 --docker_distro=alpine.3.17" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/.." />
<option name="PASS_PARENT_ENVS" value="1" />
<envs>
Expand Down
4 changes: 2 additions & 2 deletions build/common/Addins/Cake.Wyam/WyamRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ private static void SetMetadata(ProcessArgumentBuilder builder, string argument,
{
if (valueBuilder.Length != 0)
{
valueBuilder.Append(",");
valueBuilder.Append(',');
}
valueBuilder.Append($"{EscapeMetadata(value.ToString()).Replace(",", "\\,")}");
}
Expand All @@ -318,5 +318,5 @@ private static void SetMetadata(ProcessArgumentBuilder builder, string argument,
}

private static string EscapeMetadata(string s) =>
s.Replace("\\", "\\\\").Replace("\"", "\\\"").Replace("=", "\\=");
s.Replace("\\", @"\\").Replace("\"", "\\\"").Replace("=", "\\=");
}
61 changes: 26 additions & 35 deletions build/common/Utilities/DockerContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public enum Architecture
Arm64,
Amd64
}

public static class DockerContextExtensions
{
public static bool SkipImageForArtifacts(this ICakeContext context, DockerImage dockerImage)
Expand Down Expand Up @@ -43,9 +44,8 @@ public static void DockerBuildImage(this BuildContextBase context, DockerImage d
var tags = context.GetDockerTags(dockerImage, arch);

var suffix = arch.ToSuffix();
var platforms = new List<string> { $"linux/{suffix}" };

var buildSettings = new DockerImageBuildSettings
var buildSettings = new DockerBuildXBuildSettings
{
Rm = true,
Tag = tags.ToArray(),
Expand All @@ -59,10 +59,10 @@ public static void DockerBuildImage(this BuildContextBase context, DockerImage d
$"VERSION={context.Version.NugetVersion}"
],
Pull = true,
Platform = string.Join(",", platforms),
Platform = [$"linux/{suffix}"]
};

context.DockerBuild(buildSettings, workDir.ToString(), "--output type=docker");
context.DockerBuildXBuild(buildSettings, workDir.ToString(), "--output type=docker");
}

public static void DockerPushImage(this BuildContextBase context, DockerImage dockerImage)
Expand All @@ -74,7 +74,8 @@ public static void DockerPushImage(this BuildContextBase context, DockerImage do
}
}

public static void DockerCreateManifest(this BuildContextBase context, DockerImage dockerImage, bool skipArm64Image = false)
public static void DockerCreateManifest(this BuildContextBase context, DockerImage dockerImage,
bool skipArm64Image = false)
{
var manifestTags = context.GetDockerTags(dockerImage);
foreach (var tag in manifestTags)
Expand Down Expand Up @@ -124,29 +125,18 @@ public static void DockerTestArtifact(this BuildContextBase context, DockerImage
context.DockerTestRun(tag, dockerImage.Architecture, "sh", cmd);
}

private static void DockerBuild(this ICakeContext context, DockerImageBuildSettings settings, string path, params string[] args)
private static void DockerBuildXBuild(this ICakeContext context, DockerBuildXBuildSettings settings, string path,
params string[] args)
{
GenericDockerRunner<DockerImageBuildSettings> genericDockerRunner =
new(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
var runner = new GenericDockerRunner<DockerBuildXBuildSettings>(context.FileSystem, context.Environment,
context.ProcessRunner, context.Tools);

string str;
switch (string.IsNullOrEmpty(path))
{
case false:
{
string str2 = path.Trim();
str = str2.Length <= 1 || !str2.StartsWith("\"") || !str2.EndsWith("\"") ? "\"" + path + "\"" : path;
break;
}
default:
str = path;
break;
}
var additional = args.Concat(new[] { str }).ToArray();
genericDockerRunner.Run("buildx build", settings, additional);
path = $"\"{path.Trim().Trim('\"')}\"";
runner.Run("buildx build", settings, [.. args, path]);
}

private static void DockerTestRun(this BuildContextBase context, string image, Architecture arch, string command, params string[] args)
private static void DockerTestRun(this BuildContextBase context, string image, Architecture arch, string command,
params string[] args)
{
var settings = GetDockerRunSettings(context, arch);
context.Information($"Testing image: {image}");
Expand All @@ -156,7 +146,9 @@ private static void DockerTestRun(this BuildContextBase context, string image, A
Assert.NotNull(context.Version?.GitVersion);
Assert.Contains(context.Version.GitVersion.FullSemVer!, output);
}
private static IEnumerable<string> GetDockerTags(this BuildContextBase context, DockerImage dockerImage, Architecture? arch = null)

private static IEnumerable<string> GetDockerTags(this BuildContextBase context, DockerImage dockerImage,
Architecture? arch = null)
{
var name = dockerImage.DockerImageName();
var distro = dockerImage.Distro;
Expand All @@ -171,31 +163,29 @@ private static IEnumerable<string> GetDockerTags(this BuildContextBase context,

if (distro == Constants.DockerDistroLatest && targetFramework == Constants.VersionLatest)
{
tags.AddRange(new[]
{
$"{name}:{context.Version.Version}",
$"{name}:{context.Version.SemVersion}",
});
tags.AddRange(new[] { $"{name}:{context.Version.Version}", $"{name}:{context.Version.SemVersion}", });

if (context.IsStableRelease)
{
tags.AddRange(new[]
{
tags.AddRange(
[
$"{name}:latest",
$"{name}:latest-{targetFramework}",
$"{name}:latest-{distro}",
$"{name}:latest-{distro}-{targetFramework}",
});
]);
}
}

if (!arch.HasValue) return tags.Distinct();

var suffix = arch.Value.ToSuffix();
return tags.Select(x => $"{x}-{suffix}").Distinct();

}
private static string DockerImageName(this DockerImage image) => $"{image.Registry}/{(image.UseBaseImage ? Constants.DockerBaseImageName : Constants.DockerImageName)}";

private static string DockerImageName(this DockerImage image) =>
$"{image.Registry}/{(image.UseBaseImage ? Constants.DockerBaseImageName : Constants.DockerImageName)}";

private static DockerContainerRunSettings GetDockerRunSettings(this BuildContextBase context, Architecture arch)
{
var currentDir = context.MakeAbsolute(context.Directory("."));
Expand All @@ -221,6 +211,7 @@ private static DockerContainerRunSettings GetDockerRunSettings(this BuildContext
$"BUILD_SOURCEBRANCH={context.EnvironmentVariable("BUILD_SOURCEBRANCH")}"
];
}

if (context.IsGitHubActionsBuild)
{
settings.Env =
Expand Down

0 comments on commit 4722a7e

Please sign in to comment.