Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating Tomcat pipeline to v2.0.3 applier conventions #41

Merged
merged 16 commits into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*/galaxy/*
27 changes: 27 additions & 0 deletions basic-tomcat/.applier/group_vars/seed-hosts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
openshift_cluster_content:
- object: projectrequest
content:
- name: basic-tomcat-spaces
file: "{{ inventory_dir }}/../.openshift/projects/projects.yml"
action: create
- object: deployments
content:
- name: jenkins
namespace: basic-tomcat-build
template: openshift//jenkins-ephemeral
params: "{{ inventory_dir }}/../.openshift/deployment/build/params"
- name: basic-tomcat-dev
template: "{{ inventory_dir }}/../.openshift/deployment/template.yml"
params: "{{ inventory_dir }}/../.openshift/deployment/dev/params"
- name: basic-tomcat-stage
template: "{{ inventory_dir }}/../.openshift/deployment/template.yml"
params: "{{ inventory_dir }}/../.openshift/deployment/stage/params"
- name: basic-tomcat-prod
template: "{{ inventory_dir }}/../.openshift/deployment/template.yml"
params: "{{ inventory_dir }}/../.openshift/deployment/prod/params"
- object: builds
content:
- name: jenkins
template: "{{ inventory_dir }}/../.openshift/builds/template.yml"
params: "{{ inventory_dir }}/../.openshift/builds/params"
2 changes: 2 additions & 0 deletions basic-tomcat/.applier/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[seed-hosts]
localhost ansible_connection=local
1 change: 1 addition & 0 deletions basic-tomcat/.openshift/builds/params
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NAMESPACE=basic-tomcat-build
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ objects:
type: "JenkinsPipeline"
jenkinsPipelineStrategy:
jenkinsfilePath: ${PIPELINE_SCRIPT}
env:
env:
- name: "APPLICATION_SOURCE_REPO"
value: "${APPLICATION_SOURCE_REPO}"
- name: "APPLICATION_SOURCE_REF"
value: "${APPLICATION_SOURCE_REF}"
- name: "BUILD_CONTEXT_DIR"
value: "demo"
value: "${APPLICATION_CONTEXT_DIR}"
- apiVersion: v1
kind: BuildConfig
metadata:
Expand Down Expand Up @@ -78,16 +82,28 @@ parameters:
- description: Git source URI for application
name: SOURCE_REPOSITORY_URL
required: true
value: https://github.com/etsauer/ticket-monster.git
value: https://github.com/redhat-cop/container-pipelines.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:
value: "basic-tomcat"
- description: Path within Git project pointing to the pipeline run script
name: PIPELINE_SCRIPT
value: pipeline.groovy
value: Jenkinsfile
- description: Source code repo for demo app
name: APPLICATION_SOURCE_REPO
required: true
value: https://github.com/jboss-developer/ticket-monster.git
- description: Source code branch/tag
name: APPLICATION_SOURCE_REF
required: true
value: 2.7.0.Final-with-tutorials
- description: Directory where POM file will be
name: APPLICATION_CONTEXT_DIR
required: true
value: demo
- description: GitHub trigger secret
from: '[a-zA-Z0-9]{8}'
generate: expression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ objects:
namespace: ${APPLICATION_NAME}${ENV}
spec:
host: ${HOSTNAME_HTTP}
path: ${ROUTE_PATH}
to:
name: ${APPLICATION_NAME}
- apiVersion: v1
Expand Down Expand Up @@ -154,6 +155,9 @@ parameters:
- description: 'Custom hostname for http service route. Leave blank for default hostname,
e.g.: <application-name>-<project>.<default-domain-suffix>'
name: HOSTNAME_HTTP
- description: Path to use for route.
name: ROUTE_PATH
value: /ticket-monster
- description: JWS Admin User
from: '[a-zA-Z0-9]{8}'
generate: expression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ items:
metadata:
name: basic-tomcat-dev
creationTimestam: null
displayName: Dev - Basic Tomcat App
displayName: Basic Tomcat App - Dev
- kind: ProjectRequest
apiVersion: v1
metadata:
name: basic-tomcat-stage
creationTimestam: null
displayName: Staging - Basic Tomcat App
displayName: Basic Tomcat App - Stage
- kind: ProjectRequest
apiVersion: v1
metadata:
name: basic-tomcat-prod
creationTimestam: null
displayName: Prod - Basic Tomcat App
displayName: Basic Tomcat App - Prod
- kind: ProjectRequest
apiVersion: v1
metadata:
name: basic-tomcat-build
creationTimestam: null
displayName: Build - Jenkins is here
displayName: Basic Tomcat App - Build
96 changes: 96 additions & 0 deletions basic-tomcat/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/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}-?\/?/, '')
println "Starting Pipeline for Application: ${APP_NAME}"
println "${env.JOB_NAME}, ${env.NAMESPACE}"
def projectBase = "${env.NAMESPACE}".replaceAll(/-build/, '')
env.STAGE0 = "${projectBase}-build"
env.STAGE1 = "${projectBase}-dev"
env.STAGE2 = "${projectBase}-stage"
env.STAGE3 = "${projectBase}-prod"
}

node('maven') {

stage('SCM Checkout') {
git url: "${APPLICATION_SOURCE_REPO}", branch: "${APPLICATION_SOURCE_REF}"
}

stage('Build') {

String pomFileLocation = env.BUILD_CONTEXT_DIR ? "${env.BUILD_CONTEXT_DIR}/pom.xml" : "pom.xml"
sh "mvn clean install -DskipTests=true -f ${pomFileLocation}"

}

stage('Build Image') {

String target = env.BUILD_CONTEXT_DIR ? "${env.BUILD_CONTEXT_DIR}/target" : "target"

sh """
ls ${target}/*
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
"""
openshift.withCluster() {
openshift.withProject("${STAGE0}") {
openshift.selector("bc", "${APP_NAME}").startBuild("--from-dir=oc-build").logs("-f")
}
}
}

stage ("Promote from Build to Dev") {
openshift.withCluster() {
openshift.tag("${env.STAGE0}/${env.APP_NAME}:latest", "${env.STAGE1}/${env.APP_NAME}:latest")
}
}

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)

}
}

println "Application ${env.APP_NAME} is now in Production!"
23 changes: 8 additions & 15 deletions basic-tomcat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@ This example demonstrates how to implement a full end-to-end Jenkins Pipeline fo
* Promotion of an application's container image to a separate OpenShift Cluster (using `skopeo`)
* Automated rollout using the [openshift-appler](https://github.com/redhat-cop/openshift-applier) project.

## Quickstart
## Automated Deployment

### Requirements
1. [OpenShift Applier](https://github.com/redhat-cop/openshift-applier)
`git clone [email protected]:redhat-cop/openshift-applier.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.
1. Clone [this repo](https://github.com/redhat-cop/container-pipelines)
2. `cd container-pipelines/basic-tomcat`
3. Run `ansible-galaxy install -r requirements.yml --roles-path=galaxy`
4. Run the following commands to instantiate this example.
```
ansible-playbook -i inventory/hosts ../openshift-applier/playbooks/openshift-cluster-seed.yml --connection=local
ansible-playbook -i .applier/ galaxy/openshift-applier/playbooks/openshift-cluster-seed.yml
```
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.
Expand All @@ -38,7 +33,7 @@ The first template, `files/builds/template.yml` is what we are calling the "Buil
* 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 build template contains a default source code repo for a java application compatible with this pipelines architecture (https://github.com/jboss-developer/ticket-monster.git).

The second template, `files/deployment/template.yml` is the "Deploy" template. It contains:

Expand All @@ -56,9 +51,7 @@ This project includes a sample `pipeline.groovy` Jenkins Pipeline script that co
* 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: `<app-name>-dev`, `<app-name>-stage`, `<app-name>-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
For convenience, the project will, by default build and deploy the [JBoss Developers Ticket Monster](https://github.com/jboss-developer/ticket-monster.git) application.

## Bill of Materials

Expand Down
3 changes: 0 additions & 3 deletions basic-tomcat/files/builds/params

This file was deleted.

27 changes: 0 additions & 27 deletions basic-tomcat/inventory/group_vars/all.yml

This file was deleted.

2 changes: 0 additions & 2 deletions basic-tomcat/inventory/hosts

This file was deleted.

Loading