From c93f8c03872bd1164d4799e0089d1d70dfef3b45 Mon Sep 17 00:00:00 2001 From: Eric Sauer Date: Thu, 3 Aug 2017 21:37:40 -0500 Subject: [PATCH] Migrate basic pipeline (#1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Adding pipeline templates and required dependencies to run it (#18) Adding pipeline templates and required dependencies to run it * Enhancement for non-priveleged users. Can specify arbitrary namespace… (#25) Enhancement for non-priveleged users. Can specify arbitrary namespace in which to do image builds * Switching over to oc apply for creating resources (#27) * Refactored basic pipeline example to be more declarative. New README. removed need to shell script. * Fixing syntax issues in README * Correcting tenses and spelling mistakes --- basic-tomcat/README.md | 152 ++++++++++++++++++ basic-tomcat/build/basic-java-template.yml | 102 ++++++++++++ basic-tomcat/build/dev/params | 2 + basic-tomcat/deploy/basic-tomcat-template.yml | 147 +++++++++++++++++ basic-tomcat/deploy/dev/params | 3 + basic-tomcat/deploy/prod/params | 3 + basic-tomcat/deploy/stage/params | 4 + basic-tomcat/pipeline.groovy | 131 +++++++++++++++ basic-tomcat/projects/projects.yml | 21 +++ jenkins-s2i/jenkins-s2i.yml | 62 +++++++ jenkins-s2i/plugins.txt | 1 + 11 files changed, 628 insertions(+) create mode 100644 basic-tomcat/README.md create mode 100644 basic-tomcat/build/basic-java-template.yml create mode 100644 basic-tomcat/build/dev/params create mode 100644 basic-tomcat/deploy/basic-tomcat-template.yml create mode 100644 basic-tomcat/deploy/dev/params create mode 100644 basic-tomcat/deploy/prod/params create mode 100644 basic-tomcat/deploy/stage/params create mode 100644 basic-tomcat/pipeline.groovy create mode 100644 basic-tomcat/projects/projects.yml create mode 100644 jenkins-s2i/jenkins-s2i.yml create mode 100644 jenkins-s2i/plugins.txt diff --git a/basic-tomcat/README.md b/basic-tomcat/README.md new file mode 100644 index 00000000..2869cf85 --- /dev/null +++ b/basic-tomcat/README.md @@ -0,0 +1,152 @@ +# A Sample OpenShift Pipeline + +This example demonstrates how to implement a full end-to-end Jenkins Pipeline for a Java application in OpenShift Container Platform. This sample demonstrates the following capabilities: + +* Deploying an integrated Jenkins server inside of OpenShift +* Running both custom and oob Jenkins slaves as pods in OpenShift +* "One Click" instantiation of a Jenkins Pipeline using OpenShift's Jenkins Pipeline Strategy feature +* Promotion of an application's container image within an OpenShift Cluster (using `oc tag`) +* Promotion of an application's container image to a separate OpenShift Cluster (using `skopeo`) + +## Quickstart + +Run the following commands to instantiate this example. + +``` +cd ./basic-tomcat +oc create -f projects/projects.yml +oc process openshift//jenkins-ephemeral | oc apply -f- -n basic-tomcat-dev +oc process -f deploy/basic-tomcat-template.yml --param-file=deploy/dev/params | oc apply -f- +oc process -f deploy/basic-tomcat-template.yml --param-file=deploy/stage/params | oc apply -f- +oc process -f deploy/basic-tomcat-template.yml --param-file=deploy/prod/params | oc apply -f- +oc process -f build/basic-java-template.yml --param-file build/dev/params | oc apply -f- +``` + +## Architecture + +### OpenShift Templates + +The components of this pipeline are divided into two templates. + +The first template, `build/basic-tomcat-template.yml` is what we are calling the "Build" template. It contains: + +* A `jenkinsPipelineStrategy` BuildConfig +* An `s2i` BuildConfig +* An ImageStream for the s2i build config to push to + +The build template contains a default source code repo for a java application compatible with this pipelines architecture (https://github.com/etsauer/ticket-monster). + +The second template, `deploy/basic-tomcat-template.yml` is the "Deploy" template. It contains: + +* A tomcat8 DeploymentConfig +* A Service definition +* A Route + +The idea behind the split between the templates is that I can deploy the build template only once (to my dev project) and that the pipeline will promote my image through all of the various stages of my application's lifecycle. The deployment template gets deployed once to each of the stages of the application lifecycle (once per OpenShift project). + +### Pipeline Script + +This project includes a sample `pipeline.groovy` Jenkins Pipeline script that could be included with a Java project in order to implement a basic CI/CD pipeline for that project, under the following assumptions: + +* The project is built with Maven +* The `pipeline.groovy` script is placed in the same directory as the `pom.xml` file in the git source. +* The OpenShift projects that represent the Application's lifecycle stages are of the naming format: `-dev`, `-stage`, `-prod`. + +For convenience, this pipeline script is already included in the following git repository, based on the [JBoss Developers Ticket Monster](https://github.com/jboss-developer/ticket-monster) app. + +https://github.com/etsauer/ticket-monster + +## Bill of Materials + +* One or Two OpenShift Container Platform Clusters + * OpenShift 3.5+ is required. +* Access to GitHub + +## Implementation Instructions + +### 1. Create Lifecycle Stages + +For the purposes of this demo, we are going to create three stages for our application to be promoted through. + +- `basic-tomcat-dev` +- `basic-tomcat-stage` +- `basic-tomcat-prod` + +In the spirit of _Infrastructure as Code_ we have a YAML file that defines the `ProjectRequests` for us. This is as an alternative to running `oc new-project`, but will yeild the same result. + +``` +$ oc create -f projects/projects.yml +projectrequest "basic-tomcat-dev" created +projectrequest "basic-tomcat-stage" created +projectrequest "basic-tomcat-prod" created +``` + +### 2. Stand up Jenkins master in dev + +For this step, the OpenShift default template set provides exactly what we need to get jenkins up and running. + +``` +$ oc process openshift//jenkins-ephemeral | oc apply -f- -n basic-tomcat-dev +route "jenkins" created +deploymentconfig "jenkins" created +serviceaccount "jenkins" created +rolebinding "jenkins_edit" created +service "jenkins-jnlp" created +service "jenkins" created +``` + +### 4. Instantiate Pipeline + +A _deploy template_ is provided at `deploy/basic-tomcat-template.yml` that defines all of the resources required to run our Tomcat application. It includes: + +* A `Service` +* A `Route` +* An `ImageStream` +* A `DeploymentConfig` +* A `RoleBinding` to allow Jenkins to deploy in each namespace. + +This template should be instantiated once in each of the namespaces that our app will be deployed to. For this purpose, we have created a param file to be fed to `oc process` to customize the template for each environment. + +Deploy the deployment template to all three projects. +``` +$ oc process -f deploy/basic-tomcat-template.yml --param-file=deploy/dev/params | oc apply -f- +service "basic-tomcat" created +route "basic-tomcat" created +imagestream "basic-tomcat" created +deploymentconfig "basic-tomcat" created +rolebinding "jenkins_edit" configured +$ oc process -f deploy/basic-tomcat-template.yml --param-file=deploy/stage/params | oc apply -f- +service "basic-tomcat" created +route "basic-tomcat" created +imagestream "basic-tomcat" created +deploymentconfig "basic-tomcat" created +rolebinding "jenkins_edit" created +$ oc process -f deploy/basic-tomcat-template.yml --param-file=deploy/prod/params | oc apply -f- +service "basic-tomcat" created +route "basic-tomcat" created +imagestream "basic-tomcat" created +deploymentconfig "basic-tomcat" created +rolebinding "jenkins_edit" created +``` + +A _build template_ is provided at `build/basic-java-template.yml` that defines all the resources required to build our java app. It includes: + +* A `BuildConfig` that defines a `JenkinsPipelineStrategy` build, which will be used to define out pipeline. +* A `BuildConfig` that defines a `Source` build with `Binary` input. This will build our image. + +Deploy the pipeline template in dev only. +``` +$ oc process -f build/basic-java-template.yml --param-file build/dev/params | oc apply -f- +buildconfig "basic-tomcat-pipeline" created +buildconfig "basic-tomcat" created +``` + +At this point you should be able to go to the Web Console and follow the pipeline by clicking in your `myapp-dev` project, and going to *Builds* -> *Pipelines*. At several points you will be prompted for input on the pipeline. You can interact with it by clicking on the _input required_ link, which takes you to Jenkins, where you can click the *Proceed* button. By the time you get through the end of the pipeline you should be able to visit the Route for your app deployed to the `myapp-prod` project to confirm that your image has been promoted through all stages. + +## Cleanup + +Cleaning up this example is as simple as deleting the projects we created at the beginning. + +``` +oc delete project basic-tomcat-dev basic-tomcat-prod basic-tomcat-stage +``` diff --git a/basic-tomcat/build/basic-java-template.yml b/basic-tomcat/build/basic-java-template.yml new file mode 100644 index 00000000..7ee79284 --- /dev/null +++ b/basic-tomcat/build/basic-java-template.yml @@ -0,0 +1,102 @@ +apiVersion: v1 +kind: Template +labels: + template: generic-java-jenkins-pipeline +metadata: + annotations: + description: Application template for JWS applications built using a Jenkins Pipeline + iconClass: icon-tomcat + tags: tomcat,tomcat8,java,jboss,xpaas,jenkins-ci + version: 1.2.0 + name: generic-java-jenkins-pipeline +objects: +- kind: "BuildConfig" + apiVersion: "v1" + metadata: + labels: + application: ${APPLICATION_NAME} + name: "${APPLICATION_NAME}-pipeline" + namespace: "${NAMESPACE}" + spec: + source: + type: Git + git: + uri: ${SOURCE_REPOSITORY_URL} + ref: ${SOURCE_REPOSITORY_REF} + contextDir: ${CONTEXT_DIR} + triggers: + - type: "GitHub" + github: + secret: ${GITHUB_WEBHOOK_SECRET} + - type: "ConfigChange" + strategy: + type: "JenkinsPipeline" + jenkinsPipelineStrategy: + jenkinsfilePath: ${PIPELINE_SCRIPT} + env: + - name: "BUILD_CONTEXT_DIR" + value: "demo" +- apiVersion: v1 + kind: BuildConfig + metadata: + labels: + application: ${APPLICATION_NAME} + name: ${APPLICATION_NAME} + namespace: "${NAMESPACE}" + spec: + output: + to: + kind: ImageStreamTag + name: ${APPLICATION_NAME}:latest + source: + binary: {} + type: Binary + strategy: + sourceStrategy: + from: + kind: ImageStreamTag + name: ${IMAGE_STREAM_TAG_NAME} + namespace: ${IMAGE_STREAM_NAMESPACE} + type: Source +parameters: +- description: The name for the application. + name: APPLICATION_NAME + required: true + value: basic-tomcat +- description: The namespace to deploy into + name: NAMESPACE + required: true +- description: Git source URI for application + name: SOURCE_REPOSITORY_URL + required: true + value: https://github.com/etsauer/ticket-monster.git +- description: Git branch/tag reference + name: SOURCE_REPOSITORY_REF + value: "master" +- description: Path within Git project to build; empty for root project directory. + name: CONTEXT_DIR + value: +- description: Path within Git project pointing to the pipeline run script + name: PIPELINE_SCRIPT + value: pipeline.groovy +- description: GitHub trigger secret + from: '[a-zA-Z0-9]{8}' + generate: expression + name: GITHUB_WEBHOOK_SECRET + required: true +- description: Generic build trigger secret + from: '[a-zA-Z0-9]{8}' + generate: expression + name: GENERIC_WEBHOOK_SECRET + required: true +- description: Namespace in which the ImageStreams for Red Hat Middleware images are + installed. These ImageStreams are normally installed in the openshift namespace. + You should only need to modify this if you've installed the ImageStreams in a + different namespace/project. + name: IMAGE_STREAM_NAMESPACE + required: true + value: openshift +- description: Image stream tag for the image you'd like to use to build the application + name: IMAGE_STREAM_TAG_NAME + required: true + value: jboss-webserver30-tomcat8-openshift:1.2 diff --git a/basic-tomcat/build/dev/params b/basic-tomcat/build/dev/params new file mode 100644 index 00000000..6e60f512 --- /dev/null +++ b/basic-tomcat/build/dev/params @@ -0,0 +1,2 @@ +APPLICATION_NAME=basic-tomcat +NAMESPACE=basic-tomcat-dev diff --git a/basic-tomcat/deploy/basic-tomcat-template.yml b/basic-tomcat/deploy/basic-tomcat-template.yml new file mode 100644 index 00000000..a50771f2 --- /dev/null +++ b/basic-tomcat/deploy/basic-tomcat-template.yml @@ -0,0 +1,147 @@ +apiVersion: v1 +kind: Template +labels: + template: jws30-tomcat8-deployment +metadata: + annotations: + description: Application template for JWS applications built using a Jenkins Pipeline + iconClass: icon-tomcat + tags: tomcat,tomcat8,java,jboss,xpaas + version: 1.2.0 + name: jws30-tomcat8-deployment +objects: +- apiVersion: v1 + kind: Service + metadata: + annotations: + description: The web server's http port. + labels: + application: ${APPLICATION_NAME} + name: ${APPLICATION_NAME} + namespace: ${NAMESPACE} + spec: + ports: + - port: 8080 + targetPort: 8080 + selector: + deploymentConfig: ${APPLICATION_NAME} +- apiVersion: v1 + id: ${APPLICATION_NAME}-http + kind: Route + metadata: + annotations: + description: Route for application's http service. + labels: + application: ${APPLICATION_NAME} + name: ${APPLICATION_NAME} + namespace: ${NAMESPACE} + spec: + host: ${HOSTNAME_HTTP} + to: + name: ${APPLICATION_NAME} +- apiVersion: v1 + kind: ImageStream + metadata: + labels: + application: ${APPLICATION_NAME} + name: ${APPLICATION_NAME} + namespace: ${NAMESPACE} +- apiVersion: v1 + kind: DeploymentConfig + metadata: + labels: + application: ${APPLICATION_NAME} + name: ${APPLICATION_NAME} + namespace: ${NAMESPACE} + spec: + replicas: 1 + selector: + deploymentConfig: ${APPLICATION_NAME} + strategy: + type: Recreate + template: + metadata: + labels: + application: ${APPLICATION_NAME} + deploymentConfig: ${APPLICATION_NAME} + name: ${APPLICATION_NAME} + spec: + containers: + - env: + - name: JWS_ADMIN_USERNAME + value: ${JWS_ADMIN_USERNAME} + - name: JWS_ADMIN_PASSWORD + value: ${JWS_ADMIN_PASSWORD} + image: ${APPLICATION_NAME} + imagePullPolicy: Always + name: ${APPLICATION_NAME} + ports: + - containerPort: 8778 + name: jolokia + protocol: TCP + - containerPort: 8080 + name: http + protocol: TCP + readinessProbe: + exec: + command: + - /bin/bash + - -c + - curl -s -u ${JWS_ADMIN_USERNAME}:${JWS_ADMIN_PASSWORD} 'http://localhost:8080/manager/jmxproxy/?get=Catalina%3Atype%3DServer&att=stateName' + |grep -iq 'stateName *= *STARTED' + terminationGracePeriodSeconds: 60 + triggers: + - imageChangeParams: + automatic: true + containerNames: + - ${APPLICATION_NAME} + from: + kind: ImageStreamTag + name: ${APPLICATION_NAME}:latest + type: ImageChange + - type: ConfigChange +- apiVersion: v1 + groupNames: null + kind: RoleBinding + metadata: + creationTimestamp: null + labels: + template: basic-tomcat-template + name: jenkins_edit + namespace: ${NAMESPACE} + roleRef: + name: edit + subjects: + - kind: ServiceAccount + name: ${SA_NAME} + namespace: ${SA_NAMESPACE} + userNames: + - system:serviceaccount:${SA_NAMESPACE}:${SA_NAME} +parameters: +- description: The name for the application. + name: APPLICATION_NAME + required: true + value: jws-app +- description: The namespace to deploy into + name: NAMESPACE + required: true +- description: Name of a service account that can deploy to this project + name: SA_NAME + required: true + value: jenkins +- description: Namespace of service account that can deploy to this project + name: SA_NAMESPACE + required: true +- description: 'Custom hostname for http service route. Leave blank for default hostname, + e.g.: -.' + name: HOSTNAME_HTTP +- description: JWS Admin User + from: '[a-zA-Z0-9]{8}' + generate: expression + name: JWS_ADMIN_USERNAME + required: true +- description: JWS Admin Password + from: '[a-zA-Z0-9]{8}' + generate: expression + name: JWS_ADMIN_PASSWORD + required: true diff --git a/basic-tomcat/deploy/dev/params b/basic-tomcat/deploy/dev/params new file mode 100644 index 00000000..691e53ec --- /dev/null +++ b/basic-tomcat/deploy/dev/params @@ -0,0 +1,3 @@ +APPLICATION_NAME=basic-tomcat +NAMESPACE=basic-tomcat-dev +SA_NAMESPACE=basic-tomcat-dev diff --git a/basic-tomcat/deploy/prod/params b/basic-tomcat/deploy/prod/params new file mode 100644 index 00000000..3c59f844 --- /dev/null +++ b/basic-tomcat/deploy/prod/params @@ -0,0 +1,3 @@ +APPLICATION_NAME=basic-tomcat +NAMESPACE=basic-tomcat-prod +SA_NAMESPACE=basic-tomcat-dev diff --git a/basic-tomcat/deploy/stage/params b/basic-tomcat/deploy/stage/params new file mode 100644 index 00000000..154e09ac --- /dev/null +++ b/basic-tomcat/deploy/stage/params @@ -0,0 +1,4 @@ +APPLICATION_NAME=basic-tomcat +NAMESPACE=basic-tomcat-stage +SA_NAME=jenkins +SA_NAMESPACE=basic-tomcat-dev diff --git a/basic-tomcat/pipeline.groovy b/basic-tomcat/pipeline.groovy new file mode 100644 index 00000000..42bc591e --- /dev/null +++ b/basic-tomcat/pipeline.groovy @@ -0,0 +1,131 @@ +#!/usr/bin/groovy + +//// +// This pipeline requires the following plugins: +// Kubernetes Plugin 0.10 +//// + +String ocpApiServer = env.OCP_API_SERVER ? "${env.OCP_API_SERVER}" : "https://openshift.default.svc.cluster.local" + +node('master') { + + env.NAMESPACE = readFile('/var/run/secrets/kubernetes.io/serviceaccount/namespace').trim() + env.TOKEN = readFile('/var/run/secrets/kubernetes.io/serviceaccount/token').trim() + env.OC_CMD = "oc --token=${env.TOKEN} --server=${ocpApiServer} --certificate-authority=/run/secrets/kubernetes.io/serviceaccount/ca.crt --namespace=${env.NAMESPACE}" + + env.APP_NAME = "${env.JOB_NAME}".replaceAll(/-?pipeline-?/, '').replaceAll(/-?${env.NAMESPACE}-?/, '') + def projectBase = "${env.NAMESPACE}".replaceAll(/-dev/, '') + env.STAGE1 = "${projectBase}-dev" + env.STAGE2 = "${projectBase}-stage" + env.STAGE3 = "${projectBase}-prod" + + sh(returnStdout: true, script: "${env.OC_CMD} get is jenkins-slave-image-mgmt --template=\'{{ .status.dockerImageRepository }}\' -n openshift > /tmp/jenkins-slave-image-mgmt.out") + env.SKOPEO_SLAVE_IMAGE = readFile('/tmp/jenkins-slave-image-mgmt.out').trim() + println "${env.SKOPEO_SLAVE_IMAGE}" + +} + +node('maven') { +// def artifactory = Artifactory.server(env.ARTIFACTORY_SERVER) + // def artifactoryMaven = Artifactory.newMavenBuild() + // def buildInfo = Artifactory.newBuildInfo() + // def scannerHome = tool env.SONARQUBE_TOOL + def mvnHome = "/usr/share/maven/" + def mvnCmd = "${mvnHome}bin/mvn" + String pomFileLocation = env.BUILD_CONTEXT_DIR ? "${env.BUILD_CONTEXT_DIR}/pom.xml" : "pom.xml" + + stage('SCM Checkout') { + checkout scm + } + + stage('Build') { + + sh "${mvnCmd} clean install -DskipTests=true -f ${pomFileLocation}" + + } + + stage('Build Image') { + + sh """ + rm -rf oc-build && mkdir -p oc-build/deployments + + for t in \$(echo "jar;war;ear" | tr ";" "\\n"); do + cp -rfv ./target/*.\$t oc-build/deployments/ 2> /dev/null || echo "No \$t files" + done + + for i in oc-build/deployments/*.war; do + mv -v oc-build/deployments/\$(basename \$i) oc-build/deployments/ROOT.war + break + done + + ${env.OC_CMD} start-build ${env.APP_NAME} --from-dir=oc-build --wait=true --follow=true || exit 1 + """ + } + + stage("Verify Deployment to ${env.STAGE1}") { + + openshiftVerifyDeployment(deploymentConfig: "${env.APP_NAME}", namespace: "${STAGE1}", verifyReplicaCount: true) + + input "Promote Application to Stage?" + } + + stage("Promote To ${env.STAGE2}") { + sh """ + ${env.OC_CMD} tag ${env.STAGE1}/${env.APP_NAME}:latest ${env.STAGE2}/${env.APP_NAME}:latest + """ + } + + stage("Verify Deployment to ${env.STAGE2}") { + + openshiftVerifyDeployment(deploymentConfig: "${env.APP_NAME}", namespace: "${STAGE2}", verifyReplicaCount: true) + + input "Promote Application to Prod?" + } + + stage("Promote To ${env.STAGE3}") { + sh """ + ${env.OC_CMD} tag ${env.STAGE2}/${env.APP_NAME}:latest ${env.STAGE3}/${env.APP_NAME}:latest + """ + } + + stage("Verify Deployment to ${env.STAGE3}") { + + openshiftVerifyDeployment(deploymentConfig: "${env.APP_NAME}", namespace: "${STAGE3}", verifyReplicaCount: true) + + } +} + +/* +podTemplate(label: 'promotion-slave', cloud: 'openshift', containers: [ + containerTemplate(name: 'jenkins-slave-image-mgmt', image: "${env.SKOPEO_SLAVE_IMAGE}", ttyEnabled: true, command: 'cat'), + containerTemplate(name: 'jnlp', image: 'jenkinsci/jnlp-slave:2.62-alpine', args: '${computer.jnlpmac} ${computer.name}') +]) { + + node('promotion-slave') { + + stage("Promote To ${env.STAGE3}") { + + container('jenkins-slave-image-mgmt') { + sh """ + + set +x + imageRegistry=\$(${env.OC_CMD} get is ${env.APP_NAME} --template='{{ .status.dockerImageRepository }}' -n ${env.STAGE2} | cut -d/ -f1) + + strippedNamespace=\$(echo ${env.NAMESPACE} | cut -d/ -f1) + + echo "Promoting \${imageRegistry}/${env.STAGE2}/${env.APP_NAME} -> \${imageRegistry}/${env.STAGE3}/${env.APP_NAME}" + skopeo --tls-verify=false copy --remove-signatures --src-creds openshift:${env.TOKEN} --dest-creds openshift:${env.TOKEN} docker://\${imageRegistry}/${env.STAGE2}/${env.APP_NAME} docker://\${imageRegistry}/${env.STAGE3}/${env.APP_NAME} + """ + } + } + + stage("Verify Deployment to ${env.STAGE3}") { + + openshiftVerifyDeployment(deploymentConfig: "${env.APP_NAME}", namespace: "${STAGE3}", verifyReplicaCount: true) + + } + + } +} +*/ +println "Application ${env.APP_NAME} is now in Production!" diff --git a/basic-tomcat/projects/projects.yml b/basic-tomcat/projects/projects.yml new file mode 100644 index 00000000..5dc18580 --- /dev/null +++ b/basic-tomcat/projects/projects.yml @@ -0,0 +1,21 @@ +apiVersion: v1 +kind: List +items: +- kind: ProjectRequest + apiVersion: v1 + metadata: + name: basic-tomcat-dev + creationTimestam: null + displayName: Dev - Basic Tomcat App +- kind: ProjectRequest + apiVersion: v1 + metadata: + name: basic-tomcat-stage + creationTimestam: null + displayName: Staging - Basic Tomcat App +- kind: ProjectRequest + apiVersion: v1 + metadata: + name: basic-tomcat-prod + creationTimestam: null + displayName: Prod - Basic Tomcat App diff --git a/jenkins-s2i/jenkins-s2i.yml b/jenkins-s2i/jenkins-s2i.yml new file mode 100644 index 00000000..ea05915a --- /dev/null +++ b/jenkins-s2i/jenkins-s2i.yml @@ -0,0 +1,62 @@ +apiVersion: v1 +kind: Template +labels: + template: jenkins2-s2i + group: jenkins2-s2i +metadata: + annotations: + description: Creates the Jenins2 image for CD Pipeline builds + iconClass: icon-jenkins + tags: instant-app,jenkins,cicd + name: jenkins2-s2i +parameters: +- description: Custom Jenkins for CD Pipeline SCM location + displayName: CD Jenkins Pipeline SCM URL + name: JENKINS_GIT_URL + required: true +- description: Custom Jenkins for CD Pipeline SCM branch + displayName: CD Jenkins Pipeline SCM branch + name: JENKINS_GIT_BRANCH + required: true + value: 'master' +- description: Context Directory inside of the Git repo + displayName: Context Directory + name: JENKINS_GIT_CONTEXT_DIR + value: '' +objects: +# Jenkins2 +- apiVersion: v1 + kind: ImageStream + metadata: + labels: + app: jenkins2-s2i + template: jenkins2-s2i + name: jenkins2-s2i +- apiVersion: v1 + kind: BuildConfig + metadata: + labels: + application: jenkins2-s2i + template: jenkins2-s2i + name: jenkins2-s2i + spec: + triggers: + - type: "ConfigChange" + output: + to: + kind: ImageStreamTag + name: jenkins2-s2i:latest + source: + type: Git + contextDir: '2' + git: + uri: "${JENKINS_GIT_URL}" + ref: "${JENKINS_GIT_BRANCH}" + contextDir: ${JENKINS_GIT_CONTEXT_DIR} + strategy: + sourceStrategy: + from: + kind: ImageStreamTag + name: jenkins:latest + namespace: openshift + type: Source diff --git a/jenkins-s2i/plugins.txt b/jenkins-s2i/plugins.txt new file mode 100644 index 00000000..96b73fd9 --- /dev/null +++ b/jenkins-s2i/plugins.txt @@ -0,0 +1 @@ +kubernetes:0.9