From 4f4fd0d6bf3806018af905adbf3fc59f481a54ae Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Mon, 31 Oct 2022 10:17:45 -0500 Subject: [PATCH] ci: Enable ccache for buildroot I wanted to use a persistent volume for the workspace volume of this Jenkins pipeline in order to speed up subsequent builds. Unfortunately, this feature does not really work well in Jenkins. Since the agent is removed when the build completes, and therefore the volume is not mounted anywhere, Jenkins cannot delete workspaces for deleted jobs. This means that when feature branches/pull requests are merged, their workspaces remain on disk forever. Using the *dynamicPVC* option deletes the entire volume when the job finishes. This avoids wasting space, but does not allow subsequent builds to reuse the workspace. As a compromise, we can use a persistent volume for the compiler cache and share it between builds. Using the compiler cache is not as effective as keeping the whole build directory, but it still saves some time. Also, it works across branches, too. --- ci/Jenkinsfile | 15 +-------------- ci/podTemplate.yaml | 8 ++++++++ ci/pvc.yaml | 4 ++-- configs/pythonctnr_defconfig | 1 + 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index c32aed6..ffef8f8 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -5,9 +5,7 @@ pipeline { kubernetes { yamlFile 'ci/podTemplate.yaml' defaultContainer 'buildroot' - workspaceVolume persistentVolumeClaimWorkspaceVolume( - claimName: 'jenkins-ws-pythonctnr' - ) + workspaceVolume dynamicPVC() } } @@ -16,20 +14,9 @@ pipeline { disableConcurrentBuilds() } - parameters { - booleanParam \ - name: 'Clean', - description: 'Clean the workspace and perform a full rebuild' - } - stages { stage('Prepare') { steps { - script { - if (params.Clean) { - sh 'rm -rf _build' - } - } checkout poll: false, scm: [ $class: 'GitSCM', branches: [[name: '2022.05.x']], diff --git a/ci/podTemplate.yaml b/ci/podTemplate.yaml index 6c05c0e..3a930b8 100644 --- a/ci/podTemplate.yaml +++ b/ci/podTemplate.yaml @@ -7,9 +7,14 @@ spec: command: - sleep - infinity + env: + - name: HOME + value: /home/jenkins volumeMounts: - name: tmp mountPath: /tmp + - name: br2-ccache + mountPath: /home/jenkins/.buildroot-ccache securityContext: readOnlyRootFilesystem: true runAsUser: 1000 @@ -25,3 +30,6 @@ spec: emptyDir: medium: Memory sizeLimit: 100Mi + - name: br2-ccache + persistentVolumeClaim: + claimName: jenkins-br2-ccache diff --git a/ci/pvc.yaml b/ci/pvc.yaml index 51c9dc0..93ea415 100644 --- a/ci/pvc.yaml +++ b/ci/pvc.yaml @@ -5,10 +5,10 @@ apiVersion: v1 kind: PersistentVolumeClaim metadata: - name: jenkins-ws-pythonctnr + name: jenkins-br2-ccache spec: accessModes: - ReadWriteOnce resources: requests: - storage: 10Gi + storage: 20Gi diff --git a/configs/pythonctnr_defconfig b/configs/pythonctnr_defconfig index aca678d..26be9f7 100644 --- a/configs/pythonctnr_defconfig +++ b/configs/pythonctnr_defconfig @@ -1,4 +1,5 @@ BR2_x86_64=y +BR2_CCACHE=y BR2_TOOLCHAIN_BUILDROOT_GLIBC=y BR2_TARGET_GENERIC_HOSTNAME="pythonctnr" BR2_TARGET_GENERIC_ISSUE=""