Benjamin Bohard
1efbd7f5ee
Some checks failed
Cadoles/Jenkins/pipeline/head There was a failure building this commit
125 lines
3.7 KiB
Groovy
125 lines
3.7 KiB
Groovy
def buildPackageWithCPKG(
|
|
String packageProfile = "debian",
|
|
String packageArch = "",
|
|
String packageBranch = "",
|
|
String baseImage = "",
|
|
String destDir = "./packages",
|
|
Boolean forceRebuild = false
|
|
) {
|
|
|
|
def result = [:]
|
|
|
|
// Retrieve commit tags
|
|
def commitTag = sh(script: 'git describe --exact-match --abbrev=0', returnStdout: true)
|
|
if (commitTag == '') {
|
|
error 'No build build tags on last commit'
|
|
}
|
|
|
|
// Split tag to retrieve context informations
|
|
def tagParts = commitTag.split('/')
|
|
def packageEnv = tagParts[1]
|
|
def packageDistrib = tagParts[2]
|
|
def packageVersion = tagParts[3]
|
|
|
|
// Create .tamarinrc file
|
|
def tamarinrc = """
|
|
project_version=${packageVersion}
|
|
no_version_suffix=${ packageEnv == 'stable' || packageEnv == 'staging' ? 'yes' : 'no' }
|
|
""".stripIndent()
|
|
writeFile file: '.tamarinrc', text: tamarinrc
|
|
|
|
sh "rm -rf ${destDir}/*"
|
|
|
|
stage("Build ${packageEnv} package (version ${packageVersion}) for ${packageDistrib}") {
|
|
result.put('tag', commitTag)
|
|
result.put('env', packageEnv)
|
|
result.put('version', packageVersion)
|
|
result.put('distrib', packageDistrib)
|
|
def packages = buildPackage(packageProfile, packageArch, baseImage, destDir, forceRebuild)
|
|
result.put('packages', packages)
|
|
}
|
|
return result
|
|
|
|
}
|
|
|
|
def buildPackage(
|
|
String packageProfile = "debian",
|
|
String packageArch = "",
|
|
String baseImage = "",
|
|
String destDir = "./packages",
|
|
Boolean forceRebuild = false
|
|
) {
|
|
|
|
def tamarinImage
|
|
def packages = []
|
|
|
|
stage("Create Tamarin environment") {
|
|
tamarinImage = buildDockerImage()
|
|
}
|
|
|
|
stage("Run Tamarin") {
|
|
def dockerArgs = """
|
|
-v /var/run/docker.sock:/var/run/docker.sock
|
|
${forceRebuild ? '-e TAMARIN_FORCE_REBUILD=1' : ''}
|
|
${packageArch ? '-e TAMARIN_PACKAGE_ARCH='+packageArch : ''}
|
|
${baseImage ? '-e TAMARIN_BASE_IMAGE='+baseImage : ''}
|
|
${packageProfile ? '-e TAMARIN_PROFILE='+packageProfile : ''}
|
|
-e TAMARIN_DEST_DIR=${destDir}
|
|
""".stripIndent()
|
|
|
|
tamarinImage.inside(dockerArgs) {
|
|
sh 'run-tamarin'
|
|
}
|
|
|
|
packages = sh(script: "find '${destDir}' -name '*.deb' -type f", returnStdout: true)
|
|
.split('\n')
|
|
.collect { return it.trim() }
|
|
.findAll { it != '' }
|
|
}
|
|
|
|
return packages
|
|
|
|
}
|
|
|
|
def prepareEnvironment(
|
|
String packageProfile = "debian",
|
|
String baseImage = ""
|
|
) {
|
|
def tamarinImage
|
|
|
|
stage("Create Tamarin environment") {
|
|
tamarinImage = buildDockerImage()
|
|
}
|
|
|
|
stage("Prepare Tamarin") {
|
|
def dockerArgs = """
|
|
-v /var/run/docker.sock:/var/run/docker.sock
|
|
${baseImage ? '-e TAMARIN_BASE_IMAGE='+baseImage : ''}
|
|
${packageProfile ? '-e TAMARIN_PROFILE='+packageProfile : ''}
|
|
-e TAMARIN_PREPARE_ONLY=true
|
|
-e TAMARIN_FORCE_REBUILD=true
|
|
""".stripIndent()
|
|
|
|
tamarinImage.inside(dockerArgs) {
|
|
sh 'run-tamarin'
|
|
}
|
|
}
|
|
}
|
|
|
|
def buildDockerImage() {
|
|
dir ('.tamarin') {
|
|
def dockerfile = libraryResource 'com/cadoles/tamarin/Dockerfile'
|
|
writeFile file:'Dockerfile', text:dockerfile
|
|
|
|
def runTamarinScript = libraryResource 'com/cadoles/tamarin/run-tamarin.sh'
|
|
writeFile file:'run-tamarin.sh', text:runTamarinScript
|
|
|
|
def addLetsEncryptCA = libraryResource 'com/cadoles/common/add-letsencrypt-ca.sh'
|
|
writeFile file:'add-letsencrypt-ca.sh', text:addLetsEncryptCA
|
|
|
|
def safeJobName = URLDecoder.decode(env.JOB_NAME).toLowerCase().replace('/', '-').replace(' ', '-')
|
|
def imageTag = "${safeJobName}-${env.BUILD_ID}"
|
|
return docker.build("tamarin:${imageTag}", ".")
|
|
}
|
|
}
|