feature: names refactoring, Jenkinsfile edit, example edit, bug fixes

This commit is contained in:
2025-03-05 01:36:24 +03:00
parent 7f3a76c984
commit 1b34bd5df1
11 changed files with 128 additions and 67 deletions

View File

@@ -12,7 +12,7 @@ class DockerBuildCommandFactory {
]
return propertyNames.stream()
.map { CIProperties.findProperty("ci.docker.build.additional-args").orNull() }
.map { CIProperties.findProperty(it).orNull() }
.filter { it != null }
.findFirst()
.orElse("")

View File

@@ -5,11 +5,6 @@ import groovy.transform.CompileStatic
@CompileStatic
class DockerImageNames {
static String getImageTag(String baseName, String dockerfile) {
def imageTagPostfix = CIProperties.findProperty("docker.image.tag.${dockerfile.toLowerCase()}.postfix").orElse("")
return "${baseName}${imageTagPostfix}"
}
static String getImageName(String dockerfileName) {
def propertyNames = [
"docker.image.${dockerfileName.toLowerCase()}.name",

View File

@@ -18,9 +18,20 @@ class DockerLogin {
// Логинимся в Registry
ScriptLog.printf "Performing login to registry..."
def registryName = System.getGlobalProperty("ci.docker.registry")
def registryUser = System.getGlobalProperty("ci.docker.registry.username")
def registryPassword = System.getGlobalProperty("ci.docker.registry.password")
def registryName = CIProperties.getProperty("docker.registry")
def registryUser = CIProperties.getProperty("docker.registry.username")
def registryPassword = CIProperties.getProperty("docker.registry.password")
if (registryName.isNullOrBlank()) {
throw new IllegalStateException("Docker registry name not set")
}
if (registryUser.isNullOrBlank()) {
throw new IllegalStateException("Docker registry user not set")
}
if (registryPassword.isNullOrBlank()) {
throw new IllegalStateException("Docker registry password not set")
}
sh "docker login $registryName -u $registryUser -p $registryPassword"

View File

@@ -38,7 +38,16 @@ class GitTags {
return getTagsWithPrefix(deployPrefixes)
}
static String sanitizeTagFromPrefixes(String tag, Collection<String> prefixes) {
static List<String> getAllPrefixes() {
def result = new ArrayList<String>()
result.addAll(getReleasePrefixes())
result.addAll(getDeployPrefixes())
return result
}
static String sanitizeTagFromPrefixes(String tag, Collection<String> prefixes = getAllPrefixes()) {
return tag.removeAll(prefixes)
}
}

View File

@@ -1,8 +1,19 @@
package util
import groovy.transform.CompileStatic
@CompileStatic
class ScriptLog {
static void printf(Object text, Object... args) {
def callerClassName = new Throwable().getStackTrace()[1].getClassName().split("\\.").last()
println "[${callerClassName}]: ${String.format(String.valueOf(text), args)}"
def scriptPrefix = new Throwable().getStackTrace()
.stream()
.map { it.className }
.filter { it != null }
.map { it.split("\\.").last() }
.filter { it.isNotNullOrBlank() && it.charAt(0).isLowerCase() }
.toList()
.lastOrNull() ?: "ci script"
println "[${scriptPrefix}]: ${String.format(String.valueOf(text), args)}"
}
}