2025-02-17 10:14:40 +00:00
package com . freeleaps . devops
class ArgoApplicationVersionUpdater {
def steps
def workspace
2025-02-17 14:13:52 +00:00
def configurations
2025-02-17 10:14:40 +00:00
2025-02-17 14:13:52 +00:00
ArgoApplicationVersionUpdater ( steps , configurations ) {
2025-02-17 10:14:40 +00:00
this . steps = steps
2025-02-17 14:13:52 +00:00
this . configurations = configurations
2025-02-17 13:01:03 +00:00
this . workspace = steps . env . WORKSPACE
2025-02-17 10:14:40 +00:00
}
def update ( environmentSlug , component ) {
2025-02-17 14:13:52 +00:00
steps . log . info ( "ArgoApplicationVersionUpdater" , "[${environmentSlug}] Update Argo application image version to ${steps.env.BUILD_IMAGE_VERSION} for ${component.name}..." )
2025-02-17 17:31:47 +00:00
steps . log . info ( "ArgoApplicationVersionUpdater" , "[${environmentSlug}] Pull freeleaps-ops repository to workspace..." )
2025-02-17 10:14:40 +00:00
2025-02-17 17:31:47 +00:00
steps . dir ( "${workspace}" ) {
steps . git branch: 'master' , credentialsId: 'freeleaps-ops-credentials' , url: 'https://freeleaps@dev.azure.com/freeleaps/freeleaps-ops/_git/freeleaps-ops'
}
steps . dir ( "${workspace}" ) {
2025-02-17 17:52:37 +00:00
def valuesFile = "./${configurations.serviceName}/helm-pkg/${configurations.serviceName}/values.${environmentSlug}.yaml"
2025-02-17 18:33:12 +00:00
def data = steps . readYaml ( file: valuesFile )
2025-02-17 18:18:04 +00:00
data [ component . name ] . image . registry = steps . env . BUILD_IMAGE_REGISTRY
data [ component . name ] . image . repository = steps . env . BUILD_IMAGE_REPOSITORY
data [ component . name ] . image . tag = steps . env . BUILD_IMAGE_VERSION
data [ component . name ] . image . name = steps . env . BUILD_IMAGE_NAME
2025-02-17 18:54:19 +00:00
steps . writeYaml ( file: valuesFile , data: data , overwrite: true )
2025-02-17 17:31:47 +00:00
steps . withCredentials ( [ steps . usernamePassword ( credentialsId: 'freeleaps-ops-credentials' , passwordVariable: 'OPS_GIT_PASSWORD' , usernameVariable: 'OPS_GIT_USERNAME' ) ] ) {
steps . sh "" "
2025-02-17 19:15:14 +00:00
echo "Install required tools for git..."
apt - get - y update & & apt - get install - y - - no - install - recommends git apt - transport - https ca - certificates curl wget gnupg
echo "Configure git user..."
2025-02-17 17:31:47 +00:00
git config user . name "freeleaps-gitops-bot"
git config user . email "gitops@mathmast.com"
2025-02-17 19:15:14 +00:00
echo "Add and commit changes..."
2025-02-17 19:04:42 +00:00
git remote add ci_origin https: //${steps.env.OPS_GIT_USERNAME}:${steps.env.OPS_GIT_PASSWORD}@dev.azure.com/freeleaps/freeleaps-ops/_git/freeleaps-ops
2025-02-17 17:31:47 +00:00
git add $ { valuesFile }
git commit - m "ci(bump): bump ${component.name} image version for ${environmentSlug} to ${steps.env.BUILD_IMAGE_VERSION}"
2025-02-17 19:15:14 +00:00
echo "Push changes to freeleaps-ops repository..."
2025-02-17 17:31:47 +00:00
git push ci_origin HEAD: master
2025-02-17 19:15:14 +00:00
echo "Done."
2025-02-17 17:31:47 +00:00
"" "
steps . log . info ( "ArgoApplicationVersionUpdater" , "[${environmentSlug}] ${component.name} image version bump to ${steps.env.BUILD_IMAGE_VERSION}" )
}
2025-02-17 10:14:40 +00:00
}
}
}