Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
Gl4di4torRr committed Jan 28, 2019
2 parents 60b95c3 + 87b3f8b commit cad9fe5
Show file tree
Hide file tree
Showing 18 changed files with 486 additions and 227 deletions.
56 changes: 52 additions & 4 deletions basic-spring-boot/.applier/group_vars/seed-hosts.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,70 @@
sb_application_name: basic-spring-boot
sb_build_namespace: basic-spring-boot-build
sb_dev_namespace: basic-spring-boot-dev
sb_stage_namespace: basic-spring-boot-stage
sb_prod_namespace: basic-spring-boot-prod
sb_application_repository_url: "https://github.com/redhat-cop/spring-rest.git"
sb_application_repository_ref: master
sb_application_readiness_response: "status.:.UP"
sb_application_readiness_path: "/health"
sb_sa_name: "jenkins"
sb_source_repository_url: "https://github.com/redhat-cop/container-pipelines.git"
sb_source_repository_ref: master
sb_pipeline_script: "Jenkinsfile"

openshift_cluster_content:
- object: projects
content:
- name: "create environments"
file: "{{ inventory_dir }}/../.openshift/projects/projects.yml"
action: create
tags:
- project
- object: builds
content:
- name: "deploy build pipeline to dev"
template: "{{ inventory_dir }}/../.openshift/templates/build.yml"
params: "{{ inventory_dir }}/../.openshift/params/build-dev"
params_from_vars:
APPLICATION_NAME: "{{ sb_application_name }}"
NAMESPACE: "{{ sb_build_namespace }}"
SOURCE_REPOSITORY_URL: "{{ sb_source_repository_url }}"
SOURCE_REPOSITORY_REF: "{{ sb_source_repository_ref }}"
APPLICATION_SOURCE_REPO: "{{ sb_application_repository_url }}"
APPLICATION_SOURCE_REF: "{{ sb_application_repository_ref }}"
PIPELINE_SCRIPT: "{{ sb_pipeline_script }}"
tags:
- build
- object: deployments
content:
- name: "deploy dev environment"
template: "{{ inventory_dir }}/../.openshift/templates/deployment.yml"
params: "{{ inventory_dir }}/../.openshift/params/deployment-dev"
params_from_vars:
APPLICATION_NAME: "{{ sb_application_name }}"
NAMESPACE: "{{ sb_dev_namespace }}"
SA_NAMESPACE: "{{ sb_build_namespace }}"
READINESS_RESPONSE: "{{ sb_application_readiness_response }}"
READINESS_PATH: "{{ sb_application_readiness_path }}"
tags:
- deployment
- name: "deply stage environment"
template: "{{ inventory_dir }}/../.openshift/templates/deployment.yml"
params: "{{ inventory_dir }}/../.openshift/params/deployment-stage"
params_from_vars:
APPLICATION_NAME: "{{ sb_application_name }}"
NAMESPACE: "{{ sb_stage_namespace }}"
SA_NAME: "{{ sb_sa_name }}"
SA_NAMESPACE: "{{ sb_build_namespace }}"
READINESS_RESPONSE: "{{ sb_application_readiness_response }}"
READINESS_PATH: "{{ sb_application_readiness_path }}"
tags:
- deployment
- name: "deply prod environment"
template: "{{ inventory_dir }}/../.openshift/templates/deployment.yml"
params: "{{ inventory_dir }}/../.openshift/params/deployment-prod"
params_from_vars:
APPLICATION_NAME: "{{ sb_application_name }}"
NAMESPACE: "{{ sb_prod_namespace }}"
SA_NAME: "{{ sb_sa_name }}"
SA_NAMESPACE: "{{ sb_build_namespace }}"
READINESS_RESPONSE: "{{ sb_application_readiness_response }}"
READINESS_PATH: "{{ sb_application_readiness_path }}"
tags:
- deployment
4 changes: 0 additions & 4 deletions basic-spring-boot/.openshift/params/build-dev

This file was deleted.

5 changes: 0 additions & 5 deletions basic-spring-boot/.openshift/params/deployment-dev

This file was deleted.

5 changes: 0 additions & 5 deletions basic-spring-boot/.openshift/params/deployment-prod

This file was deleted.

6 changes: 0 additions & 6 deletions basic-spring-boot/.openshift/params/deployment-stage

This file was deleted.

