Jenkins/vars/podman.groovy

41 lines
1.2 KiB
Groovy
Raw Normal View History

2023-04-18 16:09:00 +02:00
String buildCadolesPodPackage(String imageName, String imageTag, Map options = [:]) {
String destDir = options.get('destDir', env.WORKSPACE + '/dist')
Map nfpmOptions = options.get('nfpmOptions', [:])
nfpmOptions['target'] = destDir
Map env = options.get('env', [:])
env['IMAGE_NAME'] = imageName
env['IMAGE_TAG'] = imageTag
2023-04-18 16:09:00 +02:00
return withPodmanPackagingTempDir {
gomplate('post-install.sh.gotmpl', 'post-install.sh', env)
gomplate('pod.service.gotmpl', 'pod.service', env)
gomplate('pod.conf.gotmpl', 'pod.conf', env)
gomplate('nfpm.yaml.gotmpl', 'nfpm.yaml', env)
nfpm(nfpmOptions)
}
}
void withPodmanPackagingTempDir(Closure fn) {
File tempDir = File.createTempDir()
2023-04-18 16:09:00 +02:00
tempDir.deleteOnExit()
tempDir.mkdirs()
dir(tempDir.getAbsolutePath()) {
List<String> resources = [
'com/cadoles/podman/nfpm.yaml.gotmpl',
'com/cadoles/podman/pod.conf.gotmpl',
'com/cadoles/podman/pod.service.gotmpl',
'com/cadoles/podman/post-install.sh.gotmpl',
]
for (res in resources) {
String fileContent = libraryResource res
String fileName = res.substring(res.lastIndexOf('/') + 1)
writeFile file:fileName, text:fileContent
}
fn()
}
}