From 538cdcdba4a703e8239f7d83e2f3ad08d8297f37 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Wed, 1 Apr 2020 13:49:29 +0200 Subject: [PATCH] add make-containerized-build job The job does not have any parameters yet, it only build for the master branch. Signed-off-by: Niels de Vos --- README.md | 46 +++++++++++++++++++++++++++++++++ make-containerized-build.groovy | 44 +++++++++++++++++++++++++++++++ make-containerized-build.yaml | 19 ++++++++++++++ prepare.sh | 7 +++++ 4 files changed, 116 insertions(+) create mode 100644 make-containerized-build.groovy create mode 100644 make-containerized-build.yaml create mode 100755 prepare.sh diff --git a/README.md b/README.md index 1bd02c952..c889bc444 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,53 @@ - Jenkins is hosted on [OpenShift in the CentOS CI](app_ci_centos_org) - scripts and Jenkins jobs are hosted in the Ceph-CSI repository (ci/centos branch) +- a Jenkins Pipeline is used to reserve bare metal system(s), and run jobs on + those systems + +# Repository/Branch Structure + +This is the `ci/centos` branch, where all the scripts for the Jenkins jobs are +maintained. The tests that are executed by the jobs are part of the normal +projects branches. + +As an example, the `make-containerized-build` Jenkins job consists out of the +following files: + +- `make-containerized-build.yaml` is a [Jenkins Job Builder](jjb) configuration + that describes the events when the job should get run and fetches the + `.groovy` file from the git repository/branch +- `make-containerized-build.groovy` is the [Jenkins Pipeline](pipeline) that + contains the stages for the Jenkins Job itself. In order to work with [the + bare-metal machines from the CentOS CI](centos_ci), it executes the following + stages: + + 1. dynamically allocate a Jenkins Slave (`node('cico-workspace')`) with tools + and configuration to request a bare-metal machine + 1. checkout the `centos/ci` branch of the repository, which contains scripts + for provisioning and preparing the environment for running tests + 1. reserve a bare-metal machine with `cico` (configured on the Jenkins Slave) + 1. provision the reserved bare-metal machine with additional tools and + dependencies to run the test (see `prepare.sh` below) + 1. run the test + 1. as final step, return the bare-metal machine to the CentOS CI for other + users (it will be re-installed with a minimal CentOS environment again) + +- `prepare.sh` installs dependencies for the test, and checks out the git + repository and branch (or Pull Request) that contains the commits to be + tested (and the test itself) + +## Deploying the Jenkins Jobs + +The Jenkins Jobs are described in Jenkins Job Builder configuration files and +Jenkins Pipelines. These need to be imported in the Jenkins instance before +they can be run. Importing is done with the `jenkins-jobs` command, which runs +in a `jjb` container. To build the container, and provide the configuration for +Jenkins Job Builder, see the [documentation in the `deploy/` +directory](deploy/README.md). [ceph_csi_ci]: https://jenkins-ceph-csi.apps.ci.centos.org [app_ci_centos_org]: https://console.apps.ci.centos.org:8443/console/project/ceph-csi +[jjb]: https://jenkins-job-builder.readthedocs.io/en/latest/index.html +[pipeline]: https://docs.openstack.org/infra/jenkins-job-builder/project_pipeline.html +[centos_ci_hw]: https://wiki.centos.org/QaWiki/PubHardware diff --git a/make-containerized-build.groovy b/make-containerized-build.groovy new file mode 100644 index 000000000..c4ea32d13 --- /dev/null +++ b/make-containerized-build.groovy @@ -0,0 +1,44 @@ +def cico_retries = 16 +def cico_retry_interval = 60 +def ci_git_repo = 'https://github.com/ceph/ceph-csi' +def ci_git_branch = 'ci/centos' + +node('cico-workspace') { + // environment (not?) set by Jenkins, or not? + environment { + GIT_REPO = 'https://github.com/ceph/ceph-csi' + GIT_BRANCH = 'master' + } + + stage('checkout ci repository') { + git url: "${ci_git_repo}", + branch: "${ci_git_branch}", + changelog: false + } + + stage('reserve bare-metal machine') { + cico = sh( + script: "cico node get -f value -c hostname -c comment --retry-count ${cico_retries} --retry-interval ${cico_retry_interval}", + returnStdout: true + ).trim().tokenize(' ') + env.CICO_NODE = "${cico[0]}.ci.centos.org" + env.CICO_SSID = "${cico[1]}" + } + + try { + stage('prepare bare-metal machine') { + sh 'scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ./prepare.sh root@${CICO_NODE}:' + sh 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${CICO_NODE} ./prepare.sh --workdir=/opt/build --gitrepo=${GIT_REPO} --branch=${GIT_BRANCH}' + } + + stage('build') { + sh 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${CICO_NODE} "cd /opt/build && make containerized-build CONTAINER_CMD=podman"' + } + } + + finally { + stage('return bare-metal machine') { + sh 'cico node done ${CICO_SSID}' + } + } +} diff --git a/make-containerized-build.yaml b/make-containerized-build.yaml new file mode 100644 index 000000000..519cb6312 --- /dev/null +++ b/make-containerized-build.yaml @@ -0,0 +1,19 @@ +--- +- job: + name: make-containerized-build + project-type: pipeline + sandbox: true + pipeline-scm: + scm: + - git: + url: https://github.com/ceph/ceph-csi + branches: + - ci/centos + script-path: make-containerized-build.groovy + lightweight-checkout: true + triggers: + - github-pull-request: + admin-list: + - nixpanic + org-list: + - ceph diff --git a/prepare.sh b/prepare.sh new file mode 100755 index 000000000..4ff0219f0 --- /dev/null +++ b/prepare.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +set -x + +yum -y install git podman + +git clone --single-branch --branch=master https://github.com/ceph/ceph-csi /opt/build