Files
jenkins-pipelines/pipelines/Cloud/Apps-Backend/cloud-messenger-core-api.groovy
Rustam Tagaev 53c965f988 [DO-1239] add_backend_ci (!49)
Co-authored-by: Rustam Tagaev <rustam.tagaev@avroid.tech>
Reviewed-on: https://git.avroid.tech/DevOps/jenkins-pipelines/pulls/49
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>
2024-11-19 14:43:57 +03:00

89 lines
3.0 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/cloud-messenger-core-api.git'
String publishBranch = 'develop'
String dockerGroup = 'cloud'
String dockerProject = 'cloud-messenger-core-api'
String projectSettingFile = 'pyproject.toml'
Map gitVars = [:]
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
String imageName = "${env.JENKINS_DOCKER_REGISTRY}/" +
"${dockerGroup}/${dockerProject}:${version}-${gitVars.GIT_COMMIT.take(5)}"
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}
"""
}
}
}
}
}
}
}
}