Skip to content

Commit

Permalink
demo_release_validation_srg_jenkins role added
Browse files Browse the repository at this point in the history
  • Loading branch information
eemrdog committed Jan 19, 2024
1 parent f6b3e38 commit 283d019
Show file tree
Hide file tree
Showing 33 changed files with 2,344 additions and 0 deletions.
1 change: 1 addition & 0 deletions user-skel/.ace/ace
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ enable_targets = [
'demo_monaco_gitops',
'demo_ar_workflows_gitlab',
'demo_release_validation_srg_gitlab',
'demo_release_validation_srg_jenkins',
'demo_ar_workflows_ansible'
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
- demo_release_validation_srg_gitlab
- never

# Use case - Release Validation with Site Reliability Guardion via Jenkins
- role: demo-release-validation-srg-jenkins
tags:
- demo_release_validation_srg_jenkins
- never

# Use case - Auto Remediation Workflows with Ansible
- role: demo-ar-workflows-ansible
tags:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
demo_quality_gates_jenkins_org: "demo"
demo_quality_gates_jenkins_repo_name: "release-validation-jenkins"
demo_quality_gates_jenkins_folder: "demo-release-validation-jenkins"
monacoVersion: "2.9.2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
pipeline {
agent {
label 'nodejs'
}
stages {
stage('Node build') {
steps {
checkout scm
container('nodejs') {
sh 'npm install'
}
}
}
stage('Docker build and push') {
parallel {
stage('Build 1') {
environment {
BUILD = '1'
GIT_COMMIT_SHORT = sh(returnStdout: true, script: "echo ${env.GIT_COMMIT} | cut -c1-6 | tr -d '\n'")
// Release product may not end in string, as Dynatrace won't merge
// services required to be merged for canary baselining
RELEASE_PRODUCT = 'simplenodeservice'
RELEASE_VERSION = "${env.BUILD}.0.0"
RELEASE_BUILD_VERSION = "${env.RELEASE_VERSION}-${env.GIT_COMMIT_SHORT}"
IMAGE_TAG = "${env.RELEASE_BUILD_VERSION}"
IMAGE_NAME = "${env.DOCKER_REGISTRY_URL}/${env.RELEASE_PRODUCT}"
IS_CANARY = false
CANARY_WEIGHT = '0'
// Usually, RELEASE_PRODUCT and HELM_RELEASE_NAME can be the same. For our demo,
// i.e. the NGINX canary feature, we need to deloy both Helm releases in the same
// namespace and therefore overwrite the release name.
HELM_RELEASE_NAME = 'simplenodeservice-0'
}
stages {
stage('Docker build') {
steps {
container('docker') {
sh "docker build --build-arg BUILD_NUMBER=${env.BUILD} -t ${env.IMAGE_NAME}:${env.IMAGE_TAG} ."
}
}
}
stage('Docker push') {
steps {
container('docker') {
sh "docker push ${env.IMAGE_NAME}:${env.IMAGE_TAG}"
}
}
}
stage('Deploy good build') {
steps {
build job: 'demo-ar-workflows-ansible/3. Deploy',
wait: false,
parameters: [
string(name: 'RELEASE_PRODUCT', value: "${env.RELEASE_PRODUCT}"),
string(name: 'RELEASE_VERSION', value: "${env.RELEASE_VERSION}"),
string(name: 'RELEASE_BUILD_VERSION', value: "${env.RELEASE_BUILD_VERSION}"),
string(name: 'RELEASE_STAGE', value: 'canary-jenkins'),
string(name: 'IMAGE_TAG', value: "${env.IMAGE_TAG}"),
string(name: 'IMAGE_NAME', value: "${env.IMAGE_NAME}"),
booleanParam(name: 'IS_CANARY', value: "${env.IS_CANARY}"),
string(name: 'CANARY_WEIGHT', value: "${env.CANARY_WEIGHT}"),
string(name: 'HELM_RELEASE_NAME', value: "${env.HELM_RELEASE_NAME}")
]
}
}
}
}
stage('Build 4') {
environment {
BUILD = '4'
GIT_COMMIT_SHORT = sh(returnStdout: true, script: "echo ${env.GIT_COMMIT} | cut -c1-6 | tr -d '\n'")
// Release product may not end in string, as Dynatrace won't merge
// services required to be merged for canary baselining
RELEASE_PRODUCT = 'simplenodeservice'
RELEASE_VERSION = "${env.BUILD}.0.0"
RELEASE_BUILD_VERSION = "${env.RELEASE_VERSION}-${env.GIT_COMMIT_SHORT}"
IMAGE_TAG = "${env.RELEASE_BUILD_VERSION}"
IMAGE_NAME = "${env.DOCKER_REGISTRY_URL}/${env.RELEASE_PRODUCT}"
IS_CANARY = true
CANARY_WEIGHT = '0'
// Usually, RELEASE_PRODUCT and HELM_RELEASE_NAME can be the same. For our demo,
// i.e. the NGINX canary feature, we need to deloy both Helm releases in the same
// namespace and therefore overwrite the release name.
HELM_RELEASE_NAME = 'simplenodeservice-1'
}
stages {
stage('Docker build') {
steps {
container('docker') {
sh "docker build --build-arg BUILD_NUMBER=${env.BUILD} -t ${env.IMAGE_NAME}:${env.IMAGE_TAG} ."
}
}
}
stage('Docker push') {
steps {
container('docker') {
sh "docker push ${env.IMAGE_NAME}:${env.IMAGE_TAG}"
}
}
}
stage('Deploy faulty build') {
steps {
build job: 'demo-ar-workflows-ansible/3. Deploy',
wait: false,
parameters: [
string(name: 'RELEASE_PRODUCT', value: "${env.RELEASE_PRODUCT}"),
string(name: 'RELEASE_VERSION', value: "${env.RELEASE_VERSION}"),
string(name: 'RELEASE_BUILD_VERSION', value: "${env.RELEASE_BUILD_VERSION}"),
string(name: 'RELEASE_STAGE', value: 'canary-jenkins'),
string(name: 'IMAGE_TAG', value: "${env.IMAGE_TAG}"),
string(name: 'IMAGE_NAME', value: "${env.IMAGE_NAME}"),
booleanParam(name: 'IS_CANARY', value: "${env.IS_CANARY}"),
string(name: 'CANARY_WEIGHT', value: "${env.CANARY_WEIGHT}"),
string(name: 'HELM_RELEASE_NAME', value: "${env.HELM_RELEASE_NAME}")
]
}
}
}
}
}
}
stage('Monaco') {
steps {
build job: 'demo-ar-workflows-ansible/2. Monaco',
wait: false
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
@Library('[email protected]')
def event = new com.dynatrace.ace.Event()

pipeline {
agent {
label 'monaco-runner'
}
environment {
DT_API_TOKEN = credentials('DT_API_TOKEN')
DT_TENANT_URL = "${env.DYNATRACE_URL_GEN3}"
DT_OAUTH_CLIENT_ID = credentials('DT_OAUTH_CLIENT_ID')
DT_OAUTH_CLIENT_SECRET = credentials('DT_OAUTH_CLIENT_SECRET')
DT_OAUTH_SSO_ENDPOINT = credentials('DT_OAUTH_SSO_ENDPOINT')
AWX_BASIC_AUTH = credentials('AWX_BASIC_AUTH')
// As of June 2023, MONACO_FEAT_AUTOMATION_RESOURCES flag required as feature is in preview
MONACO_FEAT_AUTOMATION_RESOURCES = '1'
// Monaco variables
DT_OWNER_IDENTIFIER = 'demo-ar-workflows-ansible'
RELEASE_PRODUCT = 'simplenodeservice'
RELEASE_STAGE = 'canary-jenkins'
}
stages {
stage('Dynatrace global project - Validate') {
steps {
container('monaco') {
script {
sh 'monaco deploy monaco/manifest.yaml -p global -d'
}
}
}
}
stage('Dynatrace global project - Deploy') {
steps {
container('monaco') {
script {
sh 'monaco deploy monaco/manifest.yaml -p global'
}
}
}
}
stage('Dynatrace app project - Validate') {
steps {
container('monaco') {
script {
sh 'monaco deploy monaco/manifest.yaml -p app -d'
}
}
}
}
stage('Dynatrace app project - Deploy') {
steps {
container('monaco') {
script {
sh 'monaco deploy monaco/manifest.yaml -p app'
}
}
}
}
stage('Dynatrace configuration event') {
steps {
script {
// Give Dynatrace a couple seconds to tag host according to current config
sleep(time:120, unit:'SECONDS')

event.pushDynatraceConfigurationEvent(
tagRule: getTagRulesForHostEvent('ace-demo-canary'),
description: 'Monaco deployment successful: ace-demo-canary',
configuration: 'ace-demo-canary',
customProperties: [
'Approved by': 'ACE'
]
)
}
}
}
}
}

//
// Legacy tag rules function can be removed with availabilty of dta feature
//
def getTagRulesForHostEvent(hostTag) {
def tagMatchRules = [
[
'meTypes': ['HOST'],
tags: [
['context': 'CONTEXTLESS', 'key': hostTag]
]
]
]

return tagMatchRules
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
@Library('[email protected]')
def event = new com.dynatrace.ace.Event()

pipeline {
parameters {
string(
name: 'RELEASE_PRODUCT',
defaultValue: 'simplenodeservice',
description: 'The name of the service to deploy.',
trim: true
)
string(
name: 'IMAGE_NAME',
defaultValue: '',
description: 'The image name of the service to deploy.',
trim: true
)
string(name: 'IMAGE_TAG', defaultValue: '', description: 'The image tag of the service to deploy.', trim: true)
string(name: 'RELEASE_VERSION', defaultValue: '', description: 'SemVer release version.', trim: true)
string(
name: 'RELEASE_BUILD_VERSION',
defaultValue: '',
description: 'Release version, including build id.',
trim: true
)
string(
name: 'RELEASE_STAGE',
defaultValue: 'canary-jenkins',
description: 'Namespace service will be deployed in.',
trim: true
)
string(
name: 'CANARY_WEIGHT',
defaultValue: '0',
description: 'Weight of traffic that will be routed to service.',
trim: true
)
booleanParam(name: 'IS_CANARY', defaultValue: false, description: 'Is canary version of service.')
string(
name: 'HELM_RELEASE_NAME',
defaultValue: 'simplenodeservice',
description: 'The name of the Helm release.',
trim: true
)
}
agent {
label 'kubegit'
}
environment {
DT_API_TOKEN = credentials('DT_API_TOKEN')
DT_TENANT_URL = credentials('DT_TENANT_URL')
}
stages {
stage('Deploy') {
steps {
script {
env.DT_CUSTOM_PROP = generateMetaData()
env.DT_TAGS = "non-prod BUILD=${env.RELEASE_BUILD_VERSION}"
}
container('helm') {
sh "helm upgrade --install ${env.HELM_RELEASE_NAME} helm/simplenodeservice \
--set image=\"${env.IMAGE_NAME}:${env.IMAGE_TAG}\" \
--set domain=${env.INGRESS_DOMAIN} \
--set version=${env.RELEASE_VERSION} \
--set build_version=${env.RELEASE_BUILD_VERSION} \
--set ingress.isCanary=${env.IS_CANARY} \
--set ingress.canaryWeight=${env.CANARY_WEIGHT} \
--set dt_release_product=\"${env.RELEASE_PRODUCT}\" \
--set dt_owner=\"demo-ar-workflows-ansible\" \
--set dt_tags=\"${env.DT_TAGS}\" \
--set dt_custom_prop=\"${env.DT_CUSTOM_PROP}\" \
--namespace ${env.RELEASE_STAGE} --create-namespace \
--wait"
}
}
}
stage('Dynatrace deployment event') {
steps {
script {
sleep(time:120, unit:'SECONDS')

event.pushDynatraceDeploymentEvent(
tagRule: getTagRulesForPGIEvent(),
deploymentName: "${env.RELEASE_PRODUCT} ${env.RELEASE_BUILD_VERSION} deployed",
deploymentVersion: "${env.RELEASE_BUILD_VERSION}",
deploymentProject: "${env.RELEASE_PRODUCT}",
customProperties : [
'Jenkins Build Number': "${env.BUILD_ID}",
'Approved by':'ACE'
]
)
}
}
}
}
}

def generateMetaData() {
String returnValue = ''

returnValue += 'FriendlyName=simplenode '
returnValue += 'SERVICE_TYPE=FRONTEND '
returnValue += 'Project=simpleproject '
returnValue += 'DesignDocument=https://simple-corp.com/stories/simplenodeservice '
returnValue += 'Tier=1 '
returnValue += 'Class=Gold '
returnValue += 'Purpose=ACE '
returnValue += "SCM=${env.GIT_URL} "
returnValue += "Branch=${env.GIT_BRANCH} "
returnValue += "Build=${env.RELEASE_BUILD_VERSION} "
returnValue += "Version=${env.RELEASE_VERSION} "
returnValue += "Image=${env.IMAGE_NAME}:${env.IMAGE_TAG} "
returnValue += "url=${env.RELEASE_PRODUCT}-${env.RELEASE_STAGE}.${env.INGRESS_DOMAIN}"
return returnValue
}

//
// Legacy tag rules function can be removed with availabilty of dta feature
//
def getTagRulesForPGIEvent() {
def tagMatchRules = [
[
'meTypes': ['PROCESS_GROUP_INSTANCE'],
tags: [
['context': 'ENVIRONMENT', 'key': 'DT_RELEASE_PRODUCT', 'value': "${env.RELEASE_PRODUCT}"],
['context': 'ENVIRONMENT', 'key': 'DT_RELEASE_STAGE', 'value': "${env.RELEASE_STAGE}"],
['context': 'ENVIRONMENT', 'key': 'DT_RELEASE_BUILD_VERSION', 'value': "${env.RELEASE_BUILD_VERSION}"]
]
]
]

return tagMatchRules
}
Loading

0 comments on commit 283d019

Please sign in to comment.