Skip to content

Commit

Permalink
rework CI for helm to merge release and test job #4
Browse files Browse the repository at this point in the history
  • Loading branch information
abychko committed Oct 21, 2024
1 parent 3b41ddf commit 45aa5c0
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 0 deletions.
104 changes: 104 additions & 0 deletions .jenkins/helm-ci-job.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
pipeline {

agent { label 'srcbuild' }

options {
timeout(time: 10, unit: 'MINUTES')
}

environment {
RH_VERSION = "8"
DOCKERHUBCREDS = credentials('DockerHub')
HELM_VER="v3.15.0"
KUBECTL_VER="v1.30.1"
HELM_PROJECT="mysql-galera"
IMAGE_TAG = "8.0.39"
MYSQL_ROOT_PASSWORD="Oohiechohr8xooTh"
MYSQL_USER="admin"
MYSQL_USER_PASSWORD="LohP4upho0oephah"
}

stages {
stage ('Helm Release') {
steps {
echo "Making Helm release from git: " + env.GIT_BRANCH
script{
currentBuild.description = "Branch: ${GIT_TARGET}"
version = sh(script: "grep appVersion mysql-galera/helm/Chart.yaml | awk '{print \$NF}' | sed -e 's:\"::g'",
returnStdout: true).trim()
directory = "mysql-galera-" + version + "-" + env.RELEASENUM
tarball = directory + ".tar.gz"
sh """
set -x
cp -a mysql-galera/helm $directory
pushd $directory
./set_values.sh \
--rootpw "@@SET_ME@@" \
--dbuser "@@SET_ME@@" \
--userpw "@@SET_ME@@"
rm -vf values.tmpl set_values.sh
popd
/usr/bin/tar -czf $tarball $directory
"""
}
archiveArtifacts artifacts: tarball
}
}
stage('Prepare minikube') {
steps {
sh "sudo apt-get update; sudo apt-get -y install gawk mysql-client-core-8.0"
sh '''
if [[ ! -x /usr/local/bin/helm ]]; then
wget https://get.helm.sh/helm-${HELM_VER}-linux-amd64.tar.gz
tar -xf helm-${HELM_VER}-linux-amd64.tar.gz --strip-components=1
sudo chmod +x ./helm
sudo mv -vf ./helm /usr/local/bin
fi
'''
sh '''
if [[ ! -x /usr/local/bin/kubectl ]]; then
wget https://dl.k8s.io/release/${KUBECTL_VER}/bin/linux/amd64/kubectl
sudo chmod +x ./kubectl
sudo mv -vf ./kubectl /usr/local/bin
fi
'''
sh '''
if [[ ! -x /usr/local/bin/minikube ]]; then
wget https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 -O minikube
sudo chmod +x minikube
sudo mv -vf minikube /usr/local/bin
fi
'''
sh "docker login --username ${DOCKERHUBCREDS_USR} --password ${DOCKERHUBCREDS_PSW}"
sh "docker version ||:"
sh "helm version ||:"
sh "kubectl version ||:"
sh "minikube version ||:"
echo "Preparing Minikube..."
sh "minikube delete"
sh "minikube start"
}
}
stage('Docker Build') {
steps {
sh "docker login --username ${DOCKERHUBCREDS_USR} --password ${DOCKERHUBCREDS_PSW}"
sh '''
docker build \
--no-cache --pull \
--build-arg RH_VERSION=${RH_VERSION} \
--build-arg MYSQL_RPM_VERSION=${MYSQL_RPM_VERSION} \
-t ${REPOSITORY}:${IMAGE_TAG} -f mysql-galera/image/Dockerfile mysql-galera/image
docker push ${REPOSITORY}:${IMAGE_TAG}
'''
cleanWs()
}
}
stage('Helm Installation') {
steps {
copyArtifacts filter: tarball, fingerprintArtifacts: true, flatten: true,
projectName: 'helm-ci-job', selector: specific(currentBuild.number.toString())

}
}
}
}
36 changes: 36 additions & 0 deletions .jenkins/helm-ci-job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
- job:
name: helm-ci-job
project-type: pipeline
sandbox: true
properties:
- build-discarder:
num-to-keep: 10
parameters:
- choice:
name: REPOSITORY
choices:
- "codership/mysql-galera-test"
- "codership/mysql-galera"
description: "Devel or public repository"
- string:
name: MYSQL_RPM_VERSION
default: "8.0.39-26.20"
description: "MYSQL RPM version"
- string:
name: RELEASENUM
default: "1"
description: "Package version"
- string:
name: GIT_TARGET
default: "pipeline-merge"
description: "Branch, Tag or commit hash"
pipeline-scm:
scm:
- git:
url: git@github.com:codership/containers.git
credentials-id: '4767db11-ae93-4aaf-91f9-3b9c728b5249'
branches:
- ${{GIT_TARGET}}
clean: true
script-path: .jenkins/helm-ci-job.groovy
lightweight-checkout: true

0 comments on commit 45aa5c0

Please sign in to comment.