5 changes: 5 additions & 0 deletions basic-spring-boot/.openshift/templates/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ objects:
env:
- name: "APPLICATION_SOURCE_REPO"
value: "${APPLICATION_SOURCE_REPO}"
- name: "APPLICATION_SOURCE_REF"
value: "${APPLICATION_SOURCE_REF}"
- apiVersion: v1
kind: BuildConfig
metadata:
Expand Down Expand Up @@ -87,6 +89,9 @@ parameters:
name: APPLICATION_SOURCE_REPO
required: true
value: https://github.com/redhat-cop/spring-rest.git
- description: Source code branch for demo app
name: APPLICATION_SOURCE_REF
value: master
- description: Path within Git project pointing to the pipeline run script
name: PIPELINE_SCRIPT
value: Jenkinsfile
Expand Down
4 changes: 2 additions & 2 deletions basic-spring-boot/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ pipeline {
// Run Maven build, skipping tests
stage('Build'){
steps {
sh "mvn clean install -DskipTests=true -f ${POM_FILE}"
sh "mvn -B clean install -DskipTests=true -f ${POM_FILE}"
}
}

// Run Maven unit tests
stage('Unit Test'){
steps {
sh "mvn test -f ${POM_FILE}"
sh "mvn -B test -f ${POM_FILE}"
}
}

Expand Down
156 changes: 156 additions & 0 deletions basic-spring-boot/Jenkinsfile.hygieia
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
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 = "${JOB_NAME}".replaceAll(/-build.*/, '')
echo "Starting Pipeline for ${APP_NAME}..."
env.BUILD = "${env.NAMESPACE}"
env.DEV = "${APP_NAME}-dev"
env.STAGE = "${APP_NAME}-stage"
env.PROD = "${APP_NAME}-prod"
}

pipeline {
// Use Jenkins Maven slave
// Jenkins will dynamically provision this as OpenShift Pod
// All the stages and steps of this Pipeline will be executed on this Pod
// After Pipeline completes the Pod is killed so every run will have clean
// workspace
agent {
label 'maven'
}

// Pipeline Stages start here
// Requeres at least one stage
stages {

// Checkout source code
// This is required as Pipeline code is originally checkedout to
// Jenkins Master but this will also pull this same code to this slave
stage('Git Checkout') {
steps {
// Turn off Git's SSL cert check, uncomment if needed
// sh 'git config --global http.sslVerify false'
git url: "${APPLICATION_SOURCE_REPO}"
script {
env.commit = sh(script:"git rev-parse HEAD", returnStdout: true).trim()
env.version = "${env.commit}-${BUILD_NUMBER}"
}
echo "Setting version to ${env.version}"
}
}

// Run Maven build, skipping tests
stage('Build'){
steps {
hygieiaBuildPublishStep buildStatus: 'InProgress'
sh "mvn clean install -DskipTests=true -f ${POM_FILE}"
}
post {
failure {
hygieiaBuildPublishStep buildStatus: 'Failure'
}
aborted {
hygieiaBuildPublishStep buildStatus: 'Aborted'
}
success {
hygieiaBuildPublishStep buildStatus: 'Success'
hygieiaArtifactPublishStep artifactDirectory: './target/', artifactGroup: 'org.test', artifactName: "shift-rest-0.1.0.jar", artifactVersion: "${env.version}"
}
}
}

// Run Maven unit tests
stage('Unit Test'){
steps {
sh "mvn test -f ${POM_FILE}"
}
}

// Build Container Image using the artifacts produced in previous stages
stage('Build Container Image'){
steps {
// Copy the resulting artifacts into common directory
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
"""

// Build container image using local Openshift cluster
// 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.
binaryBuild(projectName: env.BUILD, buildConfigName: env.APP_NAME, artifactsDirectoryName: "oc-build")
}
}

stage('Promote from Build to Dev') {
steps {
tagImage(sourceImageName: env.APP_NAME, sourceImagePath: env.BUILD, toImagePath: env.DEV)
}
}

stage ('Verify Deployment to Dev') {
steps {
verifyDeployment(projectName: env.DEV, targetApp: env.APP_NAME)
}
post {
success {
hygieiaDeployPublishStep applicationName: "${APP_NAME}", artifactDirectory: './target/', artifactGroup: 'org.test', artifactName: "shift-rest-0.1.0.jar", artifactVersion: "${env.version}", buildStatus: 'Success', environmentName: "${env.DEV}"
}
}
}

stage('Promote from Dev to Stage') {
steps {
tagImage(sourceImageName: env.APP_NAME, sourceImagePath: env.DEV, toImagePath: env.STAGE)
}
}

stage ('Verify Deployment to Stage') {
steps {
verifyDeployment(projectName: env.STAGE, targetApp: env.APP_NAME)
}
post {
success {
hygieiaDeployPublishStep applicationName: "${APP_NAME}", artifactDirectory: './target/', artifactGroup: 'org.test', artifactName: "shift-rest-0.1.0.jar", artifactVersion: "${env.version}", buildStatus: 'Success', environmentName: "${env.STAGE}"
}
}
}

stage('Promotion gate') {
steps {
script {
input message: 'Promote application to Production?'
}
}
}

stage('Promote from Stage to Prod') {
steps {
tagImage(sourceImageName: env.APP_NAME, sourceImagePath: env.STAGE, toImagePath: env.PROD)
}
}

stage ('Verify Deployment to Prod') {
steps {
verifyDeployment(projectName: env.PROD, targetApp: env.APP_NAME)
}
post {
success {
hygieiaDeployPublishStep applicationName: "${APP_NAME}", artifactDirectory: './target/', artifactGroup: 'org.test', artifactName: "shift-rest-0.1.0.jar", artifactVersion: "${env.version}", buildStatus: 'Success', environmentName: "${env.PROD}"
}
}
}
}
}
2 changes: 1 addition & 1 deletion basic-spring-boot/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: v2.0.4
version: v2.0.6
Loading

0 comments on commit cad9fe5

Please sign in to comment.