From f6b6c21900f0654abcdfa2fc7293f93b3f6782a1 Mon Sep 17 00:00:00 2001
From: Leonardo Rossetti <lrossett@redhat.com>
Date: Apr 20 2022 14:51:41 +0000
Subject: molecule test jobs


---

diff --git a/defs/jobs/koji-operator/koji-operator-molecule-tests/Jenkinsfile b/defs/jobs/koji-operator/koji-operator-molecule-tests/Jenkinsfile
new file mode 100644
index 0000000..5ebf122
--- /dev/null
+++ b/defs/jobs/koji-operator/koji-operator-molecule-tests/Jenkinsfile
@@ -0,0 +1,74 @@
+#!groovy
+
+def git_url = params.GIT_URL
+def git_refs = params.GIT_REFS
+
+def node_sh(cmd, username='root') {
+    def key_path = '/duffy-ssh-key/ssh-privatekey'
+    def vars = [
+        [var: 'node_hostname', password: node_hostname]
+    ]
+    def regexes = [
+        [regex: ',([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\'']
+    ]
+
+    wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: vars, varMaskRegexes: regexes]) {
+        sh "ssh -o StrictHostKeyChecking=no ${username}@${node_hostname} -i ${key_path} '${cmd}'"
+    }
+}
+
+node('cico-workspace') {
+    stage('cico') {
+        node = sh(script: "cico --debug node get --release 8-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'
+        }
+    }
+
+    stage('dependencies') {
+        // system packages
+        node_sh 'yum install -y make rust cargo podman python3-devel python3-pip python3-setuptools python3-setuptools-*'
+
+        //pip packages
+        node_sh 'pip3 install wheel setuptools-rust'
+        node_sh 'pip3 install ansible molecule'
+        
+        //kustomize
+        node_sh 'curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash'
+        node_sh 'mv kustomize /usr/bin/kustomize'
+        node_sh 'chmod +x /usr/bin/kustomize'
+
+        //minikube
+        node_sh 'curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64'
+        node_sh 'install minikube-linux-amd64 /usr/local/bin/minikube'
+    }
+
+    stage('prepare') {
+        node_sh 'adduser kubesig'
+        node_sh 'usermod -aG wheel kubesig'
+        node_sh 'echo "kubesig ALL=(ALL) NOPASSWD: /usr/bin/podman" >> /etc/sudoers'
+    }
+
+    stage('checkout') {
+        dir('koji-operator') {
+            git branch: git_refs, url: git_url
+
+            node_sh "mkdir -p /tmp/koji-operator"
+
+            wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[var: 'node_hostname', password: node_hostname]], varMaskRegexes: []]) {
+                sh "scp -o StrictHostKeyChecking=no -i /duffy-ssh-key/ssh-privatekey -r operator/* root@${node_hostname}:/tmp/koji-operator"
+            }
+        }
+    }
+
+    stage('test') {
+        node_sh '(cd /tmp/koji-operator; sudo -h kubesig bash -c \'MINIKUBE_DRIVER=podman molecule test -s minikube\')'
+    }
+    
+    stage('cleanup') {
+        sh "cico node done ${node_ssid}"
+    }
+}
diff --git a/defs/jobs/koji-operator/koji-operator-molecule-tests/job.yaml b/defs/jobs/koji-operator/koji-operator-molecule-tests/job.yaml
new file mode 100644
index 0000000..43e3413
--- /dev/null
+++ b/defs/jobs/koji-operator/koji-operator-molecule-tests/job.yaml
@@ -0,0 +1,21 @@
+- job:
+    name: koji-operator-molecule-tests
+    project-type: pipeline
+    display-name: Koji Operator Molecule Tests
+    pipeline-scm:
+      scm:
+        - git:
+            url: https://pagure.io/kube-sig/jenkins.git
+            branches:
+              - master
+            clean:
+              after: true
+      script-path: defs/jobs/koji-operator/koji-operator-molecule-tests/Jenkinsfile
+    parameters:
+      - string:
+          name: "GIT_URL"
+          description: "GIT repository url to pull from"
+      - string:
+          name: "GIT_REFS"
+          description: "GIT refs to use, such as branch, tag, commit, etc"
+          default: "main"
diff --git a/defs/jobs/koji-operator/koji-operator-pagure-ci/Jenkinsfile b/defs/jobs/koji-operator/koji-operator-pagure-ci/Jenkinsfile
new file mode 100644
index 0000000..c5b2879
--- /dev/null
+++ b/defs/jobs/koji-operator/koji-operator-pagure-ci/Jenkinsfile
@@ -0,0 +1,13 @@
+def repo = params.REPO
+def branch = params.BRANCH
+def branch_to = params.BRANCH_TO
+
+node('cico-workspace') {
+    def jobName = 'operator-sdk-molecule-test'
+    def jobParams = [
+        string(name: 'GIT_URL', value: repo),
+        string(name: 'GIT_REFS', value: branch)
+    ]
+    
+    build job: jobName, parameters: jobParams 
+}
diff --git a/defs/jobs/koji-operator/koji-operator-pagure-ci/job.yaml b/defs/jobs/koji-operator/koji-operator-pagure-ci/job.yaml
new file mode 100644
index 0000000..aa5c81b
--- /dev/null
+++ b/defs/jobs/koji-operator/koji-operator-pagure-ci/job.yaml
@@ -0,0 +1,31 @@
+- job-template:
+    name: koji-operator-pagure-ci
+    project-type: pipeline
+    display-name: Koji-Operator CI
+    auth-token: "{auth_token}"
+    notifications:
+      - http:
+          url: "https://pagure.io/api/0/ci/jenkins/kube-sig/koji-operator/{auth_token}/build-finished"
+          format: json
+          event: all
+          timeout: 60000
+          log: 1
+    pipeline-scm:
+      scm:
+        - git:
+            url: https://pagure.io/forks/lrossett/kube-sig/jenkins.git
+            branches:
+              - master
+            clean:
+              after: true
+      script-path: defs/jobs/koji-operator/koji-operator-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 "
diff --git a/defs/projects.yaml b/defs/projects.yaml
new file mode 100644
index 0000000..3a0803e
--- /dev/null
+++ b/defs/projects.yaml
@@ -0,0 +1,6 @@
+- project:
+    name: koji-operator
+    jobs:
+      - koji-operator-pagure-ci:
+          auth_token: "{job_koji_operator_pagure_ci_auth_token}"
+
diff --git a/defs/views.yaml b/defs/views.yaml
index bd7fe33..9959f52 100644
--- a/defs/views.yaml
+++ b/defs/views.yaml
@@ -22,3 +22,16 @@
       - last-success
       - last-failure
       - last-duration
+- view:
+    name: koji-operator
+    view-type: list
+    job-name:
+      - koji-operator-pagure-ci
+      - koji-operator-molecule-tests
+    columns:
+      - status
+      - weather
+      - job
+      - last-success
+      - last-failure
+      - last-duration
\ No newline at end of file

