create moon jenkins 95/50495/1
authorRHE <rebirthmonkey@gmail.com>
Fri, 12 Jan 2018 13:56:14 +0000 (14:56 +0100)
committerRHE <rebirthmonkey@gmail.com>
Fri, 12 Jan 2018 13:56:14 +0000 (14:56 +0100)
Change-Id: I10cac28f45fca917a0a841e1113a9ffb31369f15
Signed-off-by: RHE <rebirthmonkey@gmail.com>
14 files changed:
tests/functional/run_tests.sh [new file with mode: 0644]
tests/python_unit/run_tests.sh
tools/jenkins/README.md [deleted file]
tools/moon_jenkins/Dockerfile [new file with mode: 0644]
tools/moon_jenkins/Jenkinsfile [new file with mode: 0644]
tools/moon_jenkins/README.md [new file with mode: 0644]
tools/moon_jenkins/docker-compose.yml [new file with mode: 0644]
tools/moon_jenkins/images/Create Multibranch Pipeline.png [new file with mode: 0644]
tools/moon_jenkins/images/Git Source Multibranch Pipeline.png [new file with mode: 0644]
tools/moon_jenkins/images/Multibranch Pipeline Log.png [new file with mode: 0644]
tools/moon_jenkins/images/Select Source Multibranch Pipeline.png [new file with mode: 0644]
tools/moon_jenkins/plugins.txt [new file with mode: 0644]
tools/moon_jenkins/security.groovy [new file with mode: 0644]
tools/moon_jenkins/setenv.groovy [new file with mode: 0644]

diff --git a/tests/functional/run_tests.sh b/tests/functional/run_tests.sh
new file mode 100644 (file)
index 0000000..ced0f9f
--- /dev/null
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+echo "starting Moon Functional Tests"
index 86a5e06..33c1ab9 100644 (file)
@@ -1,4 +1,12 @@
 #!/usr/bin/env bash
 
-cd ${MOON_HOME}/python_moonclient
+echo "starting Moon Functional Tests"
+
+cd python_moonutilities
+docker run --rm --volume $(pwd):/data wukongsun/moon_python_unit_test:latest
+
+cd ../python_moondb
+docker run --rm --volume $(pwd):/data wukongsun/moon_python_unit_test:latest
+
+cd ../python_moonclient
 docker run --rm --volume $(pwd):/data wukongsun/moon_python_unit_test:latest
