tamarin: add prepareEnvironment() method

This commit is contained in:
wpetit 2020-03-27 11:50:44 +01:00
parent 3890170351
commit 073995cb1b
3 changed files with 179 additions and 138 deletions

View File

@ -10,10 +10,36 @@ pipeline {
projectDir = "${env.project_name}_${env.BUILD_ID}" projectDir = "${env.project_name}_${env.BUILD_ID}"
} }
triggers {
// Execute pipeline every day at 7h30 to prepare docker images
cron(env.BRANCH_NAME == 'develop' ? '30 7 * * 1-5' : '')
}
stages { stages {
stage("Clone repository") { stage("Prepare build environment") {
when {
anyOf {
triggeredBy cause: "UserIdCause", detail: "wpetit"
triggeredBy 'TimerTrigger'
}
}
steps { steps {
script {
tamarin.prepareEnvironment()
}
}
}
stage("Package project") {
when {
not {
triggeredBy 'TimerTrigger'
}
}
steps {
script {
stage("Clone repository") {
checkout scm: checkout scm:
[ [
$class: 'GitSCM', $class: 'GitSCM',
@ -28,11 +54,8 @@ pipeline {
changelog: false, changelog: false,
poll: false poll: false
} }
}
stage("Ensure packaging branch") { stage("Ensure packaging branch") {
steps {
script {
dir(env.projectDir) { dir(env.projectDir) {
sh 'git checkout "${packageBranch}"' sh 'git checkout "${packageBranch}"'
def commitOrRef = env.commit ? env.commit : env.ref def commitOrRef = env.commit ? env.commit : env.ref
@ -43,12 +66,8 @@ pipeline {
} }
} }
} }
}
}
stage("Check [ci skip] in tag message") { stage("Check [ci skip] in tag message") {
steps {
script {
dir(env.projectDir) { dir(env.projectDir) {
sh 'git checkout "${packageBranch}"' sh 'git checkout "${packageBranch}"'
def commitTags = sh(script: 'git describe --exact-match --abbrev=0', returnStdout: true).split(' ') def commitTags = sh(script: 'git describe --exact-match --abbrev=0', returnStdout: true).split(' ')
@ -63,24 +82,17 @@ pipeline {
} }
} }
} }
}
}
stage("Checkout ref") { stage("Checkout ref") {
steps {
dir(env.projectDir) { dir(env.projectDir) {
sh """ sh """
git checkout ${env.ref} git checkout ${env.ref}
""" """
} }
} }
}
stage("Build package") { stage("Build package") {
steps {
script {
dir(env.projectDir) { dir(env.projectDir) {
// On construit les paquets à partir des informations // On construit les paquets à partir des informations
// de contexte provenant de CPKG et du webhook // de contexte provenant de CPKG et du webhook
def result = tamarin.buildPackageWithCPKG( def result = tamarin.buildPackageWithCPKG(
@ -161,14 +173,15 @@ pipeline {
} }
} }
} }
}
post { post {
always { always {
sh "rm -rf '${env.projectDir}'" sh "rm -rf '${env.projectDir}'"
} }
} }
}
}
} }

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -xe
cp -r . /src cp -r . /src
@ -17,6 +17,7 @@ https_proxy=${https_proxy}
EOF EOF
[ "${TAMARIN_FORCE_REBUILD}" == "true" ] && PACKAGE_ARGS="${PACKAGE_ARGS} --rebuild" [ "${TAMARIN_FORCE_REBUILD}" == "true" ] && PACKAGE_ARGS="${PACKAGE_ARGS} --rebuild"
[ "${TAMARIN_PREPARE_ONLY}" == "true" ] && PACKAGE_ARGS="${PACKAGE_ARGS} --prepare-only"
[ ! -z "${TAMARIN_PACKAGE_ARCH}" ] && PACKAGE_ARGS="${PACKAGE_ARGS} -a ${TAMARIN_PACKAGE_ARCH}" [ ! -z "${TAMARIN_PACKAGE_ARCH}" ] && PACKAGE_ARGS="${PACKAGE_ARGS} -a ${TAMARIN_PACKAGE_ARCH}"
[ ! -z "${TAMARIN_BASE_IMAGE}" ] && PACKAGE_ARGS="${PACKAGE_ARGS} -b ${TAMARIN_BASE_IMAGE}" [ ! -z "${TAMARIN_BASE_IMAGE}" ] && PACKAGE_ARGS="${PACKAGE_ARGS} -b ${TAMARIN_BASE_IMAGE}"
[ ! -z "${TAMARIN_PROFILE}" ] && PACKAGE_ARGS="${PACKAGE_ARGS} -p ${TAMARIN_PROFILE}" [ ! -z "${TAMARIN_PROFILE}" ] && PACKAGE_ARGS="${PACKAGE_ARGS} -p ${TAMARIN_PROFILE}"
@ -25,4 +26,6 @@ EOF
DEST_DIR=${TAMARIN_DEST_DIR:-dist} DEST_DIR=${TAMARIN_DEST_DIR:-dist}
mkdir -p ${DEST_DIR} mkdir -p ${DEST_DIR}
cp -r /dist/* ./${DEST_DIR} for f in /dist/*; do
[ -e "$f" ] && cp "$f" ./${DEST_DIR}
done

View File

@ -89,6 +89,31 @@ def buildPackage(
} }
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() { def buildDockerImage() {
dir ('.tamarin') { dir ('.tamarin') {
def dockerfile = libraryResource 'com/cadoles/tamarin/Dockerfile' def dockerfile = libraryResource 'com/cadoles/tamarin/Dockerfile'