[DO-1239] add_backend_ci (!48)
добавил pipeline для сборки cloud-messenger-backend-api Co-authored-by: Rustam Tagaev <rustam.tagaev@avroid.tech> Reviewed-on: https://git.avroid.tech/DevOps/jenkins-pipelines/pulls/48 Reviewed-by: Denis Patrakeev <denis.patrakeev@avroid.team> Co-authored-by: Rustam Tagaev <rustam.tagaev@avroid.team> Co-committed-by: Rustam Tagaev <rustam.tagaev@avroid.team>
This commit is contained in:
committed by
Denis Patrakeev
parent
4ed0e6f48a
commit
c4d5987382
@@ -35,7 +35,7 @@
|
||||
|
||||
Репозиторий для реализации методологии **IaC** для управления задачами в Jenkins
|
||||
c использованием плагина [Job DSL](https://plugins.jenkins.io/job-dsl/)
|
||||
[Ссылка](https://jenkins.devos.club/plugin/job-dsl/api-viewer/index.html) на локальную документацию.
|
||||
[Ссылка](https://jenkins.avroid.tech/plugin/job-dsl/api-viewer/index.html) на локальную документацию.
|
||||
|
||||
Джобы **dsl** должны называться через "_" пробелы и "-" запрещены, потому что у **job dsl** проблемы с парсингом.
|
||||
|
||||
|
||||
9
jobs-dsl/folders/Cloud.groovy
Normal file
9
jobs-dsl/folders/Cloud.groovy
Normal file
@@ -0,0 +1,9 @@
|
||||
folder('Cloud') {
|
||||
displayName('Cloud')
|
||||
description('Cloud projects')
|
||||
}
|
||||
|
||||
folder('Cloud/Apps-Backend') {
|
||||
displayName('Apps-Backend')
|
||||
description('Apps-Backend organization')
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
multibranchPipelineJob('Cloud/Apps-Backend/cloud-messenger-core-api') {
|
||||
description('cloud-messenger-core-api')
|
||||
displayName('cloud-messenger-core-api')
|
||||
factory {
|
||||
remoteJenkinsFileWorkflowBranchProjectFactory {
|
||||
localMarker('')
|
||||
matchBranches(true)
|
||||
fallbackBranch('master')
|
||||
lookupInParameters(false)
|
||||
remoteJenkinsFile('pipelines/Cloud/Apps-Backend/cloud-messenger-core-api.groovy')
|
||||
remoteJenkinsFileSCM {
|
||||
gitSCM {
|
||||
userRemoteConfigs {
|
||||
userRemoteConfig {
|
||||
url('https://git.avroid.tech/DevOps/jenkins-pipelines.git')
|
||||
credentialsId('user-jenkins-in-gitea')
|
||||
name('')
|
||||
refspec('')
|
||||
}
|
||||
}
|
||||
gitTool('')
|
||||
browser {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
branchSources {
|
||||
branchSource {
|
||||
source {
|
||||
giteaSCMSource {
|
||||
serverUrl('https://git.avroid.tech')
|
||||
repoOwner('Apps-Backend')
|
||||
repository('cloud-messenger-core-api')
|
||||
credentialsId('user-jenkins-in-gitea')
|
||||
id('Apps-Backend/cloud-messenger-core-api')
|
||||
traits {
|
||||
giteaBranchDiscovery {
|
||||
// 1 Exclude branches that are also filed as PRs
|
||||
// 2 Only branches that are also filed as PRs
|
||||
// 3 Only branches that are also filed as PRs or main
|
||||
// 4 All branches
|
||||
strategyId(1)
|
||||
}
|
||||
|
||||
giteaPullRequestDiscovery {
|
||||
// 1 Merging the pull request with the current target branch revision
|
||||
// 2 The current pull request revision
|
||||
// 3 Both the current pull request revision and the pull request merged with
|
||||
// the current target branch revision
|
||||
strategyId(2)
|
||||
}
|
||||
|
||||
giteaForkDiscovery {
|
||||
// 1 Merging the pull request with the current target branch revision
|
||||
// 2 The current pull request revision
|
||||
// 3 Both the current pull request revision and the pull request merged with
|
||||
// the current target branch revision
|
||||
strategyId(2)
|
||||
trust {
|
||||
giteaTrustContributors()
|
||||
}
|
||||
}
|
||||
|
||||
giteaTagDiscovery()
|
||||
pruneStaleBranch()
|
||||
pruneStaleTag()
|
||||
|
||||
refSpecs {
|
||||
templates {
|
||||
refSpecTemplate {
|
||||
value('+refs/heads/*:refs/remotes/@{remote}/*')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
orphanedItemStrategy {
|
||||
discardOldItems {
|
||||
numToKeep(20)
|
||||
}
|
||||
|
||||
defaultOrphanedItemStrategy {
|
||||
pruneDeadBranches(true)
|
||||
numToKeepStr('10')
|
||||
daysToKeepStr('10')
|
||||
}
|
||||
}
|
||||
}
|
||||
77
pipelines/Cloud/Apps-Backend/cloud-messenger-core-api.groovy
Normal file
77
pipelines/Cloud/Apps-Backend/cloud-messenger-core-api.groovy
Normal file
@@ -0,0 +1,77 @@
|
||||
@Library('shared-lib') _
|
||||
|
||||
import tech.avroid.kube.PodTemplates
|
||||
import tech.avroid.scm.Git
|
||||
|
||||
Git git = new Git(this, env.JENKINS_GIT_CREDENTIALS_SSH)
|
||||
|
||||
String repoPath = 'Apps-Backend/cloud-messenger-core-api.git'
|
||||
String ciUser = 'robot\$\$ci'
|
||||
String publishBranch = 'develop'
|
||||
|
||||
Map configuration = [
|
||||
vaultUrl: 'https://vault.avroid.tech',
|
||||
vaultCredentialId: 'vault-role',
|
||||
engineVersion: 2
|
||||
]
|
||||
|
||||
List dockerCreds = [
|
||||
[path: 'team-devops/services/registry/Harbor/harbor.avroid.tech', engineVersion: 2,
|
||||
secretValues:
|
||||
[
|
||||
[vaultKey: 'service.user.ci.login'],
|
||||
[vaultKey: 'service.user.ci.token'],
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
slaveTemplates = new PodTemplates(this, env.JENKINS_DOCKER_REGISTRY, ["${env.JENKINS_K8S_HARBOR_SECRET}"])
|
||||
|
||||
slaveTemplates.jnlp {
|
||||
slaveTemplates.poetry {
|
||||
slaveTemplates.docker {
|
||||
node(POD_LABEL){
|
||||
|
||||
stage('Download sources') {
|
||||
git.clone([urlRepo: "${env.JENKINS_GIT_REPOSITORY_SSH_URL}/${repoPath}",
|
||||
branch: git.getBranch()])
|
||||
}
|
||||
|
||||
stage('prepare app'){
|
||||
container('poetry'){
|
||||
sh 'make setup'
|
||||
}
|
||||
}
|
||||
|
||||
withVault([configuration: configuration, vaultSecrets: dockerCreds]) {
|
||||
String dockerToken = getProperty('service.user.ci.token')
|
||||
String makeArgs = " DOCKER_REGISTRY='${env.JENKINS_DOCKER_REGISTRY}'" +
|
||||
" DOCKER_REGISTRY_USER='${ciUser}'" +
|
||||
" DOCKER_REGISTRY_PASSWORD='${dockerToken}'"
|
||||
|
||||
container('docker'){
|
||||
stage('build image'){
|
||||
sh """#!/bin/sh
|
||||
apk add make
|
||||
make build-image ${makeArgs}
|
||||
"""
|
||||
}
|
||||
|
||||
stage('push image'){
|
||||
sh """#!/bin/sh
|
||||
apk add make
|
||||
make build-image ${makeArgs}
|
||||
"""
|
||||
|
||||
if (git.getBranch() == publishBranch){
|
||||
sh """#!/bin/sh
|
||||
make push-image ${makeArgs}
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user