Browse Source

Ajout d'utilitaires pour le packaging Debian via Jenkins

Permet de reproduire le comportement de l'actuel serveur d'empaquetage
Marang.
redesign-tamarin
William Petit 7 months ago
commit
573715c9d7

+ 26
- 0
resources/com/cadoles/tamarin/Dockerfile View File

@@ -0,0 +1,26 @@
1
+FROM alpine:3.8
2
+
3
+ARG HTTP_PROXY=
4
+ARG HTTPS_PROXY=
5
+ARG http_proxy=
6
+ARG https_proxy=
7
+
8
+ARG TAMARIN_VERSION=develop
9
+
10
+RUN apk add --no-cache git docker python3 bash
11
+
12
+RUN git clone https://forge.cadoles.com/Cadoles/Tamarin /tamarin\
13
+  && cd /tamarin\
14
+  && git checkout ${TAMARIN_VERSION}
15
+
16
+RUN mkdir -p /src
17
+RUN mkdir -p /dist && touch /dist/.dummy
18
+
19
+VOLUME /tamarin
20
+VOLUME /src
21
+VOLUME /dist
22
+
23
+ADD run-tamarin.sh /usr/local/bin/run-tamarin
24
+RUN chmod +x /usr/local/bin/run-tamarin
25
+
26
+CMD /usr/local/bin/run-tamarin

+ 28
- 0
resources/com/cadoles/tamarin/run-tamarin.sh View File

