Skip to content

Commit db2753a

Browse files
committed
feat: OCI annotations
1 parent ffb64eb commit db2753a

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/main/groovy/cz/augi/gradle/dockerjava/DistDockerTask.groovy

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,30 @@ class DistDockerTask extends DefaultTask {
9292
}
9393

9494
private Map<String, String> getLabels() {
95+
def url = getUrl()
96+
def vcsUrl = getVcsUrl()
97+
def vcsRef = getVcsRef()
98+
99+
// https://label-schema.org/
95100
def labels = ['org.label-schema.schema-version':'1.0']
96101
labels.put('org.label-schema.build-date', Clock.systemUTC().instant().toString())
97102
labels.put('org.label-schema.version', project.version.toString())
98103
labels.put('org.label-schema.name', project.name)
99-
if (project.description) {
100-
labels.put('org.label-schema.description', project.description)
101-
}
102-
def url = getUrl()
104+
if (project.description) labels.put('org.label-schema.description', project.description)
103105
if (url) labels.put('org.label-schema.url', url)
104-
def vcsUrl = getVcsUrl()
105106
if (vcsUrl) labels.put('org.label-schema.vcs-url', vcsUrl)
106-
def vcsRef = getVcsRef()
107107
if (vcsRef) labels.put('org.label-schema.vcs-ref', vcsRef)
108108
labels.put('org.label-schema.docker.cmd', "docker run -d ${settings.ports.collect { "-p $it:$it" }.join(' ')} ${settings.volumes.collect { "-v $it:$it" }.join(' ')} ${settings.image}")
109+
110+
// https://github.com/opencontainers/image-spec/blob/main/annotations.md
111+
labels.put('org.opencontainers.image.created', Clock.systemUTC().instant().toString())
112+
labels.put('org.opencontainers.image.version', project.version.toString())
113+
labels.put('org.opencontainers.image.title', project.name)
114+
if (project.description) labels.put('org.opencontainers.image.description', project.description)
115+
if (url) labels.put('org.opencontainers.image.url', url)
116+
if (vcsUrl) labels.put('org.opencontainers.image.source', vcsUrl)
117+
if (vcsRef) labels.put('org.opencontainers.image.revision', vcsRef)
118+
109119
labels.putAll(settings.labels)
110120
labels
111121
}

src/test/groovy/cz/augi/gradle/dockerjava/DockerJavaPluginTest.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class DockerJavaPluginTest extends Specification {
6262
dockerRunOutput.contains('Hello from Docker, developer')
6363
labels.'org.label-schema.schema-version' == '1.0'
6464
labels.'org.label-schema.version' == '1.2.3'
65+
labels.'org.opencontainers.image.version' == '1.2.3'
6566
labels.'mylabel' == 'mylabelvalue'
6667
def workingDirectory = Paths.get(projectDir.absolutePath, 'build', 'dockerJava')
6768
Files.exists(workingDirectory.resolve('Dockerfile'))

0 commit comments

Comments
 (0)