Add jenkins slave image update jobs 15/12015/2
authorsankar palanivel <sankar.palanivel@est.tech>
Thu, 13 Jan 2022 14:26:05 +0000 (14:26 +0000)
committersankar palanivel <sankar.palanivel@est.tech>
Thu, 13 Jan 2022 14:33:50 +0000 (14:33 +0000)
In this change,
  - Add packer build jobs to update nordix jenkins
   build slave images

Change-Id: I2c3f9455f8f5c57c51bf504def1e1b1ad62a80d2

jjb/infra/packer_build_jobs.yaml [new file with mode: 0644]
jjb/infra/update-jenkins-slave.sh [new file with mode: 0644]

diff --git a/jjb/infra/packer_build_jobs.yaml b/jjb/infra/packer_build_jobs.yaml
new file mode 100644 (file)
index 0000000..925bf58
--- /dev/null
@@ -0,0 +1,119 @@
+---
+# ============LICENSE_START=======================================================
+#  Copyright (C) 2021 Nordix Foundation.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# SPDX-License-Identifier: Apache-2.0
+# ============LICENSE_END=========================================================
+- project:
+
+    name: jenkins-slave-update-job
+
+    project: infra/tools
+
+    stream:
+      - master:
+          branch: '{stream}'
+
+    target:
+      - 'cloud-infra':
+           image: 'cloud-infra-base-ubuntu1804'
+           openstack-project: 'CICD'
+           region: 'fra'
+      - 'nordix-nsm-build-server':
+           image: 'nordix-nsm-build-ubuntu1804'
+           openstack-project: 'CICD'
+           region: 'fra'
+      - 'uds-build-server':
+           image: 'onap-uds-build-ubuntu1804'
+           openstack-project: 'CICD'
+           region: 'fra'
+      - 'nordix-onap-jenkins-build-server':
+           image: 'onap-build-ubuntu1804'
+           openstack-project: 'DefaultProject34201'
+           region: 'kna'
+      - 'oransc-build-server':
+           image: 'oransc-build-ubuntu2004'
+           openstack-project: 'DefaultProject34201'
+           region: 'kna'
+
+    jobs:
+      - jenkins-slave-update-{target}-{stream}
+
+- job-template:
+    name: jenkins-slave-update-{target}-{stream}
+
+    node: packer-ubuntu1804
+
+    disabled: false
+
+    concurrent: false
+
+    parameters:
+      - project-parameters:
+          project: '{project}'
+          branch: '{branch}'
+      - nordix-gerrit-parameters
+      - string:
+          name: PACKER_VERSION
+          default: '1.6.0'
+          description: 'Packer version.'
+      - string:
+          name: TARGET
+          default: '{target}'
+          description: 'Target project name.'
+      - string:
+          name: IMAGE
+          default: '{image}'
+          description: 'Image name to build.'
+
+    properties:
+      - logrotate
+
+    scm:
+      - git-scm:
+          ssh-credentials-id: nordixinfra-nordix-gerrit-ssh
+          branch: '{branch}'
+          refspec: ''
+          wipe_workspace: true
+          clean_before: false
+
+    triggers:
+      - nordix-gerrit-trigger-change-merged:
+          project: '{project}'
+          branch: '{branch}'
+          files: 'infra/jenkins/slave-setup/{target}/**'
+
+    wrappers:
+      - build-timeout:
+          timeout: 150
+      - fix-workspace-permissions
+      - mask-passwords
+      - openstack:
+          single-use: true
+      - credentials-binding:
+          - file:
+              credential-id: '{openstack-project}-openrc-{region}'
+              variable: OPENRC_FILE
+
+    builders:
+      - shell: |
+          #!/bin/bash
+          /bin/rm -f /tmp/openrc
+          /bin/cp -f $OPENRC_FILE /tmp/openrc
+      - shell: |
+          !include-raw-escape: ./update-jenkins-slave.sh
+      - shell: |
+          #!/bin/bash
+          /bin/rm -f /tmp/openrc
diff --git a/jjb/infra/update-jenkins-slave.sh b/jjb/infra/update-jenkins-slave.sh
new file mode 100644 (file)
index 0000000..9473aae
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/bash
+set -o errexit
+set -o nounset
+set -o pipefail
+
+sudo apt install -y -q=3 python3-minimal python3-pip virtualenv
+
+# workaround for https://github.com/pypa/virtualenv/issues/1029
+export PS1=${PS1:-}
+
+cd "$WORKSPACE"
+echo "----------------------------------------------------"
+echo "Info: Create virtualenv to update Jenkins slaves"
+virtualenv -p python3 --quiet --no-site-packages .venv
+source .venv/bin/activate
+pip install python-openstackclient
+echo "----------------------------------------------------"
+echo "Info  : Installing packer version ${PACKER_VERSION}"
+wget -q "https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip" -O /tmp/packer.zip
+unzip /tmp/packer.zip > /dev/null 2>&1
+sudo mv -f ./packer /usr/local/bin/packer
+sudo chmod +x /usr/local/bin/packer
+echo "----------------------------------------------------"
+packer -version
+/bin/rm -f /tmp/packer.zip
+# shellcheck disable=SC1091
+source "/tmp/openrc"
+echo "----------------------------------------------------"
+echo "Info: Create backup of existing image"
+cd "$WORKSPACE"
+BACKUP_ZONE_ID=$(openstack image list --property name=${IMAGE} -f value -c ID)
+openstack image set --name "${IMAGE}-backup-$GIT_COMMIT" "$BACKUP_ZONE_ID"
+echo "----------------------------------------------------"
+echo "Info: Updating the CI slave image"
+cd "infra/jenkins/slave-setup/${TARGET}/"
+packer validate *-ubuntu*.json
+packer build *-ubuntu*.json
+echo "----------------------------------------------------"
\ No newline at end of file