Virtual Development Server: Provide Docker images in docker registry for Oracle via Jenkins

Posted by Torsten Kleiber on December 07, 2016
Tags: Blue-Ocean Continous-Integration Docker Infrastructure-as-Code Jenkins Pipeline Vagrant Virtual-Development-Server VirtualBox

We now try to automate the build of all needed images as soon as Oracle GitHub Sources changed or we need to build our Vagrant VirtualBox again from scratch.

After we have already installed Jenkins we now install first some needed plugins.

  1. We select explicit plugins at Jenkins Configuration

    Virtual Development Server Install Jenkins for Continuos Integration Delivery Deployment   jenkins select plugins
  2. Pipeline and Pipeline Stage View

    Virtual Development Server Install Jenkins for Continuos Integration Delivery Deployment   jenkins pipeline plugins
  3. Git

    Virtual Development Server Install Jenkins for Continuos Integration Delivery Deployment   jenkins git plugin
  4. SSH Slaves

    Virtual Development Server Install Jenkins for Continuos Integration Delivery Deployment   jenkins ssh slaves plugin
  5. and wait for the install process

    Virtual Development Server Install Jenkins for Continuos Integration Delivery Deployment   jenkins plugin install progress
  6. Later we add Blue Ocean Beta via "Manage Jenkins" > "Manage Plugins"

    Virtual Development Server Install Jenkins for Continuos Integration Delivery Deployment   jenkins blue ocean plugin
  7. After all is installed we restart Jenkins

    Virtual Development Server Install Jenkins for Continuos Integration Delivery Deployment   jenkins blue ocean plugin progress

After that we create our Jenkins pipeline via "New Item".

  1. We give it a name and select pipeline.

    Virtual Development Server Install Jenkins for Continuos Integration Delivery Deployment   jenkins create pipeline
  2. As we do not own the git repository and cannot create a hook there, we create a simple scm poll schedule.

    Virtual Development Server Install Jenkins for Continuos Integration Delivery Deployment   jenkins build oracle images build trigger
  3. Then we add our pipeline script.

    Virtual Development Server Install Jenkins for Continuos Integration Delivery Deployment   jenkins build oracle images pipeline

Here is the script for the moment, later after we have it successfully tested and implemented all builds of images we need, we will put it in it’s own git repository and call it from there. The script is written in Pipeline Model Definition, a config-like syntax for defining Pipelines.

pipeline {
 agent label:'localhost_vagrant'
 stages {
  // Get the actual docker images sourcse from oracle git account
  stage('Get Sources') {
   steps {
    git url: 'https://github.com/oracle/docker-images.git'
   }
  }
  stage('Build Oracle Docker Images') {
   steps {
    parallel (
     "Database XE 11.2.0.2" : {
      dir('OracleDatabase/dockerfiles') {
       // provide the downloaded source (via your oracle account) from the host
       sh 'if [ ! -f 11.2.0.2/oracle-xe-11.2.0-1.0.x86_64.rpm.zip ]; then cp /software/Oracle/Database/oracle-xe-11.2.0-1.0.x86_64.rpm.zip 11.2.0.2/oracle-xe-11.2.0-1.0.x86_64.rpm.zip; fi'
       // build the image
       sh 'sudo ./buildDockerImage.sh  -v 11.2.0.2 -x'
       // prepare the image for push to the local registry
       sh 'docker tag oracle/database:11.2.0.2-xe localhost:5000/oracle/database:11.2.0.2-xe'
       // push to the local registry
       sh 'docker push localhost:5000/oracle/database:11.2.0.2-xe'
      }
     },
     "WebLogic 12.2.1.2" : {
     // server-jre is required for Weblogic
      dir('OracleJava/java-8') {
       // provide the downloaded source (via your oracle account) from the host
       sh 'if [ ! -f server-jre-8u111-linux-x64.tar.gz ]; then cp /software/Oracle/Java/server-jre-8u111-linux-x64.tar.gz server-jre-8u111-linux-x64.tar.gz; fi'
       // build the image
       sh 'sudo ./build.sh'
       // prepare the image for push to the local registry
       sh 'docker tag oracle/serverjre:8 localhost:5000/oracle/serverjre:8'
       // push to the local registry
       sh 'docker push localhost:5000/oracle/serverjre:8'
      }
      dir('OracleWebLogic/dockerfiles') {
       // provide the downloaded source (via your oracle account) from the host
       sh 'if [ ! -f 12.2.1.2/fmw_12.2.1.2.0_wls_Disk1_1of1.zip ]; then cp /software/Oracle/WebLogic/fmw_12.2.1.2.0_wls_Disk1_1of1.zip 12.2.1.2/fmw_12.2.1.2.0_wls_Disk1_1of1.zip; fi'
       // build the image
       sh 'sudo ./buildDockerImage.sh -v 12.2.1.2 -g'
       // prepare the image for push to the local registry
       sh 'docker tag oracle/weblogic:12.2.1.2-generic localhost:5000/oracle/weblogic:12.2.1.2-generic'
       // push to the local registry
       sh 'docker push localhost:5000/oracle/weblogic:12.2.1.2-generic'
      }
     }
    )
   }
  }
  stage('Cleanup') {
   steps {
    // clean virtualbox
    sh 'docker rmi --force localhost:5000/oracle/database:11.2.0.2-xe'
    sh 'docker rmi --force oracle/database:11.2.0.2-xe'
    sh 'docker rmi --force localhost:5000/oracle/weblogic:12.2.1.2-generic'
    sh 'docker rmi --force oracle/weblogic:12.2.1.2-generic'
    sh 'docker rmi --force localhost:5000/oracle/serverjre:8'
    sh 'docker rmi --force oracle/serverjre:8'
   }
  }
 }
}

We can wait now the 15 min poll time or start the job manually.

After an "vagrant halt / vagrant up" you can control in your browser, that the created images are persistent in the local docker registry:

Virtual Development Server Install Jenkins for Continuos Integration Delivery Deployment   docker registry persistent

Here you find the source code for this blog.

Here you find more about the topic "Virtual Development Server".

That’s it.