Skip to content

Commit

Permalink
Use pipeline-library for basic-spring-boot app, fixes #32
Browse files Browse the repository at this point in the history
  • Loading branch information
pabrahamsson committed Oct 22, 2018
1 parent d46aed7 commit 76bbb2b
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 76 deletions.
10 changes: 5 additions & 5 deletions basic-spring-boot/.applier/group_vars/seed-hosts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ openshift_cluster_content:
- name: "create environments"
file: "{{ inventory_dir }}/../.openshift/projects/projects.yml"
action: create
- object: builds
content:
- name: "deploy build pipeline to dev"
template: "{{ inventory_dir }}/../.openshift/templates/build.yml"
params: "{{ inventory_dir }}/../.openshift/params/build-dev"
- object: deployments
content:
- name: "deploy dev environment"
Expand All @@ -15,8 +20,3 @@ openshift_cluster_content:
- name: "deply prod environment"
template: "{{ inventory_dir }}/../.openshift/templates/deployment.yml"
params: "{{ inventory_dir }}/../.openshift/params/deployment-prod"
- object: builds
content:
- name: "deploy build pipeline to dev"
template: "{{ inventory_dir }}/../.openshift/templates/build.yml"
params: "{{ inventory_dir }}/../.openshift/params/build-dev"
1 change: 1 addition & 0 deletions basic-spring-boot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
galaxy
2 changes: 1 addition & 1 deletion basic-spring-boot/.openshift/params/build-dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APPLICATION_NAME=spring-rest
APPLICATION_NAME=basic-spring-boot
NAMESPACE=basic-spring-boot-build
SOURCE_REPOSITORY_URL=https://github.com/redhat-cop/container-pipelines.git
SOURCE_REPOSITORY_REF=master
2 changes: 1 addition & 1 deletion basic-spring-boot/.openshift/params/deployment-dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APPLICATION_NAME=spring-rest
APPLICATION_NAME=basic-spring-boot
NAMESPACE=basic-spring-boot-dev
SA_NAMESPACE=basic-spring-boot-build
READINESS_RESPONSE=status.:.UP
Expand Down
2 changes: 1 addition & 1 deletion basic-spring-boot/.openshift/params/deployment-prod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APPLICATION_NAME=spring-rest
APPLICATION_NAME=basic-spring-boot
NAMESPACE=basic-spring-boot-prod
SA_NAMESPACE=basic-spring-boot-build
READINESS_RESPONSE=status.:.UP
Expand Down
2 changes: 1 addition & 1 deletion basic-spring-boot/.openshift/params/deployment-stage
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APPLICATION_NAME=spring-rest
APPLICATION_NAME=basic-spring-boot
NAMESPACE=basic-spring-boot-stage
SA_NAME=jenkins
SA_NAMESPACE=basic-spring-boot-build
Expand Down
86 changes: 21 additions & 65 deletions basic-spring-boot/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
library identifier: "pipeline-library@master",
retriever: modernSCM(
[
$class: "GitSCMSource",
remote: "https://github.com/redhat-cop/pipeline-library.git"
]
)

openshift.withCluster() {
env.NAMESPACE = openshift.project()
env.POM_FILE = env.BUILD_CONTEXT_DIR ? "${env.BUILD_CONTEXT_DIR}/pom.xml" : "pom.xml"
env.APP_NAME = "${env.JOB_NAME}".replaceAll(/-?pipeline-?/, '').replaceAll(/-?${env.NAMESPACE}-?/, '').replaceAll("/", '')
env.APP_NAME = "${JOB_NAME}".replaceAll(/-build.*/, '')
echo "Starting Pipeline for ${APP_NAME}..."
def projectBase = "${env.NAMESPACE}".replaceAll(/-build/, '')
env.STAGE0 = "${projectBase}-build"
env.STAGE1 = "${projectBase}-dev"
env.STAGE2 = "${projectBase}-stage"
env.STAGE3 = "${projectBase}-prod"
env.BUILD = "${env.NAMESPACE}"
env.DEV = "${APP_NAME}-dev"
env.STAGE = "${APP_NAME}-stage"
env.PROD = "${APP_NAME}-prod"
}

