Ajout d'utilitaires pour le packaging Debian via Jenkins
Permet de reproduire le comportement de l'actuel serveur d'empaquetage Marang.
This commit is contained in:
commit
573715c9d7
|
@ -0,0 +1,26 @@
|
|||
FROM alpine:3.8
|
||||
|
||||
ARG HTTP_PROXY=
|
||||
ARG HTTPS_PROXY=
|
||||
ARG http_proxy=
|
||||
ARG https_proxy=
|
||||
|
||||
ARG TAMARIN_VERSION=develop
|
||||
|
||||
RUN apk add --no-cache git docker python3 bash
|
||||
|
||||
RUN git clone https://forge.cadoles.com/Cadoles/Tamarin /tamarin\
|
||||
&& cd /tamarin\
|
||||
&& git checkout ${TAMARIN_VERSION}
|
||||
|
||||
RUN mkdir -p /src
|
||||
RUN mkdir -p /dist && touch /dist/.dummy
|
||||
|
||||
VOLUME /tamarin
|
||||
VOLUME /src
|
||||
VOLUME /dist
|
||||
|
||||
ADD run-tamarin.sh /usr/local/bin/run-tamarin
|
||||
RUN chmod +x /usr/local/bin/run-tamarin
|
||||
|
||||
CMD /usr/local/bin/run-tamarin
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
cp -r . /src
|
||||
|
||||
CONTAINER_ID=${HOSTNAME}
|
||||
ENV_FILE=$(mktemp)
|
||||
DOCKER_ARGS="run --rm --env-file='${ENV_FILE}' --volumes-from ${CONTAINER_ID} [IMAGE_TAG] /usr/bin/python3 /tamarin/lib/build.py [PROFILE] [ARCH]"
|
||||
|
||||
# Forward proxy environment
|
||||
cat > "${ENV_FILE}" <<EOF
|
||||
HTTP_PROXY=${HTTP_PROXY}
|
||||
HTTPS_PROXY=${HTTPS_PROXY}
|
||||
http_proxy=${http_proxy}
|
||||
https_proxy=${https_proxy}
|
||||
EOF
|
||||
|
||||
[ "${TAMARIN_FORCE_REBUILD}" == "true" ] && PACKAGE_ARGS="${PACKAGE_ARGS} --rebuild"
|
||||
[ ! -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_PROFILE}" ] && PACKAGE_ARGS="${PACKAGE_ARGS} -p ${TAMARIN_PROFILE}"
|
||||
|
||||
/tamarin/package . ${PACKAGE_ARGS} --override-docker-args="${DOCKER_ARGS}"
|
||||
|
||||
DEST_DIR=${TAMARIN_DEST_DIR:-dist}
|
||||
mkdir -p ${DEST_DIR}
|
||||
cp -r /dist/* ./${DEST_DIR}
|
|
@ -0,0 +1,90 @@
|
|||
def buildPackageWithCPKG(
|
||||
String packageProfile = "debian",
|
||||
String packageArch = "",
|
||||
String baseImage = "",
|
||||
String destDir = "./packages",
|
||||
Boolean forceRebuild = false,
|
||||
Boolean publishPackages = true
|
||||
) {
|
||||
|
||||
// Fetch tags from remote
|
||||
sh 'git fetch --tags --force'
|
||||
|
||||
// Retrieve commit tags
|
||||
def commitTags = sh(script: 'git describe --exact-match --abbrev=0', returnStdout: true).split(' ')
|
||||
if (commitTags.length == 0) {
|
||||
error 'No build build tags on last commit'
|
||||
}
|
||||
|
||||
// For each tags
|
||||
for (tag in commitTags) {
|
||||
|
||||
// Split tag to retrieve context informations
|
||||
def tagParts = tag.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
|
||||
|
||||
stage("Build ${packageEnv} package (version ${packageVersion}) for ${packageDistrib}") {
|
||||
sh "rm -rf ${destDir}/*"
|
||||
buildPackage(packageProfile, packageArch, baseImage, destDir, forceRebuild)
|
||||
if (publishPackages) {
|
||||
vulcain.publish(destDir, packageEnv, env.BRANCH_NAME)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
def buildPackage(
|
||||
String packageProfile = "debian",
|
||||
String packageArch = "",
|
||||
String baseImage = "",
|
||||
String destDir = "./packages",
|
||||
Boolean forceRebuild = false
|
||||
) {
|
||||
|
||||
def tamarinImage
|
||||
|
||||
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'
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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 safeJobName = URLDecoder.decode(env.JOB_NAME).toLowerCase().replace('/', '-')
|
||||
def imageTag = "${safeJobName}-${env.BUILD_ID}"
|
||||
return docker.build("tamarin:${imageTag}", ".")
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
def publish(
|
||||
String packagesDir = './packages',
|
||||
String packagesEnv = 'dev',
|
||||
String packagesBranch = '',
|
||||
String sshCredentialsId = 'vulcain-packages-ssh-keypair',
|
||||
String vulcainHost = 'vulcain.cadoles.com'
|
||||
) {
|
||||
if (!packagesBranch) {
|
||||
packagesBranch = env.BRANCH_NAME
|
||||
}
|
||||
withCredentials([
|
||||
sshUserPrivateKey(credentialsId: sshCredentialsId, keyFileVariable: 'VULCAIN_SSH_KEY', usernameVariable: 'VULCAIN_SSH_USER')
|
||||
]) {
|
||||
sh """
|
||||
SSH_ARGS='-i ${VULCAIN_SSH_KEY} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
|
||||
ssh \$SSH_ARGS ${VULCAIN_SSH_USER}@${vulcainHost} mkdir -p '/home/${VULCAIN_SSH_USER}/packages/${packagesEnv}/${packagesBranch}'
|
||||
scp \$SSH_ARGS -r ${packagesDir}/*.deb '${VULCAIN_SSH_USER}@${vulcainHost}:/home/${VULCAIN_SSH_USER}/packages/${packagesEnv}/${packagesBranch}/'
|
||||
"""
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue