Files
jenkins-pipelines/pipelines/Cloud/Apps-Backend/msg-messenger-core-api.groovy
2025-02-10 16:34:33 +03:00

101 lines
3.6 KiB
Groovy

@Library('shared-lib') _
import tech.avroid.kube.PodTemplates
import tech.avroid.scm.Git
properties([
buildDiscarder(logRotator(artifactDaysToKeepStr: '',
artifactNumToKeepStr: '30',
daysToKeepStr: '',
numToKeepStr: '30')),
disableConcurrentBuilds()
])
Git git = new Git(this, env.JENKINS_GIT_CREDENTIALS_SSH)
String repoPath = 'Apps-Backend/msg-messenger-core-api.git'
String publishBranch = 'develop'
String dockerGroup = 'cloud'
String dockerProject = 'msg-messenger-core-api'
String projectSettingFile = 'pyproject.toml'
Map gitVars = [:]
String tag = ''
Map configuration = [
vaultUrl: env.JENKINS_VAULT_URL,
vaultCredentialId: env.JENKINS_VAULT_TOKEN,
engineVersion: 2
]
List dockerCreds = [
[path: 'team-devops/services/registry/Harbor/harbor.avroid.tech', engineVersion: 2,
secretValues:
[
[vaultKey: 'service.user.jenkins.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') {
gitVars = 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 ciUser = getProperty('service.user.jenkins.ci.login')
String dockerToken = getProperty('service.user.ci.token')
container('docker'){
Map props = readTOML file: projectSettingFile
String version = props.tool.poetry.version
tag = "${version}-${gitVars.GIT_COMMIT.take(5)}"
String imageName = "${env.JENKINS_DOCKER_REGISTRY}/" +
"${dockerGroup}/${dockerProject}:${tag}"
stage('build image'){
sh """#!/bin/sh
docker build --build-arg PIP_INDEX_URL=${env.JENKINS_PIP_INDEX_URL} \
-f Dockerfile -t ${imageName} .
"""
}
stage('push image'){
if (git.getBranch() == publishBranch){
sh """#!/bin/sh
docker login -u ${ciUser} -p '${dockerToken}' ${env.JENKINS_DOCKER_REGISTRY}
docker push ${imageName}
"""
}
}
stage('deploy application'){
if (git.getBranch() == publishBranch){
build job: 'Cloud/Deploy/Backend/msg-messenger-core-api-deploy',
parameters: [
string(name: 'ENV', value: 'DEV'),
string(name: 'APP_VERSION', value: tag)
],
wait: false
}
}
}
}
}
}
}
}