pipeline {
Expand Down Expand Up @@ -65,95 +72,44 @@ pipeline {
// Giving all the artifacts to OpenShift Binary Build
// This places your artifacts into right location inside your S2I image
// if the S2I image supports it.
script {
openshift.withCluster() {
openshift.withProject("${STAGE0}") {
openshift.selector("bc", "${APP_NAME}").startBuild("--from-dir=oc-build").logs("-f")
}
}
}
binaryBuild(projectName: env.BUILD, buildConfigName: env.APP_NAME, artifactsDirectoryName: "oc-build")
}
}

stage('Promote from Build to Dev') {
steps {
script {
openshift.withCluster() {
openshift.tag("${env.STAGE0}/${env.APP_NAME}:latest", "${env.STAGE1}/${env.APP_NAME}:latest")
}
}
tagImage(sourceImageName: env.APP_NAME, sourceImagePath: env.BUILD, toImagePath: env.DEV)
}
}

stage ('Verify Deployment to Dev') {
steps {
script {
openshift.withCluster() {
openshift.withProject("${STAGE1}") {
def dcObj = openshift.selector('dc', env.APP_NAME).object()
def podSelector = openshift.selector('pod', [deployment: "${APP_NAME}-${dcObj.status.latestVersion}"])
podSelector.untilEach {
echo "pod: ${it.name()}"
return it.object().status.containerStatuses[0].ready
}
}
}
}
verifyDeployment(projectName: env.DEV, targetApp: env.APP_NAME)
}
}

stage('Promote from Dev to Stage') {
steps {
script {
openshift.withCluster() {
openshift.tag("${env.STAGE1}/${env.APP_NAME}:latest", "${env.STAGE2}/${env.APP_NAME}:latest")
}
}
tagImage(sourceImageName: env.APP_NAME, sourceImagePath: env.DEV, toImagePath: env.STAGE)
}
}

stage ('Verify Deployment to Stage') {
steps {
script {
openshift.withCluster() {
openshift.withProject("${STAGE2}") {
def dcObj = openshift.selector('dc', env.APP_NAME).object()
def podSelector = openshift.selector('pod', [deployment: "${APP_NAME}-${dcObj.status.latestVersion}"])
podSelector.untilEach {
echo "pod: ${it.name()}"
return it.object().status.containerStatuses[0].ready
}
}
}
}
verifyDeployment(projectName: env.STAGE, targetApp: env.APP_NAME)
}
}

stage('Promote from Stage to Prod') {
steps {
script {
openshift.withCluster() {
openshift.tag("${env.STAGE2}/${env.APP_NAME}:latest", "${env.STAGE3}/${env.APP_NAME}:latest")
}
}
tagImage(sourceImageName: env.APP_NAME, sourceImagePath: env.STAGE, toImagePath: env.PROD)
}
}

stage ('Verify Deployment to Prod') {
steps {
script {
openshift.withCluster() {
openshift.withProject("${STAGE3}") {
def dcObj = openshift.selector('dc', env.APP_NAME).object()
def podSelector = openshift.selector('pod', [deployment: "${APP_NAME}-${dcObj.status.latestVersion}"])
podSelector.untilEach {
echo "pod: ${it.name()}"
return it.object().status.containerStatuses[0].ready
}
}
}
}
verifyDeployment(projectName: env.PROD, targetApp: env.APP_NAME)
}
}

}
}
3 changes: 1 addition & 2 deletions basic-spring-boot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This example demonstrates how to implement a full end-to-end Jenkins Pipeline fo
* 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`)
* Building a Jenkins pipeline with library functions from our [pipeline-library](https://github.com/redhat-cop/pipeline-library)
* Automated rollout using the [openshift-appler](https://github.com/redhat-cop/openshift-applier) project.

## Automated Deployment
Expand All @@ -17,7 +17,6 @@ This quickstart can be deployed quickly using Ansible. Here are the steps.
3. Run `ansible-galaxy install -r requirements.yml --roles-path=galaxy`
2. Log into an OpenShift cluster, then run the following command.
```
$ oc login
$ ansible-playbook -i ./.applier/ galaxy/openshift-applier/playbooks/openshift-cluster-seed.yml
```

Expand Down

0 comments on commit 76bbb2b

Please sign in to comment.