#6 image-build template job
Merged 2 years ago by lrossett. Opened 2 years ago by lrossett.
kube-sig/ lrossett/jenkins resultsdb-image-job  into  master

@@ -0,0 +1,40 @@ 

+ def repo = params.REPO

+ def branch = params.BRANCH

+ def branch_to = params.BRANCH_TO

+ 

+ def push_secret_name = 'quay-secret'

+ def image_push = branch_to == 'None'

+ 

+ node('cico-workspace') {

+     def jobName = 'container-image-build-and-push'   

+     def jobs = [

+         [

+             'chdir': 'images/resultsdb-backend',

+             'image_name': 'quay.io/fedora-kube-sig/resultsdb-backend:latest-f35',

+             'extra_args': 'OS_NAME=fedora OS_VERSION=35',

+             'push_secret_name': push_secret_name,

+             'image_push': image_push

+         ],

+         [

+             'chdir': 'images/resultsdb-frontend',

+             'image_name': 'quay.io/fedora-kube-sig/resultsdb-frontend:latest-f35',

+             'extra_args': 'OS_NAME=fedora OS_VERSION=35',

+             'push_secret_name': push_secret_name,

+             'image_push': image_push

+         ]

+     ]

+ 

+     jobs.each { job ->

+         def jobParams = [

+             string(name: 'GIT_URL', value: repo),

+             string(name: 'GIT_REFS', value: branch),

+             string(name: 'CHDIR', value: job.chdir),

+             string(name: 'IMAGE_NAME', value: job.image_name),

+             string(name: 'IMAGE_BUILD_EXTRA_ARGS', value: job.extra_args),

+             string(name: 'PUSH_SECRET_NAME', value: job.push_secret_name),

+             booleanParam(name: 'IMAGE_PUSH', value: job.image_push)

+         ]

+     

+         build job: jobName, parameters: jobParams 

+     }

+ }

@@ -0,0 +1,40 @@ 

+ - job-template:

+     name: gating-services-images-pagure-ci

+     project-type: pipeline

+     display-name: Gating Services Images Pagure CI

+     auth-token: "{auth_token}"

+     notifications:

+       - raw:

+           xml: |-

+             <com.tikal.hudson.plugins.notification.Endpoint>

+               <protocol>HTTP</protocol>

+               <format>JSON</format>

+               <urlInfo>

+                 <urlOrId>gating-services-images-pagure-ci-url</urlOrId>

+                 <urlType>SECRET</urlType>

+               </urlInfo>

+               <event>all</event>

+               <timeout>60000</timeout>

+               <loglines>0</loglines>

+               <buildNotes/>

+               <retries>0</retries>

+             </com.tikal.hudson.plugins.notification.Endpoint>

+     pipeline-scm:

+       scm:

+         - git:

+             url: https://pagure.io/kube-sig/jenkins.git

+             branches:

+               - master

+             clean:

+               after: true

+       script-path: defs/jobs/gating-services/gating-services-images-pagure-ci/Jenkinsfile

+     parameters:

+       - string:

+           name: "REPO"

+           description: "The GIT repository to pull from"

+       - string:

+           name: "BRANCH"

+           description: "GIT branch to  source from"

+       - string:

+           name: "BRANCH_TO"

+           description: "GIT branch merge to"

defs/jobs/library/container-image-build-and-push/Jenkinsfile defs/jobs/images/container-image/Jenkinsfile
file renamed
+51 -36
@@ -1,10 +1,10 @@ 

- #!groovy

- 

  def git_refs = params.GIT_REFS

  def git_repo = params.GIT_REPO

  def chdir = params.CHDIR

  def image_name = params.IMAGE_NAME

- def quay_secret_name = params.QUAY_SECRET_NAME

+ def image_build_extra_args = params.IMAGE_BUILD_EXTRA_ARGS

+ def image_push = params.IMAGE_PUSH

+ def push_secret_name = params.PUSH_SECRET_NAME

  

  def node_sh(cmd) {

      def key_path = '/duffy-ssh-key/ssh-privatekey'
@@ -21,53 +21,68 @@ 

  }

  

  node('cico-workspace') {

-     stage('cico') {

-         node = sh(script: "cico --debug node get -f value -c hostname -c comment", returnStdout: true).trim().tokenize(' ')

-         env.node_hostname = "${node[0]}.ci.centos.org"

-         env.node_ssid = "${node[1]}"

+     try {

+         stage('cico') {

+             node = sh(script: "cico --debug node get --release 9-stream -f value -c hostname -c comment", returnStdout: true).trim().tokenize(' ')

+             env.node_hostname = "${node[0]}.ci.centos.org"

+             env.node_ssid = "${node[1]}"

  

-          wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[var: 'node_hostname', password: node_hostname]], varMaskRegexes: []]) {

-             node_sh 'cat /etc/centos-release'

-          }

-     }

+              wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[var: 'node_hostname', password: node_hostname]], varMaskRegexes: []]) {

+                 node_sh 'cat /etc/centos-release'

+              }

+         }

  

