GoogleContainerTools / GoogleContainerTools/jib

Feature request: Docker semantic tagging in Gradle plugin

Open
#3,548 1 comment 0 reactions 0 assignees View on GitHub
enhancement priority:p4
Dominant language
Java
Stars
14.5k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

This is a feature request.

I am currently actively working to fully implement [Docker semantic tagging](https://medium.com/@mccode/using-semantic-versioning-for-docker-image-tags-dfde8be06699) as documented.

To illustrate it short, given your project has version `1.0.1`, I want to create Docker tags for the following tags:

- 1
- 1.0
- 1.0.1

On the next patch release, 1.0.2, the two early tags should be overwritten, while the third retained.

Currently, I wrote some Groovy code that parses the `version` object (computed by [reckon](https://github.com/ajoberstar/reckon))

```groovy
/**
* Parses semantic version into multiple bindable versions
*
* Examples
*
*

1.0.15

*
 *     1

* 1.0
* 1.0.15
*

*
*
*
1.4.13-SNAPSHOT

*
 *     1-SNAPSHOT

* 1.4-SNAPSHOT
* 1.4.13-SNAPSHOT
*

*
* @param version
*/
static def parseSemantic(String version) {
int indexOfDash = version.indexOf('-')
def versionType = indexOfDash < 0 ? '' : version.substring(indexOfDash)
def ret = []
for (def indexOfDot = 0; indexOfDot > -1; indexOfDot = version.indexOf('.', indexOfDot + 1)) {
if (indexOfDot == 0) continue
ret.push("${version.substring(0, indexOfDot)}$versionType")
}
ret.push(version)
ret.push("latest${versionType}")
ret
}

task jibDisplaySemanticVersions {
description 'Prints semantic versions for Docker tags'
group 'jib'
doLast {
parseSemantic(version.toString()).forEach {
println "Version >> $it"
}
}
}

```

Example usage in a Spring Boot project

```
jib {
to {
image = 'xxxxx'
tags = parseSemantic(version.toString())
}
container {
ports = ['8080']
environment = [
SPRING_OUTPUT_ANSI_ENABLED: 'ALWAYS',
]
creationTime = 'USE_CURRENT_TIMESTAMP'
}
}
```

I believe that Semantic tagging is a very good idea to maintain images. I recommend the jib team to implement such a feature in the Maven and Gradle plugins

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.