Merge "Adding TLS authentication" into dev/icn-v0.2.0 dev/icn-v0.2.0
authorEnyinna Ochulor <enyinna.ochulor@intel.com>
Mon, 23 Sep 2019 23:33:19 +0000 (23:33 +0000)
committerGerrit Code Review <gerrit@akraino.org>
Mon, 23 Sep 2019 23:33:19 +0000 (23:33 +0000)
12 files changed:
Jenkinsfile [new file with mode: 0644]
ci/README.md [new file with mode: 0644]
ci/gerrit.groovy [new file with mode: 0644]
ci/icn_check.xml [new file with mode: 0644]
ci/setup_jenkins.sh [new file with mode: 0755]
ci/site_jenkins.yaml [new file with mode: 0644]
deploy/kud-plugin-addons/minio/install.sh [new file with mode: 0755]
deploy/kud-plugin-addons/minio/local-pv.yaml [new file with mode: 0644]
deploy/kud-plugin-addons/minio/local-pvc.yaml [new file with mode: 0644]
deploy/kud-plugin-addons/minio/local-sc.yaml [new file with mode: 0644]
deploy/kud-plugin-addons/minio/minio-deployment.yaml [new file with mode: 0644]
deploy/kud-plugin-addons/minio/minio-service.yaml [new file with mode: 0644]