\ No newline at end of file
diff --git a/tools/jenkins/README.md b/tools/jenkins/README.md
deleted file mode 100644 (file)
index 8b13789..0000000
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/tools/moon_jenkins/Dockerfile b/tools/moon_jenkins/Dockerfile
new file mode 100644 (file)
index 0000000..573d4ac
--- /dev/null
@@ -0,0 +1,9 @@
+FROM jenkinsci/blueocean
+
+ENV JAVA_OPTS="-Djenkins.install.runSetupWizard=false"
+
+COPY security.groovy /usr/share/jenkins/ref/init.groovy.d/security.groovy
+COPY setenv.groovy /usr/share/jenkins/ref/init.groovy.d/setenv.groovy
+
+COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
+RUN /usr/local/bin/install-plugins.sh < /usr/share/jenkins/ref/plugins.txt
\ No newline at end of file
diff --git a/tools/moon_jenkins/Jenkinsfile b/tools/moon_jenkins/Jenkinsfile
new file mode 100644 (file)
index 0000000..7e0e07c
--- /dev/null
@@ -0,0 +1,24 @@
+pipeline {
+  agent {
+    docker {
+      image 'wukongsun/moon_python_unit_test'
+      args '-e moon_home=${moon_home}'
+    }
+  }
+  stages {
+    stage('Python Unit Test') {
+      steps {
+        script {
+          sh("cd ${moon_home}/tests/python_unit")
+          sh("bash run_tests")
+        }
+      }
+    }
+    stage('Functional Test') {
+      script {
+          sh("cd ${moon_home}/tests/functional")
+          sh("bash run_tests")
+      }
+    }
+  }
+}
\ No newline at end of file
diff --git a/tools/moon_jenkins/README.md b/tools/moon_jenkins/README.md
new file mode 100644 (file)
index 0000000..684b351
--- /dev/null
@@ -0,0 +1,37 @@
+# Moon Jenkins
+The aim of this repo is to give a quick way to start with jenkins in containers.
+These were the aims of the automation:
+- minimal interaction with Jenkins GUI - the plugins in plugins.txt are installed automatically, the admin user is setup based on environment variables, proxy variables are inherited from environment
+- the build of the custom image is integrated in the same workflow
+
+## Prerequisites
+- one host running a newer version of the docker-engine
+- docker-compose 1.18.0 
+
+## Usage
+- Setup secrets:
+```bash
+export JENKINS_USER=admin
+export JENKINS_PASSWORD=admin
+```
+- Deploy jenkins:
+```bash
+docker-compose up -d
+ ```
+- Test: Jenkins GUI can be available on `http://<docker host IP>:8080`
+
+
+## Pipeline Creation
+You may find bellow an example of pipeline creation using BlueOcean interface.
+As example I used a clone (https://github.com/brutus333/moon.git) of the moon project (https://git.opnfv.org/moon/)
+
+Click on "Create a new job" in the classical Jenkins UI and follow the steps highlighted bellow:
+
+![Create Multibranch Pipeline](images/Create%20Multibranch%20Pipeline.png)
+![Select Source](images/Select%20Source%20Multibranch%20Pipeline.png)
+![Configure Source](images/Git%20Source%20Multibranch%20Pipeline.png)
+![Multibranch Pipeline Log](images/Multibranch%20Pipeline%20Log.png)
+
+Clicking on BlueOcean shows the pipeline in the blueocean interface:
+
+![Blue Ocean Pipeline success](images/blue%20ocean%20success%20pipeline.png)
diff --git a/tools/moon_jenkins/docker-compose.yml b/tools/moon_jenkins/docker-compose.yml
new file mode 100644 (file)
index 0000000..2329f7b
--- /dev/null
@@ -0,0 +1,22 @@
+version: '3.1'
+
+services:
+
+  jenkins:
+    build:
+      context: .
+      args:
+    image: blueocean:v0.3
+    ports:
+      - 8080:8080
+      - 50000:50000
+    environment:
+      - jenkins_user=${JENKINS_USER}
+      - jenkins_password=${JENKINS_PASSWORD}
+    volumes:
+      - jenkins-data:/var/jenkins_home
+      - /var/run/docker.sock:/var/run/docker.sock
+    user: root
+
+volumes:
+  jenkins-data:
diff --git a/tools/moon_jenkins/images/Create Multibranch Pipeline.png b/tools/moon_jenkins/images/Create Multibranch Pipeline.png
new file mode 100644 (file)
index 0000000..c71415c
Binary files /dev/null and b/tools/moon_jenkins/images/Create Multibranch Pipeline.png differ
diff --git a/tools/moon_jenkins/images/Git Source Multibranch Pipeline.png b/tools/moon_jenkins/images/Git Source Multibranch Pipeline.png
new file mode 100644 (file)
index 0000000..dd37f21
Binary files /dev/null and b/tools/moon_jenkins/images/Git Source Multibranch Pipeline.png differ
diff --git a/tools/moon_jenkins/images/Multibranch Pipeline Log.png b/tools/moon_jenkins/images/Multibranch Pipeline Log.png
new file mode 100644 (file)
index 0000000..a190593
Binary files /dev/null and b/tools/moon_jenkins/images/Multibranch Pipeline Log.png differ
diff --git a/tools/moon_jenkins/images/Select Source Multibranch Pipeline.png b/tools/moon_jenkins/images/Select Source Multibranch Pipeline.png
new file mode 100644 (file)
index 0000000..eadbe91
Binary files /dev/null and b/tools/moon_jenkins/images/Select Source Multibranch Pipeline.png differ
diff --git a/tools/moon_jenkins/plugins.txt b/tools/moon_jenkins/plugins.txt
new file mode 100644 (file)
index 0000000..2463d02
--- /dev/null
@@ -0,0 +1,100 @@
+ssh-credentials
+git
+blueocean-dashboard
+pipeline-model-api
+pipeline-graph-analysis
+workflow-support
+display-url-api
+blueocean-config
+workflow-cps
+branch-api
+blueocean-i18n
+workflow-job
+blueocean-bitbucket-pipeline
+favorite
+docker-commons
+pipeline-input-step
+blueocean-pipeline-api-impl
+workflow-api
+jackson2-api
+git-client
+blueocean-pipeline-scm-api
+blueocean
+pipeline-build-step
+jquery-detached
+matrix-project
+antisamy-markup-formatter
+pipeline-model-extensions
+docker-workflow
+github
+git-server
+authentication-tokens
+workflow-cps-global-lib
+pipeline-model-definition
+workflow-scm-step
+pipeline-model-declarative-agent
+cloudbees-bitbucket-branch-source
+script-security
+scm-api
+blueocean-rest
+variant
+sse-gateway
+htmlpublisher
+matrix-auth
+pubsub-light
+blueocean-github-pipeline
+token-macro
+credentials
+mercurial
+plain-credentials
+blueocean-events
+github-api
+blueocean-git-pipeline
+structs
+durable-task
+pipeline-milestone-step
+blueocean-pipeline-editor
+blueocean-web
+pipeline-stage-tags-metadata
+ace-editor
+blueocean-commons
+blueocean-jira
+blueocean-rest-impl
+workflow-step-api
+blueocean-personalization
+workflow-basic-steps
+blueocean-display-url
+jira
+pipeline-stage-step
+jsch
+blueocean-jwt
+cloudbees-folder
+credentials-binding
+github-branch-source
+apache-httpcomponents-client-4-api
+blueocean-autofavorite
+workflow-multibranch
+mailer
+workflow-durable-task-step
+junit
+command-launcher
+bouncycastle-api
+build-timeout
+timestamper
+resource-disposer
+ws-cleanup
+ant
+gradle
+pipeline-rest-api
+handlebars
+momentjs
+pipeline-stage-view
+workflow-aggregator
+pipeline-github-lib
+mapdb-api
+subversion
+ssh-slaves
+pam-auth
+ldap
+email-ext
+locale
diff --git a/tools/moon_jenkins/security.groovy b/tools/moon_jenkins/security.groovy
new file mode 100644 (file)
index 0000000..0fb5ff6
--- /dev/null
@@ -0,0 +1,20 @@
+#!groovy
+
+import jenkins.model.*
+import hudson.security.*
+
+def instance = Jenkins.getInstance()
+
+def user = System.getenv()['jenkins_user']
+def pass = System.getenv()['jenkins_password']
+// Create user account
+def hudsonRealm = new HudsonPrivateSecurityRealm(false)
+hudsonRealm.createAccount(user,pass)
+instance.setSecurityRealm(hudsonRealm)
+
+// Enable matrix auth strategy and set my_user as admin
+def strategy = new GlobalMatrixAuthorizationStrategy()
+strategy.add(Jenkins.ADMINISTER, user)
+instance.setAuthorizationStrategy(strategy)
+
+instance.save()
diff --git a/tools/moon_jenkins/setenv.groovy b/tools/moon_jenkins/setenv.groovy
new file mode 100644 (file)
index 0000000..ab2dc13
--- /dev/null
@@ -0,0 +1,34 @@
+#!groovy
+
+import jenkins.*
+import jenkins.model.*
+import hudson.*
+import hudson.model.*
+
+instance = Jenkins.getInstance()
+globalNodeProperties = instance.getGlobalNodeProperties()
+
+envVarsNodePropertyList = globalNodeProperties.getAll(hudson.slaves.EnvironmentVariablesNodeProperty.class)
+
+newEnvVarsNodeProperty = null
+envVars = null
+
+if (envVarsNodePropertyList == null || envVarsNodePropertyList.size() == 0) {
+    newEnvVarsNodeProperty = new hudson.slaves.EnvironmentVariablesNodeProperty();
+    globalNodeProperties.add(newEnvVarsNodeProperty)
+    envVars = newEnvVarsNodeProperty.getEnvVars()
+} else {
+    envVars = envVarsNodePropertyList.get(0).getEnvVars()
+}
+
+http_proxy = System.getenv()['http_proxy']
+https_proxy = System.getenv()['https_proxy']
+
+if (http_proxy) {
+  envVars.put("http_proxy", System.getenv()['http_proxy'])
+}
+if (https_proxy) {
+  envVars.put("https_proxy", System.getenv()['https_proxy'])
+}
+
+instance.save()