[DO-1378] add_ci_for_openresty (!55)
cloud openresty deploy Co-authored-by: Rustam Tagaev <rustam.tagaev@avroid.tech> Reviewed-on: https://git.avroid.tech/DevOps/jenkins-pipelines/pulls/55 Reviewed-by: Denis Patrakeev <denis.patrakeev@avroid.team> Reviewed-by: Stanislav Gabenov <stanislav.gabenov@avroid.team>
This commit is contained in:
@@ -7,3 +7,8 @@ folder('Cloud/Apps-Backend') {
|
|||||||
displayName('Apps-Backend')
|
displayName('Apps-Backend')
|
||||||
description('Apps-Backend organization')
|
description('Apps-Backend organization')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
folder('Cloud/Deploy') {
|
||||||
|
displayName('Deploy')
|
||||||
|
description('Deploy jobs')
|
||||||
|
}
|
||||||
|
|||||||
25
jobs-dsl/jobs/Cloud/Deploy/openresty_deploy.groovy
Normal file
25
jobs-dsl/jobs/Cloud/Deploy/openresty_deploy.groovy
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
pipelineJob('Cloud/Deploy/openresty-deploy') {
|
||||||
|
logRotator {
|
||||||
|
numToKeep(10)
|
||||||
|
artifactNumToKeep(10)
|
||||||
|
}
|
||||||
|
|
||||||
|
definition {
|
||||||
|
cpsScm {
|
||||||
|
scm {
|
||||||
|
git {
|
||||||
|
remote {
|
||||||
|
url("${JENKINS_GIT_REPOSITORY_SSH_URL}/DevOps/jenkins-pipelines.git")
|
||||||
|
credentials("${JENKINS_GIT_CREDENTIALS_SSH}")
|
||||||
|
}
|
||||||
|
branch('master')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scriptPath('pipelines/Cloud/Deploy/openresty-deploy.groovy')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
properties {
|
||||||
|
disableConcurrentBuilds()
|
||||||
|
}
|
||||||
|
}
|
||||||
85
pipelines/Cloud/Deploy/openresty-deploy.groovy
Normal file
85
pipelines/Cloud/Deploy/openresty-deploy.groovy
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
@Library('shared-lib') _
|
||||||
|
|
||||||
|
import tech.avroid.kube.PodTemplates
|
||||||
|
import tech.avroid.scm.Git
|
||||||
|
import tech.avroid.jenkins.Notifications
|
||||||
|
import tech.avroid.jenkins.Jenkins
|
||||||
|
|
||||||
|
properties([
|
||||||
|
buildDiscarder(logRotator(artifactDaysToKeepStr: '',
|
||||||
|
artifactNumToKeepStr: '10',
|
||||||
|
daysToKeepStr: '',
|
||||||
|
numToKeepStr: '10')),
|
||||||
|
disableConcurrentBuilds()
|
||||||
|
])
|
||||||
|
|
||||||
|
String repoPath = 'Apps-Backend/helm-values.git'
|
||||||
|
String branch = 'master'
|
||||||
|
String valuesPath = 'avroid.local/api-gateway/openresty'
|
||||||
|
String namespace = 'api-gateway'
|
||||||
|
String helmChart = 'openresty'
|
||||||
|
String helmRepoPath = 'avroid/openresty'
|
||||||
|
|
||||||
|
Map configuration = [
|
||||||
|
vaultUrl: env.JENKINS_VAULT_URL,
|
||||||
|
vaultCredentialId: 'vault-role',
|
||||||
|
engineVersion: 2
|
||||||
|
]
|
||||||
|
|
||||||
|
List dockerCreds = [
|
||||||
|
[path: 'team-devops/services/ci-cd/Jenkins/jenkins.avroid.tech', engineVersion: 2,
|
||||||
|
secretValues:
|
||||||
|
[
|
||||||
|
[vaultKey: 'k8s_jenkins_deploy_token'],
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
Git git = new Git(this, env.JENKINS_GIT_CREDENTIALS_SSH)
|
||||||
|
PodTemplates slaveTemplates = new PodTemplates(this, env.JENKINS_DOCKER_REGISTRY, ["${env.JENKINS_K8S_HARBOR_SECRET}"])
|
||||||
|
|
||||||
|
slaveTemplates.jnlp {
|
||||||
|
slaveTemplates.helm {
|
||||||
|
slaveTemplates.kubectl {
|
||||||
|
try {
|
||||||
|
node(POD_LABEL){
|
||||||
|
withVault([configuration: configuration, vaultSecrets: dockerCreds]) {
|
||||||
|
stage('get repo with values'){
|
||||||
|
gitVars = git.clone([urlRepo: "${env.JENKINS_GIT_REPOSITORY_SSH_URL}/${repoPath}",
|
||||||
|
branch: branch])
|
||||||
|
}
|
||||||
|
container('helm'){
|
||||||
|
stage('deploy'){
|
||||||
|
dir(valuesPath){
|
||||||
|
sh """#!/bin/sh
|
||||||
|
helm repo add avroid ${env.JENKINS_NEXUS_URL}/repository/devops-helm-release
|
||||||
|
helm -n ${namespace} upgrade -f values.yaml --install ${helmChart} ${helmRepoPath}
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(err) {
|
||||||
|
errorMessage = err.getMessage()
|
||||||
|
|
||||||
|
println 'ERROR: ' + errorMessage
|
||||||
|
|
||||||
|
currentBuild.result = 'FAILURE'
|
||||||
|
|
||||||
|
String currentBuildUser = Jenkins.GetCurrentBuildUser(script: this)
|
||||||
|
String emailSubject = "${currentBuild.currentResult}. " +
|
||||||
|
"Pipeline task: ${currentBuild.fullDisplayName}"
|
||||||
|
|
||||||
|
Notifications.email(
|
||||||
|
script: this,
|
||||||
|
subject: emailSubject,
|
||||||
|
errorString: errorMessage,
|
||||||
|
recipientProviders: [],
|
||||||
|
to: "${currentBuildUser}@avroid.team"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user