Skip to content

Commit

Permalink
(build) added new annotations to the docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
arturcic committed Feb 9, 2024
1 parent 9c32aa8 commit 9dc7853
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions build/common/Utilities/DockerContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static class DockerContextExtensions
"org.opencontainers.image.vendor=GitTools",
"org.opencontainers.image.licenses=MIT",
"org.opencontainers.image.source=https://github.com/GitTools/GitVersion.git",
"org.opencontainers.image.documentation=https://gitversion.net/docs/usage/docker",
$"org.opencontainers.image.created={DateTime.UtcNow:O}",
];

Expand Down Expand Up @@ -49,7 +50,12 @@ public static void DockerBuildImage(this BuildContextBase context, DockerImage d

var suffix = arch.ToSuffix();
var imageSuffix = $"({distro}-{context.Version.NugetVersion}-{targetFramework}-{arch.ToSuffix()})";
var baseNameSuffix = $"{registry}/{Constants.DockerBaseImageName}:{distro}-runtime-{targetFramework}-{arch.ToSuffix()}";
var description = $"org.opencontainers.image.description=GitVersion images {imageSuffix}";
var baseName = $"org.opencontainers.image.base.name={baseNameSuffix}";
var version = $"org.opencontainers.image.version={context.Version.NugetVersion}";
var revision = $"org.opencontainers.image.revision={context.Version.GitVersion.Sha}";
var source = $"org.opencontainers.image.source=https://github.com/GitTools/GitVersion/blob/{context.Version.GitVersion.Sha}/build/docker/Dockerfile";

var buildSettings = new DockerBuildXBuildSettings
{
Expand All @@ -72,11 +78,19 @@ public static void DockerBuildImage(this BuildContextBase context, DockerImage d
[
"maintainers=GitTools Maintainers",
.. Annotations,
baseName,
version,
source,
revision,
description
],
Annotation =
[
.. Annotations,
baseName,
version,
source,
revision,
description
]
};
Expand All @@ -100,7 +114,7 @@ public static void DockerManifest(this BuildContextBase context, DockerImage doc
var amd64Tag = $"{tag}-{Architecture.Amd64.ToSuffix()}";
var arm64Tag = $"{tag}-{Architecture.Arm64.ToSuffix()}";

var settings = GetManifestSettings(dockerImage, context.Version!.NugetVersion!, tag);
var settings = GetManifestSettings(dockerImage, context.Version!, tag);
context.DockerBuildXImageToolsCreate(settings, [amd64Tag, arm64Tag]);
}
}
Expand All @@ -127,17 +141,21 @@ public static void DockerPushImage(this BuildContextBase context, DockerImage do
}
}

public static DockerBuildXImageToolsCreateSettings GetManifestSettings(DockerImage dockerImage, string version, string tag)
public static DockerBuildXImageToolsCreateSettings GetManifestSettings(DockerImage dockerImage, BuildVersion buildVersion, string tag)
{
var imageSuffix = $"({dockerImage.Distro}-{version}-{dockerImage.TargetFramework})";
var imageSuffix = $"({dockerImage.Distro}-{buildVersion.NugetVersion}-{dockerImage.TargetFramework})";
var description = $"org.opencontainers.image.description=GitVersion images {imageSuffix}";
var version = $"org.opencontainers.image.version={buildVersion.NugetVersion}";
var revision = $"org.opencontainers.image.revision={buildVersion.GitVersion.Sha}";
var settings = new DockerBuildXImageToolsCreateSettings
{
Tag = [tag],
Annotation =
[
.. Annotations.Select(a => "index:" + a).ToArray(),
$"index:{description}",
$"index:{version}",
$"index:{revision}"
]
};
return settings;
Expand Down

0 comments on commit 9dc7853

Please sign in to comment.