[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>
This commit is contained in:
Rustam Tagaev
2024-11-19 14:43:57 +03:00
committed by Denis Patrakeev
parent c4d5987382
commit 53c965f988

View File

@@ -3,15 +3,26 @@
import tech.avroid.kube.PodTemplates import tech.avroid.kube.PodTemplates
import tech.avroid.scm.Git 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) Git git = new Git(this, env.JENKINS_GIT_CREDENTIALS_SSH)
String repoPath = 'Apps-Backend/cloud-messenger-core-api.git' String repoPath = 'Apps-Backend/cloud-messenger-core-api.git'
String ciUser = 'robot\$\$ci'
String publishBranch = 'develop' String publishBranch = 'develop'
String dockerGroup = 'cloud'
String dockerProject = 'cloud-messenger-core-api'
String projectSettingFile = 'pyproject.toml'
Map gitVars = [:]
Map configuration = [ Map configuration = [
vaultUrl: 'https://vault.avroid.tech', vaultUrl: env.JENKINS_VAULT_URL,
vaultCredentialId: 'vault-role', vaultCredentialId: env.JENKINS_VAULT_TOKEN,
engineVersion: 2 engineVersion: 2
] ]
@@ -19,7 +30,7 @@ List dockerCreds = [
[path: 'team-devops/services/registry/Harbor/harbor.avroid.tech', engineVersion: 2, [path: 'team-devops/services/registry/Harbor/harbor.avroid.tech', engineVersion: 2,
secretValues: secretValues:
[ [
[vaultKey: 'service.user.ci.login'], [vaultKey: 'service.user.jenkins.ci.login'],
[vaultKey: 'service.user.ci.token'], [vaultKey: 'service.user.ci.token'],
] ]
] ]
@@ -33,8 +44,8 @@ slaveTemplates.jnlp {
node(POD_LABEL){ node(POD_LABEL){
stage('Download sources') { stage('Download sources') {
git.clone([urlRepo: "${env.JENKINS_GIT_REPOSITORY_SSH_URL}/${repoPath}", gitVars = git.clone([urlRepo: "${env.JENKINS_GIT_REPOSITORY_SSH_URL}/${repoPath}",
branch: git.getBranch()]) branch: git.getBranch()])
} }
stage('prepare app'){ stage('prepare app'){
@@ -44,28 +55,28 @@ slaveTemplates.jnlp {
} }
withVault([configuration: configuration, vaultSecrets: dockerCreds]) { withVault([configuration: configuration, vaultSecrets: dockerCreds]) {
String ciUser = getProperty('service.user.jenkins.ci.login')
String dockerToken = getProperty('service.user.ci.token') 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'){ 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'){ stage('build image'){
sh """#!/bin/sh sh """#!/bin/sh
apk add make docker build --build-arg PIP_INDEX_URL=${env.JENKINS_PIP_INDEX_URL} \
make build-image ${makeArgs} -f Dockerfile -t ${imageName} .
""" """
} }
stage('push image'){ stage('push image'){
sh """#!/bin/sh
apk add make
make build-image ${makeArgs}
"""
if (git.getBranch() == publishBranch){ if (git.getBranch() == publishBranch){
sh """#!/bin/sh sh """#!/bin/sh
make push-image ${makeArgs} docker login -u ${ciUser} -p '${dockerToken}' ${env.JENKINS_DOCKER_REGISTRY}
docker push ${imageName}
""" """
} }
} }