Skip to content

Commit

Permalink
Updating blue green pipeline with applier v2.0.3 (#42)
Browse files Browse the repository at this point in the history
* Updating blue green pipeline with applier v2.0.3

* Adjust scm step in Jenkinsfile

* Remove git describe

* Fixing environment search & replace

* Fixing pipeline

* Fixing project display names so they group together

* Pointing to primary repository instead of fork

* Adding removal of slash from namespace
  • Loading branch information
etsauer authored and oybed committed Oct 16, 2018
1 parent 91b141b commit bdea401
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 68 deletions.
27 changes: 27 additions & 0 deletions blue-green-spring/.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: simple-spring-boot-spaces
file: "{{ inventory_dir }}/../.openshift/projects/projects.yml"
action: create
- object: deployments
content:
- name: jenkins
namespace: spring-boot-web-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-bg.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 blue-green-spring/.applier/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[seed-hosts]
localhost ansible_connection=local
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
APPLICATION_NAME=spring-boot-web
NAMESPACE=spring-boot-web-build
IMAGE_STREAM_TAG_NAME=redhat-openjdk18-openshift:1.1
SOURCE_REPOSITORY_URL=https://github.com/pabrahamsson/simple-spring-boot-web.git
SOURCE_REPOSITORY_REF=build
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ objects:
type: "JenkinsPipeline"
jenkinsPipelineStrategy:
jenkinsfilePath: ${PIPELINE_SCRIPT}
env:
- name: "BUILD_CONTEXT_DIR"
value: "demo"
env:
- name: "APPLICATION_SOURCE_REPO"
value: "${APPLICATION_SOURCE_REPO}"
- apiVersion: v1
kind: BuildConfig
metadata:
Expand Down Expand Up @@ -76,16 +76,20 @@ parameters:
- description: Git source URI for application
name: SOURCE_REPOSITORY_URL
required: true
value: https://github.com/malacourse/simple-spring-boot-web.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: "blue-green-spring"
- 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/redhat-cop/spring-rest.git
- 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 @@ -134,7 +134,8 @@ objects:
command:
- /bin/bash
- -c
- curl -s 'http://localhost:8080/' |grep -iq 'Openshift'
- curl -s 'http://localhost:8080${READINESS_PATH}'
|grep -iq '${READINESS_RESPONSE}'
terminationGracePeriodSeconds: 60
triggers:
- imageChangeParams:
Expand Down Expand Up @@ -184,7 +185,8 @@ objects:
command:
- /bin/bash
- -c
- curl -s 'http://localhost:8080/' |grep -iq 'Openshift'
- curl -s 'http://localhost:8080${READINESS_PATH}'
|grep -iq '${READINESS_RESPONSE}'
terminationGracePeriodSeconds: 60
triggers:
- imageChangeParams:
Expand Down Expand Up @@ -232,3 +234,11 @@ 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: 'URI to check for app health'
name: READINESS_PATH
required: true
value: '/health'
- description: 'String value expected back from readiness check'
name: READINESS_RESPONSE
required: true
value: 'UP'
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ objects:
command:
- /bin/bash
- -c
- curl -s 'http://localhost:8080/' |grep -iq 'Openshift'
- curl -s 'http://localhost:8080${READINESS_PATH}'
|grep -iq '${READINESS_RESPONSE}'
terminationGracePeriodSeconds: 60
triggers:
- imageChangeParams:
Expand Down Expand Up @@ -127,3 +128,11 @@ 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: 'URI to check for app health'
name: READINESS_PATH
required: true
value: '/health'
- description: 'String value expected back from readiness check'
name: READINESS_RESPONSE
required: true
value: 'UP'
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ items:
metadata:
name: spring-boot-web-dev
creationTimestam: null
displayName: Dev - Spring Boot Blue Green
displayName: Spring Boot Blue Green - Dev
- kind: ProjectRequest
apiVersion: v1
metadata:
name: spring-boot-web-stage
creationTimestam: null
displayName: Staging - Spring Boot Blue Green
displayName: Spring Boot Blue Green - Staging
- kind: ProjectRequest
apiVersion: v1
metadata:
name: spring-boot-web-prod
creationTimestam: null
displayName: Prod - Spring Boot Blue Green
displayName: Spring Boot Blue Green - Prod
- kind: ProjectRequest
apiVersion: v1
metadata:
name: spring-boot-web-build
creationTimestam: null
displayName: Build - Jenkins is here
displayName: Spring Boot Blue Green - Build
21 changes: 10 additions & 11 deletions blue-green-spring/pipeline.groovy → blue-green-spring/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
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 --request-timeout='0' --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.APP_NAME = "${env.JOB_NAME}".replaceAll(/-?pipeline-?/, '').replaceAll(/-?${env.NAMESPACE}-?\/?/, '')
def projectBase = "${env.NAMESPACE}".replaceAll(/-build/, '')
env.STAGE1 = "${projectBase}-dev"
env.STAGE2 = "${projectBase}-stage"
env.STAGE3 = "${projectBase}-prod"
Expand All @@ -28,8 +28,7 @@ node('maven') {

stage('SCM Checkout') {

checkout scm
sh "orig=\$(pwd); cd \$(dirname ${pomFileLocation}); git describe --tags; cd \$orig"
git url: "${APPLICATION_SOURCE_REPO}"
}

stage('Build') {
Expand All @@ -52,7 +51,7 @@ node('maven') {
def version = getVersionFromPom("./pom.xml")
println("Artifact ID:" + artifactId + ", Group ID:" + groupId)
println("New version tag:" + version)

stage('Build Image') {

sh """
Expand Down Expand Up @@ -100,9 +99,9 @@ node('maven') {

def newState = "blue"
def currentState = "green"

stage("Promote To ${env.STAGE3}") {

sh "oc get route ${env.APP_NAME} -n ${env.STAGE3} -o jsonpath='{ .spec.to.name }' --loglevel=4 > activeservice"
activeService = readFile('activeservice').trim()
println("Current active service:" + activeService)
Expand All @@ -115,7 +114,7 @@ node('maven') {
${env.OC_CMD} tag ${env.STAGE1}/${env.APP_NAME}:'latest' ${env.STAGE3}/${env.APP_NAME}-${newState}:${version}
"""
sh "${env.OC_CMD} patch dc ${env.APP_NAME}-${newState} --patch '{\"spec\": { \"triggers\": [ { \"type\": \"ImageChange\", \"imageChangeParams\": { \"containerNames\": [ \"${env.APP_NAME}-${newState}\" ], \"from\": { \"kind\": \"ImageStreamTag\", \"namespace\": \"${env.STAGE3}\", \"name\": \"${env.APP_NAME}-${newState}:${version}\"}}}]}}' -n ${env.STAGE3}"

openshiftDeploy (apiURL: "${ocpApiServer}", authToken: "${env.TOKEN}", depCfg: "${env.APP_NAME}-${newState}", namespace: "${env.STAGE3}", waitTime: '300', waitUnit: 'sec')

}
Expand All @@ -126,11 +125,11 @@ node('maven') {
println "Application ${env.APP_NAME}-${newState} is now in Production!"

input "Switch ${env.STAGE3} from ${currentState} to ${newState} deployment?"

// Switch Route to new active c
sh "oc patch route ${env.APP_NAME} --patch '{\"spec\": { \"to\": { \"name\": \"${env.APP_NAME}-${newState}\"}}}' -n ${env.STAGE3}"
println("Route switched to: " + newState)

}
}

Expand Down
16 changes: 4 additions & 12 deletions blue-green-spring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,21 @@ This sample demonstrates the following capabilities:
* Switching production routes between blue and green deployments after confirmation
* Automated rollout using the [openshift-applier](https://github.com/redhat-cop/openshift-applier/tree/master/roles/openshift-applier) Ansible role.

## Quickstart
## Automated Deployment

### Requirements
1. [Ansible](https://www.ansible.com/)

```
sudo dnf install ansible
```

### Installation
Run the following commands to instantiate this example.
1. Clone this repository
1. Clone [this repo](https://github.com/redhat-cop/container-pipelines)
2. `cd container-pipelines/blue-green-spring`
3. Run ansible-galaxy to install required Ansible roles

```
ansible-galaxy install -r requirements.yml --roles-path=roles
ansible-galaxy install -r requirements.yml --roles-path=galaxy
```

4. Run the following Ansible playbook to install all the necessary projects and OpenShift objects as well as a Jenkins instance that will build, promote and deploy the application.

```
ansible-playbook -i inventory/hosts roles/openshift-applier/playbooks/openshift-cluster-seed.yml --connection=local
ansible-playbook -i .applier galaxy/openshift-applier/playbooks/openshift-cluster-seed.yml
```

## Architecture
Expand Down
27 changes: 0 additions & 27 deletions blue-green-spring/inventory/group_vars/all.yml

This file was deleted.

2 changes: 0 additions & 2 deletions blue-green-spring/inventory/hosts

This file was deleted.

2 changes: 1 addition & 1 deletion blue-green-spring/requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
- name: openshift-applier
scm: git
src: https://github.com/redhat-cop/openshift-applier
version: v3.7.2
version: v2.0.3

0 comments on commit bdea401

Please sign in to comment.