@@ -0,0 +1,28 @@
1
+#!/usr/bin/env bash
2
+
3
+set -e
4
+
5
+cp -r . /src
6
+
7
+CONTAINER_ID=${HOSTNAME}
8
+ENV_FILE=$(mktemp)
9
+DOCKER_ARGS="run --rm --env-file='${ENV_FILE}' --volumes-from ${CONTAINER_ID} [IMAGE_TAG] /usr/bin/python3 /tamarin/lib/build.py [PROFILE] [ARCH]"
10
+
11
+# Forward proxy environment
12
+cat > "${ENV_FILE}" <<EOF
13
+HTTP_PROXY=${HTTP_PROXY}
14
+HTTPS_PROXY=${HTTPS_PROXY}
15
+http_proxy=${http_proxy}
16
+https_proxy=${https_proxy}
17
+EOF
18
+
19
+[ "${TAMARIN_FORCE_REBUILD}" == "true" ] && PACKAGE_ARGS="${PACKAGE_ARGS} --rebuild"
20
+[ ! -z "${TAMARIN_PACKAGE_ARCH}" ] && PACKAGE_ARGS="${PACKAGE_ARGS} -a ${TAMARIN_PACKAGE_ARCH}"
21
+[ ! -z "${TAMARIN_BASE_IMAGE}" ] && PACKAGE_ARGS="${PACKAGE_ARGS} -b ${TAMARIN_BASE_IMAGE}"
22
+[ ! -z "${TAMARIN_PROFILE}" ] && PACKAGE_ARGS="${PACKAGE_ARGS} -p ${TAMARIN_PROFILE}"
23
+
24
+/tamarin/package . ${PACKAGE_ARGS} --override-docker-args="${DOCKER_ARGS}"
25
+
26
+DEST_DIR=${TAMARIN_DEST_DIR:-dist}
27
+mkdir -p ${DEST_DIR}
28
+cp -r /dist/* ./${DEST_DIR}

+ 90
- 0
vars/tamarin.groovy View File

@@ -0,0 +1,90 @@
1
+def buildPackageWithCPKG(
2
+    String packageProfile = "debian",
3
+    String packageArch = "",
4
+    String baseImage = "", 
5
+    String destDir = "./packages",
6
+    Boolean forceRebuild = false,
7
+    Boolean publishPackages = true
8
+) {
9
+
10
+    // Fetch tags from remote
11
+    sh 'git fetch --tags --force'
12
+
13
+    // Retrieve commit tags
14
+    def commitTags = sh(script: 'git describe --exact-match --abbrev=0', returnStdout: true).split(' ')
15
+    if (commitTags.length == 0) {
16
+        error 'No build build tags on last commit'
17
+    }
18
+
19
+    // For each tags
20
+    for (tag in commitTags) {
21
+
22
+        // Split tag to retrieve context informations
23
+        def tagParts = tag.split('/')
24
+        def packageEnv = tagParts[1]
25
+        def packageDistrib = tagParts[2]
26
+        def packageVersion = tagParts[3]
27
+
28
+        // Create .tamarinrc file
29
+        def tamarinrc = """
30
+        project_version=${packageVersion}
31
+        no_version_suffix=${ packageEnv == 'stable' || packageEnv == 'staging' ? 'yes' : 'no' }
32
+        """.stripIndent()
33
+        writeFile file: '.tamarinrc', text: tamarinrc
34
+        
35
+        stage("Build ${packageEnv} package (version ${packageVersion}) for ${packageDistrib}") {
36
+            sh "rm -rf ${destDir}/*"
37
+            buildPackage(packageProfile, packageArch, baseImage, destDir, forceRebuild)
38
+            if (publishPackages) {
39
+                vulcain.publish(destDir, packageEnv, env.BRANCH_NAME)
40
+            }
41
+        }
42
+        
43
+    }
44
+
45
+}
46
+
47
+def buildPackage(
48
+    String packageProfile = "debian", 
49
+    String packageArch = "",
50
+    String baseImage = "", 
51
+    String destDir = "./packages",
52
+    Boolean forceRebuild = false
53
+) {
54
+
55
+    def tamarinImage 
56
+    
57
+    stage("Create Tamarin environment") {
58
+        tamarinImage = buildDockerImage()
59
+    }   
60
+    
61
+    stage("Run Tamarin") {
62
+        def dockerArgs = """
63
+        -v /var/run/docker.sock:/var/run/docker.sock
64
+        ${forceRebuild ? '-e TAMARIN_FORCE_REBUILD=1' : ''}
65
+        ${packageArch ? '-e TAMARIN_PACKAGE_ARCH='+packageArch : ''}
66
+        ${baseImage ? '-e TAMARIN_BASE_IMAGE='+baseImage : ''}
67
+        ${packageProfile ? '-e TAMARIN_PROFILE='+packageProfile : ''}
68
+        -e TAMARIN_DEST_DIR=${destDir}
69
+        """.stripIndent()
70
+
71
+        tamarinImage.inside(dockerArgs) {
72
+            sh 'run-tamarin'
73
+        }
74
+    }
75
+    
76
+}
77
+
78
+def buildDockerImage() {
79
+    dir ('.tamarin') {
80
+        def dockerfile = libraryResource 'com/cadoles/tamarin/Dockerfile'
81
+        writeFile file:'Dockerfile', text:dockerfile
82
+
83
+        def runTamarinScript = libraryResource 'com/cadoles/tamarin/run-tamarin.sh'
84
+        writeFile file:'run-tamarin.sh', text:runTamarinScript
85
+        
86
+        def safeJobName = URLDecoder.decode(env.JOB_NAME).toLowerCase().replace('/', '-')
87
+        def imageTag = "${safeJobName}-${env.BUILD_ID}"
88
+        return docker.build("tamarin:${imageTag}", ".")
89
+    }
90
+}

+ 20
- 0
vars/vulcain.groovy View File

@@ -0,0 +1,20 @@
1
+def publish(
2
+    String packagesDir = './packages', 
3
+    String packagesEnv = 'dev', 
4
+    String packagesBranch = '',
5
+    String sshCredentialsId = 'vulcain-packages-ssh-keypair',
6
+    String vulcainHost = 'vulcain.cadoles.com'
7
+) {
8
+    if (!packagesBranch) {
9
+        packagesBranch = env.BRANCH_NAME
10
+    }
11
+    withCredentials([
12
+        sshUserPrivateKey(credentialsId: sshCredentialsId, keyFileVariable: 'VULCAIN_SSH_KEY', usernameVariable: 'VULCAIN_SSH_USER')
13
+    ]) {
14
+        sh """
15
+        SSH_ARGS='-i ${VULCAIN_SSH_KEY} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
16
+        ssh \$SSH_ARGS ${VULCAIN_SSH_USER}@${vulcainHost} mkdir -p '/home/${VULCAIN_SSH_USER}/packages/${packagesEnv}/${packagesBranch}'
17
+        scp \$SSH_ARGS -r ${packagesDir}/*.deb '${VULCAIN_SSH_USER}@${vulcainHost}:/home/${VULCAIN_SSH_USER}/packages/${packagesEnv}/${packagesBranch}/'
18
+        """
19
+    }
20
+}

Loading…
Cancel
Save