Skip to content

Commit

Permalink
extract GetDockerTags as extension
Browse files Browse the repository at this point in the history
  • Loading branch information
arturcic committed Jan 20, 2025
1 parent ebf0b76 commit d02ca64
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 42 deletions.
7 changes: 2 additions & 5 deletions build/build/Tasks/DockerBuildBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected virtual void DockerImage(BuildContext context, DockerDepsImage dockerI

protected void DockerManifest(BuildContext context, DockerDepsImage dockerImage)
{
var manifestTags = GetDockerTags(dockerImage, context.DockerRegistry);
var manifestTags = dockerImage.GetDockerTags(context.DockerRegistry);
foreach (var tag in manifestTags)
{
var amd64Tag = $"{tag}-{Architecture.Amd64.ToSuffix()}";
Expand Down Expand Up @@ -62,7 +62,7 @@ protected virtual DockerBuildXBuildSettings GetBuildSettings(DockerDepsImage doc
{
var arch = dockerImage.Architecture;
var suffix = arch.ToSuffix();
var dockerTags = GetDockerTags(dockerImage, registry, arch).ToArray();
var dockerTags = dockerImage.GetDockerTags(registry, arch).ToArray();
var buildSettings = new DockerBuildXBuildSettings
{
Rm = true,
Expand All @@ -82,7 +82,4 @@ protected virtual DockerBuildXBuildSettings GetBuildSettings(DockerDepsImage doc
}

protected abstract DirectoryPath GetWorkingDir(DockerDepsImage dockerImage);

protected abstract IEnumerable<string> GetDockerTags(DockerDepsImage dockerImage, string dockerRegistry,
Architecture? arch = null);
}
14 changes: 0 additions & 14 deletions build/build/Tasks/DockerBuildDeps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,4 @@ protected override DockerBuildXImageToolsCreateSettings GetManifestSettings(Dock
];
return settings;
}

protected override IEnumerable<string> GetDockerTags(DockerDepsImage dockerImage, string dockerRegistry,
Architecture? arch = null)
{
var tags = new[]
{
$"{dockerRegistry}/{Constants.DockerImageDeps}:{dockerImage.Distro}"
};

if (!arch.HasValue) return tags;

var suffix = arch.Value.ToSuffix();
return tags.Select(x => $"{x}-{suffix}");
}
}
23 changes: 0 additions & 23 deletions build/build/Tasks/DockerBuildImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,6 @@ protected override DockerBuildXImageToolsCreateSettings GetManifestSettings(Dock
return settings;
}

protected override IEnumerable<string> GetDockerTags(DockerDepsImage dockerImage, string dockerRegistry,
Architecture? arch = null)
{
var (distro, version, variant, _) = (dockerImage as DockerImage)!;

var tags = new List<string>
{
$"{dockerRegistry}/{Constants.DockerImageName}:{distro}-{variant}-{version}"
};

if (version == Constants.DockerDistroLatest)
{
tags.AddRange(
[
$"{dockerRegistry}/{Constants.DockerImageName}:{distro}-{variant}-latest"
]);
}

if (!arch.HasValue) return tags;

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

private static void GenerateDockerfile(ICakeContext context, DirectoryPath? workDir, DockerDepsImage dockerImage)
{
Expand Down
31 changes: 31 additions & 0 deletions build/build/Utils/DockerImageExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace Build;

public static class DockerImageExtensions
{
public static IEnumerable<string> GetDockerTags(this DockerDepsImage dockerImage, string dockerRegistry,
Architecture? arch = null)
{
var tags = new List<string>();

if (dockerImage is DockerImage image)
{
var (distro, version, variant, _) = image;

tags.Add($"{dockerRegistry}/{Constants.DockerImageName}:{distro}-{variant}-{version}");

if (version == Constants.DockerDistroLatest)
{
tags.Add($"{dockerRegistry}/{Constants.DockerImageName}:{distro}-{variant}-latest");
}
}
else
{
tags.Add($"{dockerRegistry}/{Constants.DockerImageDeps}:{dockerImage.Distro}");
}

if (!arch.HasValue) return tags;

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

0 comments on commit d02ca64

Please sign in to comment.