diff --git a/Jenkinsfile b/Jenkinsfile
new file mode 100644 (file)
index 0000000..895065a
--- /dev/null
@@ -0,0 +1,30 @@
+pipeline {
+    agent any
+    options {
+        skipDefaultCheckout()
+    }
+    environment {
+        changeBranch = "change-${GERRIT_CHANGE_NUMBER}-${GERRIT_PATCHSET_NUMBER}"
+    }
+    stages {
+        stage("Build ISO Image") {
+            steps {
+                sh "sudo rm -rf icn build/ubuntu icn-ubuntu-18.04.iso"
+                sh "git clone https://gerrit.akraino.org/r/icn"
+                dir("icn") {
+                    sh "git fetch origin ${GERRIT_REFSPEC}:${changeBranch}"
+                    sh "git checkout ${changeBranch}"
+                    sh "git rebase origin/${GERRIT_BRANCH}"
+                }
+                sh "sudo icn/tools/setup_build_machine.sh"
+                // sh "sudo icn/tools/collect.sh"
+                sh "sudo icn/tools/create_usb_bootable.sh"
+            }
+        }
+    }
+    post {
+        always {
+            archiveArtifacts artifacts: "icn-ubuntu-18.04.iso", onlyIfSuccessful: true
+        }
+    }
+}
diff --git a/ci/README.md b/ci/README.md
new file mode 100644 (file)
index 0000000..c368dc3
--- /dev/null
@@ -0,0 +1,24 @@
+# Setup a private Jenkins server from a refresh ubuntu
+
+
+**Note:** As we don't support that downloading packages in sandbox for now,
+it means that the packages are all downloaded directely from the jenkins
+server. So that the jenkins server must have the same OS version with ICN
+nodes. Currently, it's ubuntu 18.04 with kernel version 4.15.0-45-generic.
+
+## How to setup jenkins server
+
+Put the gerrit ssh key under `icn/ci/gerrit.key`
+The default listening address is the default ip address of the Jenkins server.
+To override the listening address/domain name, use variable `jenkins_hostname`.
+The default Jenkins username/password is `admin/admin`. To overrides it, use variables
+`jenkins_admin_username` and `jenkins_admin_password`.
+
+```bash
+git clone "https://gerrit.akraino.org/r/icn" # may need to switch the branch based on your case
+cd icn/ci
+sudo ./setup_jenkins.sh
+sudo ansible-playbook site_jenkins.yaml -v
+```
+
+Once the playbook is successful, we can visite the jenkins server at http://<listen_address>:8080.
diff --git a/ci/gerrit.groovy b/ci/gerrit.groovy
new file mode 100644 (file)
index 0000000..38d3076
--- /dev/null
@@ -0,0 +1,34 @@
+import jenkins.*
+import jenkins.model.*
+import hudson.*
+import hudson.model.*
+import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Config
+import com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer
+import com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl
+
+
+def gerrit_server_name = 'gerrit.akraino.org'
+def gerrit_hostname = 'gerrit.akraino.org'
+def gerrit_key_path = '/var/lib/jenkins/.ssh/gerrit.key'
+def gerrit_url = 'https://gerrit.akraino.org/'
+def gerrit_username = 'icn.jenkins'
+
+if (PluginImpl.getInstance().getServer(gerrit_server_name) == null) {
+  GerritServer defaultServer = new GerritServer(gerrit_server_name)
+  Config config = defaultServer.getConfig()
+  PluginImpl.getInstance().addServer(defaultServer)
+  defaultServer.start()
+  // setting properties
+  config.setGerritHostName(gerrit_hostname)
+  config.setGerritFrontEndURL(gerrit_url)
+  config.setGerritUserName(gerrit_username)
+  config.setGerritAuthKeyFile(new File(gerrit_key_path))
+} else {
+  Config config = PluginImpl.getInstance().getServer(gerrit_server_name).getConfig()
+  config.setGerritHostName(gerrit_hostname)
+  config.setGerritFrontEndURL(gerrit_url)
+  config.setGerritUserName(gerrit_username)
+  config.setGerritAuthKeyFile(new File(gerrit_key_path))
+  PluginImpl.getInstance().save()
+}
+return "success"
diff --git a/ci/icn_check.xml b/ci/icn_check.xml
new file mode 100644 (file)
index 0000000..668f711
--- /dev/null
@@ -0,0 +1,105 @@
+<?xml version='1.1' encoding='UTF-8'?>
+<flow-definition plugin="workflow-job@2.35">
+  <actions>
+    <org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobAction plugin="pipeline-model-definition@1.3.9"/>
+    <org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobPropertyTrackerAction plugin="pipeline-model-definition@1.3.9">
+      <jobProperties/>
+      <triggers/>
+      <parameters/>
+      <options>
+        <string>skipDefaultCheckout</string>
+      </options>
+    </org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobPropertyTrackerAction>
+  </actions>
+  <description>ICN CI job</description>
+  <keepDependencies>false</keepDependencies>
+  <properties>
+    <org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
+      <triggers>
+        <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger plugin="gerrit-trigger@2.30.0">
+          <spec></spec>
+          <gerritProjects>
+            <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.GerritProject>
+              <compareType>PLAIN</compareType>
+              <pattern>icn</pattern>
+              <branches>
+                <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch>
+                  <compareType>ANT</compareType>
+                  <pattern>**</pattern>
+                </com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch>
+              </branches>
+              <disableStrictForbiddenFileVerification>false</disableStrictForbiddenFileVerification>
+            </com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.GerritProject>
+          </gerritProjects>
+          <dynamicGerritProjects class="empty-list"/>
+          <skipVote>
+            <onSuccessful>false</onSuccessful>
+            <onFailed>false</onFailed>
+            <onUnstable>false</onUnstable>
+            <onNotBuilt>false</onNotBuilt>
+          </skipVote>
+          <gerritBuildSuccessfulVerifiedValue>0</gerritBuildSuccessfulVerifiedValue>
+          <gerritBuildSuccessfulCodeReviewValue>1</gerritBuildSuccessfulCodeReviewValue>
+          <gerritBuildFailedVerifiedValue>0</gerritBuildFailedVerifiedValue>
+          <gerritBuildFailedCodeReviewValue>-1</gerritBuildFailedCodeReviewValue>
+          <gerritBuildUnstableVerifiedValue>0</gerritBuildUnstableVerifiedValue>
+          <gerritBuildUnstableCodeReviewValue>-1</gerritBuildUnstableCodeReviewValue>
+          <silentMode>false</silentMode>
+          <notificationLevel></notificationLevel>
+          <silentStartMode>false</silentStartMode>
+          <escapeQuotes>true</escapeQuotes>
+          <nameAndEmailParameterMode>PLAIN</nameAndEmailParameterMode>
+          <dependencyJobsNames></dependencyJobsNames>
+          <commitMessageParameterMode>BASE64</commitMessageParameterMode>
+          <changeSubjectParameterMode>PLAIN</changeSubjectParameterMode>
+          <commentTextParameterMode>BASE64</commentTextParameterMode>
+          <buildStartMessage></buildStartMessage>
+          <buildFailureMessage>ci failed</buildFailureMessage>
+          <buildSuccessfulMessage>ci pass</buildSuccessfulMessage>
+          <buildUnstableMessage></buildUnstableMessage>
+          <buildNotBuiltMessage></buildNotBuiltMessage>
+          <buildUnsuccessfulFilepath></buildUnsuccessfulFilepath>
+          <customUrl></customUrl>
+          <serverName>gerrit.akraino.org</serverName>
+          <triggerOnEvents>
+            <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginPatchsetCreatedEvent>
+              <excludeDrafts>false</excludeDrafts>
+              <excludeTrivialRebase>false</excludeTrivialRebase>
+              <excludeNoCodeChange>false</excludeNoCodeChange>
+              <excludePrivateState>false</excludePrivateState>
+              <excludeWipState>false</excludeWipState>
+            </com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginPatchsetCreatedEvent>
+          </triggerOnEvents>
+          <dynamicTriggerConfiguration>false</dynamicTriggerConfiguration>
+          <triggerConfigURL></triggerConfigURL>
+          <triggerInformationAction/>
+        </com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger>
+      </triggers>
+    </org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
+  </properties>
+  <definition class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition" plugin="workflow-cps@2.74">
+    <scm class="hudson.plugins.git.GitSCM" plugin="git@3.12.1">
+      <configVersion>2</configVersion>
+      <userRemoteConfigs>
+        <hudson.plugins.git.UserRemoteConfig>
+          <name>origin</name>
+          <url>https://gerrit.akraino.org/r/icn.git</url>
+        </hudson.plugins.git.UserRemoteConfig>
+      </userRemoteConfigs>
+      <branches>
+        <hudson.plugins.git.BranchSpec>
+          <name>origin/${GERRIT_BRANCH}</name>
+        </hudson.plugins.git.BranchSpec>
+      </branches>
+      <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
+      <submoduleCfg class="list"/>
+      <extensions>
+        <hudson.plugins.git.extensions.impl.CleanBeforeCheckout/>
+      </extensions>
+    </scm>
+    <scriptPath>Jenkinsfile</scriptPath>
+    <lightweight>true</lightweight>
+  </definition>
+  <triggers/>
+  <disabled>false</disabled>
+</flow-definition>
\ No newline at end of file
diff --git a/ci/setup_jenkins.sh b/ci/setup_jenkins.sh
new file mode 100755 (executable)
index 0000000..dfb523e
--- /dev/null
@@ -0,0 +1,4 @@
+export DEBIAN_FRONTEND=noninteractive
+apt update
+apt install -y ansible
+ansible-galaxy install geerlingguy.jenkins,3.7.0 --roles-path /etc/ansible/roles
diff --git a/ci/site_jenkins.yaml b/ci/site_jenkins.yaml
new file mode 100644 (file)
index 0000000..1510fc8
--- /dev/null
@@ -0,0 +1,89 @@
+- hosts: localhost
+  vars:
+    jenkins_hostname: "{{ ansible_default_ipv4.address }}"
+    jenkins_version: 2.192
+    jenkins_plugin_timeout: 360
+    jenkins_plugins:
+      - gerrit-trigger
+      - workflow-aggregator
+      - git
+  roles:
+    - role: geerlingguy.java
+      become: yes
+    - role: geerlingguy.jenkins
+      become: yes
+  tasks:
+    - name: restart jenkins to use new installed plugins
+      meta: flush_handlers
+
+    - name: Wait for Jenkins to start up before proceeding.
+      command: >
+        curl -D - --silent --max-time 5 http://{{ jenkins_hostname }}:{{ jenkins_http_port }}{{ jenkins_url_prefix }}/cli/
+      args:
+        warn: false
+      register: result
+      until: >
+        (result.stdout.find("403 Forbidden") != -1)
+        or (result.stdout.find("200 OK") != -1)
+        and (result.stdout.find("Please wait while") == -1)
+      retries: "{{ jenkins_connection_retries | default(60) }}"
+      delay: "{{ jenkins_connection_delay | default(5) }}"
+      changed_when: false
+      check_mode: false
+
+    - name: create directory /var/lib/jenkins/.ssh
+      file:
+        path: /var/lib/jenkins/.ssh
+        owner: jenkins
+        group: jenkins
+        state: directory
+
+    - name: place gerrit ssh key
+      copy:
+        src: "{{ gerrit_key_path | default('gerrit.key') }}"
+        dest: /var/lib/jenkins/.ssh/gerrit.key
+        owner: jenkins
+        group: jenkins
+        mode: '0600'
+      tags: [gerrit]
+
+    - name: grant jenkins user sudo
+      copy:
+        content: "jenkins        ALL=(ALL)       NOPASSWD: ALL"
+        dest: /etc/sudoers.d/jenkins
+        owner: root
+        group: root
+        mode: '0660'
+      tags: [gerrit]
+
+    - name: add gerrit server
+      jenkins_script:
+        script: "{{lookup('file', 'gerrit.groovy')}}"
+        url: "http://{{ jenkins_hostname }}:{{ jenkins_http_port }}{{ jenkins_url_prefix }}"
+        user: "{{ jenkins_admin_username }}"
+        password: "{{ jenkins_admin_password }}"
+        validate_certs: no
+      register: result
+      failed_when: "'Result: success\n' != result.output"
+      tags: [gerrit]
+
+    - name: Install python-pip
+      apt:
+        name: python-pip
+      tags: [jobs]
+
+    - name: Install python-jenkins and lxml(required by jenkins_job module)
+      pip:
+        name:
+          - python-jenkins
+          - lxml
+      tags: [jobs]
+
+    - name: Add pipeline job for ICN CI
+      jenkins_job:
+        name: icn_check
+        config: "{{lookup('file', 'icn_check.xml')}}"
+        url: "http://{{ jenkins_hostname }}:{{ jenkins_http_port }}{{ jenkins_url_prefix }}"
+        user: "{{ jenkins_admin_username }}"
+        password: "{{ jenkins_admin_password }}"
+      tags: [jobs]
diff --git a/deploy/kud-plugin-addons/minio/install.sh b/deploy/kud-plugin-addons/minio/install.sh
new file mode 100755 (executable)
index 0000000..f1a61ea
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+# Make sure 64GB+ free space.
+
+echo "s"|sudo -S mkdir /mnt/minio
+
+# Create local-storage persistent volume first since not support dynamic provisioning.
+kubectl create -f local-pv.yaml
+
+# Create storage class for local-storage
+kubectl create -f local-sc.yaml
+
+# Create persistent volume claim for minio server
+kubectl create -f local-pvc.yaml
+
+# Create deployment of MinIO server
+kubectl create -f minio-deployment.yaml
+
+# Create service for MinIO
+kubectl create -f minio-service.yaml
+
diff --git a/deploy/kud-plugin-addons/minio/local-pv.yaml b/deploy/kud-plugin-addons/minio/local-pv.yaml
new file mode 100644 (file)
index 0000000..d273a0f
--- /dev/null
@@ -0,0 +1,23 @@
+apiVersion: v1
+kind: PersistentVolume
+metadata:
+  name: minio-pv
+spec:
+  capacity:
+    storage: 64Gi
+  volumeMode: Filesystem
+  accessModes:
+  - ReadWriteOnce
+  persistentVolumeReclaimPolicy: Delete
+  storageClassName: local-storage
+  local:
+    path: /mnt/minio
+  nodeAffinity:
+    required:
+      nodeSelectorTerms:
+      - matchExpressions:
+        - key: kubernetes.io/os
+          operator: In
+          values:
+          - linux
+
diff --git a/deploy/kud-plugin-addons/minio/local-pvc.yaml b/deploy/kud-plugin-addons/minio/local-pvc.yaml
new file mode 100644 (file)
index 0000000..923dd61
--- /dev/null
@@ -0,0 +1,12 @@
+kind: PersistentVolumeClaim
+apiVersion: v1
+metadata:
+  name: minio-local-claim
+spec:
+  accessModes:
+  - ReadWriteOnce
+  resources:
+    requests:
+      storage: 64Gi
+  storageClassName: local-storage
+
diff --git a/deploy/kud-plugin-addons/minio/local-sc.yaml b/deploy/kud-plugin-addons/minio/local-sc.yaml
new file mode 100644 (file)
index 0000000..b442e77
--- /dev/null
@@ -0,0 +1,7 @@
+kind: StorageClass
+apiVersion: storage.k8s.io/v1
+metadata:
+  name: local-storage
+provisioner: kubernetes.io/no-provisioner
+volumeBindingMode: WaitForFirstConsumer
+
diff --git a/deploy/kud-plugin-addons/minio/minio-deployment.yaml b/deploy/kud-plugin-addons/minio/minio-deployment.yaml
new file mode 100644 (file)
index 0000000..373ba55
--- /dev/null
@@ -0,0 +1,44 @@
+apiVersion: apps/v1 #  for k8s versions before 1.9.0 use apps/v1beta2  and before 1.8.0 use extensions/v1beta1
+kind: Deployment
+metadata:
+  # This name uniquely identifies the Deployment
+  name: minio-deployment
+spec:
+  selector:
+    matchLabels:
+      app: minio
+  strategy:
+    type: Recreate
+  template:
+    metadata:
+      labels:
+        # Label is used as selector in the service.
+        app: minio
+    spec:
+      # Refer to the PVC created earlier
+      volumes:
+      - name: storage
+        persistentVolumeClaim:
+          # Name of the PVC created earlier
+          claimName: minio-local-claim
+      containers:
+      - name: minio
+        # Pulls the default Minio image from Docker Hub
+        image: minio/minio:latest
+        args:
+        - server
+        - /storage
+        env:
+        # Minio access key and secret key
+        - name: MINIO_ACCESS_KEY
+          value: "ICN-ACCESSKEYID"
+        - name: MINIO_SECRET_KEY
+          value: "ICN-SECRETACCESSKEY"
+        ports:
+        - containerPort: 9000
+          hostPort: 9000
+        # Mount the volume into the pod
+        volumeMounts:
+        - name: storage # must match the volume name, above
+          mountPath: "/storage"
+
diff --git a/deploy/kud-plugin-addons/minio/minio-service.yaml b/deploy/kud-plugin-addons/minio/minio-service.yaml
new file mode 100644 (file)
index 0000000..766a1a2
--- /dev/null
@@ -0,0 +1,13 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: minio-service
+spec:
+  type: LoadBalancer
+  ports:
+    - port: 9000
+      targetPort: 9000
+      protocol: TCP
+  selector:
+    app: minio
+