Giter Site home page Giter Site logo

custom-jenkins's Introduction

custom-jenkins

Repository that explains how to create a custom jenkins image for Openshift (3.4) using Docker Build, S2I and Persistent volumes
OpenShift Jenkins Image Repository: https://github.com/openshift/jenkins

Dockerfile

Using Jenkins Template provided by OpenShift

Jenkins is customisable using docker build (example in the directory Dockerfile). To do that, do the following steps:

  1. Create a Dockerfile that extends the original openshift3/jenkins-2-rhel7
FROM openshift/jenkins-2-rhel7
COPY plugins.txt /opt/openshift/configuration/plugins.txt
RUN /usr/local/bin/install-plugins.sh /opt/openshift/configuration/plugins.txt
  1. Build the image using the Dockerfile above
docker build -t docker.io/clrxm/custom-jenkins:latest .
  1. Push the image in a docker registry
docker push docker.io/clrxm/custom-jenkins:latest
  1. In OpenShift, create a new project
oc new-project custom-jenkins --display-name="Dockerfile Jenkins" --description="Demonstrate custom jenkins image with docker build"
  1. Create an imageStream with your image (This will import all the tags).
oc import-image custom-jenkins --from=docker.io/clrxm/custom-jenkins --confirm --all

You can repeat this command to import new tags 6. Deploy Jenkins using the OpenShift jenkins template

oc new-app jenkins-ephemeral -p NAMESPACE=custom-jenkins -p JENKINS_IMAGE_STREAM_TAG=custom-jenkins:latest

As it is shown in the section "Latest Openshift Jenkins Image" you can directly build your docker image in Openshift if your dockerfile is available in a git repository.

oc new-build https://github.com/clerixmaxime/custom-jenkins.git \
   --context-dir=/Dockerfile --strategy=docker

Using custom template

  1. Repeat steps 1, 2, & 3 above.
  2. In OpenShift, create a new project
oc new-project custom-jenkins --display-name="Dockerfile Jenkins" --description="Demonstrate custom jenkins image with docker build"
  1. Import the custom template under directory Dockerfile
oc create -f https://raw.githubusercontent.com/clerixmaxime/custom-jenkins/Dockerfile/jenkins-docker-image-template.yml
  1. Deploy Jenkins. You have to specify the JENKINS_IMAGE to use as environement variable
oc new-app jenkins-master-s2i -p JENKINS_IMAGE=docker.io/clrxm/custom-jenkins:latest

S2I

You can use the S2I feature of OpenShift to build new Custom Jenkins Images. In order to include your modifications in Jenkins image, you need to have a Git repository with following directory structure:

  • ./plugins folder that contains binary Jenkins plugins you want to copy into Jenkins
  • ./plugins.txt file that list the plugins you want to install (see the section above)
  • ./configuration/jobs folder that contains the Jenkins job definitions
  • ./configuration/config.xml file that contains your custom Jenkins configuration

Note that the ./configuration folder will be copied into /var/lib/jenkins folder, so you can also include additional files (like credentials.xml, etc.).

  1. Create a new project.
oc new-project custom-jenkins-s2i
  1. Build the new custom-jenkins image using S2I jenkins image provided by OpenShift.
oc new-build jenkins:2~https://github.com/clerixmaxime/custom-jenkins.git --context-dir=/s2i --name=custom-jenkins
  1. Deploy Jenkins using the OpenShift jenkins template
oc new-app jenkins-ephemeral \
     -p NAMESPACE=custom-jenkins-s2i  -p JENKINS_IMAGE_STREAM_TAG=custom-jenkins:latest

Latest Openshift Jenkins Image / Custom template

Building the last version of the openshift/jenkins image, an environment variable INSTALL_PLUGINS has been integrated that allows to provide a list of plugins. The image will install all these plugins at start up.

  1. Create a new project.
oc new-project custom-jenkins-image
  1. Get image in OpenShift
  • Build the image directly in Openshift (This will build the image from a Dockerfile locate on a Git repository and create the ImageStream associated)
oc new-build https://github.com/openshift/jenkins.git \
   --context-dir=/1 --strategy=docker
  • Import the image in Openshift as an ImageStream (The image has already been built and is available on my Docker Hub. Refer to ttps://github.com/openshift/jenkins to build the image on your own or retag my image and add it to your own registry)
oc import-image jenkins --from=docker.io/clrxm/jenkins-2-centos7 --confirm
  1. Download the template jenkins-ephemeral-latest.json under s2i
  2. Import the template
oc create -f jenkins-ephemeral-latest.json
  1. Deploy Jenkins using this template
oc new-app jenkins-ephemeral-latest -p NAMESPACE=custom-jenkins-image -p JENKINS_IMAGE_STREAM_TAG=jenkins:latest -p INSTALL_PLUGINS=blueocean:1.0.1

persistentVolumes

You can also create a custom-jenkins image by mounting a persistent volume with the required plugins.

  1. Create a Persistent Volume on OpenShift (Depends on your backing-storage solution)
  2. Copy the required files (/plugins directory) in the persistent volume

/!\ The /plugins directory must contain all plugin dependencies

  1. Create a new project.
oc new-project custom-jenkins-pv
  1. Deploy Jenkins using the OpenShift jenkins-persistent template
oc new-app jenkins-persistent

custom-jenkins's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.