-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c0a549
commit a66d8bf
Showing
35 changed files
with
297 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,33 +10,36 @@ This example demonstrates how to implement a full end-to-end Jenkins Pipeline fo | |
|
||
## Quickstart | ||
|
||
### Requirements | ||
1. [OpenShift Applier](https://github.com/redhat-cop/casl-ansible) | ||
`git clone [email protected]:redhat-cop/casl-ansible.git` | ||
`git checkout v3.6.1` | ||
2. [Ansible](https://www.ansible.com/) | ||
`sudo dnf install ansible` | ||
|
||
### Installation | ||
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- | ||
ansible-playbook -i inventory/hosts ../casl-ansible/playbooks/openshift-cluster-seed.yml --connection=local | ||
``` | ||
The above command will create all the necessary projects and OpenShift objects as well as a Jenkins instance that will build, promote and deploy the application. | ||
Run the following commands to instantiate this example. | ||
|
||
## 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: | ||
The first template, `files/builds/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: | ||
The second template, `files/deployment/template.yml` is the "Deploy" template. It contains: | ||
|
||
* A tomcat8 DeploymentConfig | ||
* A Service definition | ||
|
@@ -68,32 +71,16 @@ https://github.com/etsauer/ticket-monster | |
|
||
For the purposes of this demo, we are going to create three stages for our application to be promoted through. | ||
|
||
- `build` | ||
- `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 build | ||
|
||
### 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 | ||
``` | ||
For this step, the OpenShift default template set provides exactly what we need to get jenkins up and running. Jenkins will be running in the `build` project and promote and deploy to the `basic-tomcat-dev` project. | ||
|
||
### 4. Instantiate Pipeline | ||
|
||
|
@@ -107,40 +94,11 @@ A _deploy template_ is provided at `deploy/basic-tomcat-template.yml` that defin | |
|
||
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 _build template_ is provided at `files/builds/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 | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
NAMESPACE=build | ||
SOURCE_REPOSITORY_URL=https://github.com/pabrahamsson/ticket-monster.git | ||
SOURCE_REPOSITORY_REF=build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
MEMORY_LIMIT=512Mi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
APPLICATION_NAME=basic-tomcat | ||
ENV=-dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
APPLICATION_NAME=basic-tomcat | ||
ENV=-prod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
APPLICATION_NAME=basic-tomcat | ||
ENV=-stage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
apiVersion: v1 | ||
kind: Template | ||
metadata: | ||
annotations: | ||
description: ImageStream template | ||
objects: | ||
- apiVersion: v1 | ||
kind: ImageStream | ||
metadata: | ||
name: jboss-webserver31-tomcat8-openshift | ||
namespace: "${NAMESPACE}" | ||
spec: | ||
lookupPolicy: | ||
local: false | ||
tags: | ||
- from: | ||
kind: DockerImage | ||
name: "${IMAGE}" | ||
name: "${TAG}" | ||
referencePolicy: | ||
type: Source | ||
parameters: | ||
- description: Image name to use for the ImageStream | ||
name: IMAGE | ||
required: true | ||
- description: The namespace where to create the ImageStream | ||
name: NAMESPACE | ||
required: true | ||
- description: Image tag to sync | ||
name: TAG | ||
required: true | ||
value: latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
IMAGE=registry.access.redhat.com/jboss-webserver-3/webserver31-tomcat8-openshift | ||
NAMESPACE=openshift | ||
TAG=1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.