aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRHE <rebirthmonkey@gmail.com>2018-01-12 14:56:14 +0100
committerRHE <rebirthmonkey@gmail.com>2018-01-12 14:56:14 +0100
commit5d325dfc5d666b345b6555ea9dc4ab3af853be67 (patch)
tree7888aab723b8d127666302f65ad5b5df6f9f92d1
parentdf9333a89b3d38a5421bc86fae4e0bba9280b21b (diff)
create moon jenkins
Change-Id: I10cac28f45fca917a0a841e1113a9ffb31369f15 Signed-off-by: RHE <rebirthmonkey@gmail.com>
-rw-r--r--tests/functional/run_tests.sh3
-rw-r--r--tests/python_unit/run_tests.sh10
-rw-r--r--tools/jenkins/README.md1
-rw-r--r--tools/moon_jenkins/Dockerfile9
-rw-r--r--tools/moon_jenkins/Jenkinsfile24
-rw-r--r--tools/moon_jenkins/README.md37
-rw-r--r--tools/moon_jenkins/docker-compose.yml22
-rw-r--r--tools/moon_jenkins/images/Create Multibranch Pipeline.pngbin0 -> 55639 bytes
-rw-r--r--tools/moon_jenkins/images/Git Source Multibranch Pipeline.pngbin0 -> 31054 bytes
-rw-r--r--tools/moon_jenkins/images/Multibranch Pipeline Log.pngbin0 -> 55231 bytes
-rw-r--r--tools/moon_jenkins/images/Select Source Multibranch Pipeline.pngbin0 -> 23375 bytes
-rw-r--r--tools/moon_jenkins/plugins.txt100
-rw-r--r--tools/moon_jenkins/security.groovy20
-rw-r--r--tools/moon_jenkins/setenv.groovy34
14 files changed, 258 insertions, 2 deletions
diff --git a/tests/functional/run_tests.sh b/tests/functional/run_tests.sh
new file mode 100644
index 00000000..ced0f9f7
--- /dev/null
+++ b/tests/functional/run_tests.sh
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+echo "starting Moon Functional Tests"
diff --git a/tests/python_unit/run_tests.sh b/tests/python_unit/run_tests.sh
index 86a5e06a..33c1ab98 100644
--- a/tests/python_unit/run_tests.sh
+++ b/tests/python_unit/run_tests.sh
@@ -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
index 8b137891..00000000
--- a/tools/jenkins/README.md
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/tools/moon_jenkins/Dockerfile b/tools/moon_jenkins/Dockerfile
new file mode 100644
index 00000000..573d4ac8
--- /dev/null
+++ b/tools/moon_jenkins/Dockerfile
@@ -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
index 00000000..7e0e07c0
--- /dev/null
+++ b/tools/moon_jenkins/Jenkinsfile
@@ -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
index 00000000..684b351c
--- /dev/null
+++ b/tools/moon_jenkins/README.md
@@ -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
index 00000000..2329f7bd
--- /dev/null
+++ b/tools/moon_jenkins/docker-compose.yml
@@ -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
index 00000000..c71415c0
--- /dev/null
+++ b/tools/moon_jenkins/images/Create Multibranch Pipeline.png
Binary files 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
index 00000000..dd37f217
--- /dev/null
+++ b/tools/moon_jenkins/images/Git Source Multibranch Pipeline.png
Binary files 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
index 00000000..a1905934
--- /dev/null
+++ b/tools/moon_jenkins/images/Multibranch Pipeline Log.png
Binary files 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
index 00000000..eadbe916
--- /dev/null
+++ b/tools/moon_jenkins/images/Select Source Multibranch Pipeline.png
Binary files differ
diff --git a/tools/moon_jenkins/plugins.txt b/tools/moon_jenkins/plugins.txt
new file mode 100644
index 00000000..2463d029
--- /dev/null
+++ b/tools/moon_jenkins/plugins.txt
@@ -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
index 00000000..0fb5ff6e
--- /dev/null
+++ b/tools/moon_jenkins/security.groovy
@@ -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
index 00000000..ab2dc137
--- /dev/null
+++ b/tools/moon_jenkins/setenv.groovy
@@ -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()