Skip to content

Commit 9dc7853

Browse files
committed
(build) added new annotations to the docker images
1 parent 9c32aa8 commit 9dc7853

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

build/common/Utilities/DockerContextExtensions.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public static class DockerContextExtensions
1818
"org.opencontainers.image.vendor=GitTools",
1919
"org.opencontainers.image.licenses=MIT",
2020
"org.opencontainers.image.source=https://github.com/GitTools/GitVersion.git",
21+
"org.opencontainers.image.documentation=https://gitversion.net/docs/usage/docker",
2122
$"org.opencontainers.image.created={DateTime.UtcNow:O}",
2223
];
2324

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

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

5460
var buildSettings = new DockerBuildXBuildSettings
5561
{
@@ -72,11 +78,19 @@ public static void DockerBuildImage(this BuildContextBase context, DockerImage d
7278
[
7379
"maintainers=GitTools Maintainers",
7480
.. Annotations,
81+
baseName,
82+
version,
83+
source,
84+
revision,
7585
description
7686
],
7787
Annotation =
7888
[
7989
.. Annotations,
90+
baseName,
91+
version,
92+
source,
93+
revision,
8094
description
8195
]
8296
};
@@ -100,7 +114,7 @@ public static void DockerManifest(this BuildContextBase context, DockerImage doc
100114
var amd64Tag = $"{tag}-{Architecture.Amd64.ToSuffix()}";
101115
var arm64Tag = $"{tag}-{Architecture.Arm64.ToSuffix()}";
102116

103-
var settings = GetManifestSettings(dockerImage, context.Version!.NugetVersion!, tag);
117+
var settings = GetManifestSettings(dockerImage, context.Version!, tag);
104118
context.DockerBuildXImageToolsCreate(settings, [amd64Tag, arm64Tag]);
105119
}
106120
}
@@ -127,17 +141,21 @@ public static void DockerPushImage(this BuildContextBase context, DockerImage do
127141
}
128142
}
129143

130-
public static DockerBuildXImageToolsCreateSettings GetManifestSettings(DockerImage dockerImage, string version, string tag)
144+
public static DockerBuildXImageToolsCreateSettings GetManifestSettings(DockerImage dockerImage, BuildVersion buildVersion, string tag)
131145
{
132-
var imageSuffix = $"({dockerImage.Distro}-{version}-{dockerImage.TargetFramework})";
146+
var imageSuffix = $"({dockerImage.Distro}-{buildVersion.NugetVersion}-{dockerImage.TargetFramework})";
133147
var description = $"org.opencontainers.image.description=GitVersion images {imageSuffix}";
148+
var version = $"org.opencontainers.image.version={buildVersion.NugetVersion}";
149+
var revision = $"org.opencontainers.image.revision={buildVersion.GitVersion.Sha}";
134150
var settings = new DockerBuildXImageToolsCreateSettings
135151
{
136152
Tag = [tag],
137153
Annotation =
138154
[
139155
.. Annotations.Select(a => "index:" + a).ToArray(),
140156
$"index:{description}",
157+
$"index:{version}",
158+
$"index:{revision}"
141159
]
142160
};
143161
return settings;

0 commit comments

Comments
 (0)