Skip to content

Commit

Permalink
feat: add helm upgrade CD pipeline for rest api
Browse files Browse the repository at this point in the history
fixes issue #40
  • Loading branch information
sydrawat01 authored and karanwadhwa committed Dec 1, 2023
1 parent 7bfd925 commit 3dae460
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ pipeline {
tools { nodejs "node" }
environment {
GH_TOKEN = credentials('jenkins-pat')
SSH_CREDENTIAL_ID = credentials('gke-bastion') // bastion sshagent
BASTION_IP = credentials('bastion-ip') // bastion host ip address
USERNAME = credentials('bastion-username') // bastion host username
PRIVATE_KEY = credentials('private-key') // ssh key for bastion
K8S_SA_JSON = credentials('k8s-sa-json') // json file for K8S SA
ROBOCOP = credentials('robocop') // image pull secrets for quay.io
GKE_CLUSTER_NAME = credentials('gke-cluster-name') // cluster name
GKE_CLUSTER_REGION = credentials('gke-cluster-region') // cluster region
GKE_PROJECT_NAME = credentials('gke-project-name') // GKE project name
}
stages {
stage('Clone repository') {
Expand Down Expand Up @@ -44,6 +53,31 @@ pipeline {
}
}
}
stage('Helm Upgrade @ GKE') {
when {
branch 'master'
}
steps {
sshagent(['gke-bastion']) {
sh '''
cat $PRIVATE_KEY > gke_compute
cat $K8S_SA_JSON > sa.json
scp -i gke_compute sa.json $USERNAME@$BASTION_IP:/home/$USERNAME
ssh -i gke-compute -o StrictHostKeyChecking=no $USERNAME@$BASTION_IP ./download-tarball.sh webapp-helm-chart
ssh -i gke-compute -o StrictHostKeyChecking=no $USERNAME@$BASTION_IP gcloud auth activate-service-account --key-file=sa.json
ssh -i gke-compute -o StrictHostKeyChecking=no $USERNAME@$BASTION_IP gcloud config configurations list
ssh -i gke-compute -o StrictHostKeyChecking=no $USERNAME@$BASTION_IP gcloud container clusters get-credentials $GKE_CLUSTER_NAME --region $GKE_CLUSTER_REGION --project $GKE_PROJECT_NAME
ssh -i gke-compute -o StrictHostKeyChecking=no $USERNAME@$BASTION_IP kubectl config view
ssh -i gke-compute -o StrictHostKeyChecking=no $USERNAME@$BASTION_IP kubectl get ns
ssh -i gke-compute -o StrictHostKeyChecking=no $USERNAME@$BASTION_IP helm ls -n webapp -a
ssh -i gke-compute -o StrictHostKeyChecking=no $USERNAME@$BASTION_IP mv csye7125-fall2023* webapp-helm-chart
ssh -i gke-compute -o StrictHostKeyChecking=no $USERNAME@$BASTION_IP helm upgrade -n webapp webapp-helm-release webapp-helm-chart --set=imagePullSecrets.dockerConfig=$ROBOCOP
ssh -i gke-compute -o StrictHostKeyChecking=no $USERNAME@$BASTION_IP helm ls -n webapp -a
ssh -i gke-compute -o StrictHostKeyChecking=no $USERNAME@$BASTION_IP rm -rf webapp-helm-chart*
'''
}
}
}
}
post {
always {
Expand Down

0 comments on commit 3dae460

Please sign in to comment.