-     stage('prepare') {

-         node_sh 'yum install -y podman'

+         stage('prepare') {

+             node_sh 'yum install -y make podman'

  

-         withCredentials([file(credentialsId: quay_secret_name, variable: 'quay_secret_json')]) {

-             node_sh 'mkdir -p /.docker'

+             if (image_push) {

+                 withCredentials([file(credentialsId: push_secret_name, variable: 'push_secret_json')]) {

+                     node_sh 'mkdir -p /.docker'

  

-             dir("/tmp/${env.node_hostname}") {

-                 writeFile file: 'config.json', text: readFile(quay_secret_json)

-                 wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[var: 'node_hostname', password: node_hostname]], varMaskRegexes: []]) {

-                     sh "scp -o StrictHostKeyChecking=no -i /duffy-ssh-key/ssh-privatekey ./config.json root@${node_hostname}:/.docker"

+                     dir("/tmp/${env.node_hostname}") {

+                         writeFile file: 'config.json', text: readFile(push_secret_json)

+                         wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[var: 'node_hostname', password: node_hostname]], varMaskRegexes: []]) {

+                             sh "scp -o StrictHostKeyChecking=no -i /duffy-ssh-key/ssh-privatekey ./config.json root@${node_hostname}:/.docker"

+                         }

+                         deleteDir()

+                     }

                  }

-                 deleteDir()

              }

          }

-     }

  

-     stage('checkout') {

-         dir('koji-operator') {

-             git branch: git_refs, url: git_url

+         stage('checkout') {

+             dir('repository') {

+                 git branch: git_refs, url: git_url

  

-             node_sh "mkdir -p /tmp/${chdir}"

+                 node_sh "mkdir -p /tmp/${chdir}"

  

-             wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[var: 'node_hostname', password: node_hostname]], varMaskRegexes: []]) {

-                 sh "scp -o StrictHostKeyChecking=no -i /duffy-ssh-key/ssh-privatekey -r ${chdir}/* root@${node_hostname}:/tmp/${chdir}"

+                 wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[var: 'node_hostname', password: node_hostname]], varMaskRegexes: []]) {

+                     sh "scp -o StrictHostKeyChecking=no -i /duffy-ssh-key/ssh-privatekey -r ${chdir}/* root@${node_hostname}:/tmp/${chdir}"

+                 }

              }

          }

-     }

  

-     stage('build') {

-         node_sh "podman build -t ${image_name} -f /tmp/${chdir}/Dockerfile /tmp/${chdir}"

-     }

+         stage('build') {

+             node_sh "(cd /tmp/${chdir}; make image/build IMAGE=${image_name} ${image_build_extra_args};)"

+         }

  

-     stage('push') {

-             node_sh "podman push --authfile /.docker/config.json ${image_name}"

+         stage('push') {

+             if (image_push) {

+                 node_sh "podman push --authfile /.docker/config.json ${image_name}"

+             }

          }

  

-     stage('cleanup') {

-         sh "cico node done ${node_ssid}"

+         stage('cleanup') {

+             wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[var: 'node_hostname', password: node_hostname]], varMaskRegexes: []]) {

+                 sh "cico -q node done ${node_ssid}"

+             }

+         }

+ 

+     } catch (Exception e) {

+         stage('fail') {

+             sh "cico node done ${node_ssid}"

+             error '[ERROR] ' + e.toString()

+         }

      }

- }

+ } 

+ 

defs/jobs/library/container-image-build-and-push/job.yaml defs/jobs/images/container-image/job.yaml
file renamed
+13 -8
@@ -1,7 +1,7 @@ 

  - job:

-     name: container-image

+     name: "container-image-build-and-push"

      project-type: pipeline

-     display-name: Container Image Build n Push

+     display-name: Container Image Build and Push

      pipeline-scm:

        scm:

          - git:
@@ -10,7 +10,7 @@ 

                - master

              clean:

                after: true

-       script-path: defs/jobs/images/container-image/Jenkinsfile

+       script-path: defs/jobs/library/container-image-build-and-push/Jenkinsfile

      parameters:

        - string:

            name: "GIT_URL"
@@ -18,15 +18,20 @@ 

        - string:

            name: "GIT_REFS"

            description: "GIT refs to use, such as branch, tag, commit, etc"

-           default: "main"

        - string:

            name: "CHDIR"

            description: "Dockerfile directory to use"

-           default: "."

        - string:

            name: "IMAGE_NAME"

            description: "fully qualified image name to use, example: quay.io/fedora/myimage:latest"

        - string:

-           name: "QUAY_SECRET_NAME"

-           description: "quay secret name to use"

-           default: "quay-secret"

+           name: "IMAGE_BUILD_EXTRA_ARGS"

+           description: "extra build arguments to be used when building the image (KEY1=VALUE1 KEY2=VALUE2)"

+       - string:

+           name: "PUSH_SECRET_NAME"

+           description: "push secret name to use"

+       - bool:

+           name: "IMAGE_PUSH"

+           description: "boolean value to indicate if the built image should also be pushed to a registry"

+           default: true

+ 

file modified
+6
@@ -4,3 +4,9 @@ 

        - koji-operator-pagure-ci:

            auth_token: "{job_koji_operator_pagure_ci_auth_token}"

  

+ 

+ - project:

+     name: gating-services

+     jobs:

+       - gating-services-images-pagure-ci:

+           auth_token: "{job_gating_services_images_pagure_ci_auth_token}"

file modified
+16 -3
@@ -1,8 +1,8 @@ 

  - view:

-     name: images

+     name: library

      view-type: list

      job-name:

-       - container-image

+       - container-image-build-and-push

      columns:

        - status

        - weather
@@ -34,4 +34,17 @@ 

        - job

        - last-success

        - last-failure

-       - last-duration 

\ No newline at end of file

+       - last-duration

+ 

+ - view:

+     name: gating-services

+     view-type: list

+     job-name:

+       - gating-services-images-pagure-ci

+     columns:

+       - status

+       - weather

+       - job

+       - last-success

+       - last-failure

+       - last-duration