Achieving Scalable and Flexible Deployment Pipelines
Purpose: Ensure the pipeline uses the latest code version
stage('Checkout Application') { steps { // Clone the application repository git url: 'https://github.com/AtakanG7/web-app', branch: 'main' // This step fetches the latest code from the specified Git repository } }
Purpose: Prepare Helm charts for deployment
stage('Clone Helm Chart Repository') { steps { // Clone the Helm chart repository sh "git clone ${HELM_REPO} helm-repo" // Add the Helm chart repository to the local Helm installation sh "helm repo add myrepo https://atakang7.github.io/gh-pages/docs" // These steps ensure that the necessary Helm charts are available for deployment } }
Purpose: Ensure correct versioning of the application
stage('Update Chart Versions') { steps { script { dir('helm-repo') { // Increment the version number env.NEW_VERSION = incrementVersion(currentVersion) // Update the Chart.yaml file with the new version sh "sed -i 's/version: .*/version: ${env.NEW_VERSION}/' ${CHART_PATH}/Chart.yaml" // This ensures that each deployment has a unique version number } } } }
Purpose: Prepare containerized application for deployment
stage('Build and Push Docker Image') { steps { script { // Build the Docker image with the new version tag sh "docker build -t atakan1927/web-app:${env.NEW_VERSION} ." // Push the newly built image to the Docker registry sh "docker push atakan1927/web-app:${env.NEW_VERSION}" // These steps create a new container image and make it available for deployment } } }
Purpose: Test new version in a controlled environment
stage('Mirror Production in Staging') { steps { script { dir('helm-repo') { def charts = sh(script: "ls charts", returnStdout: true).trim().split() for (def chart in charts) { sh """ helm upgrade --install ${chart}-staging charts/${chart} \ --namespace staging \ -f charts/${chart}/values-staging.yaml \ --wait """ } } } } }
Purpose: Ensure application quality and functionality
stage('Run Tests') { steps { echo "Running tests on staging environment..." // This is a placeholder for actual testing commands // In a real scenario, you would run various tests here to verify the application's functionality } }
Purpose: Human validation before live deployment
stage('Approval') { steps { // Wait for manual approval before proceeding input message: 'Approve deployment to production?', ok: 'Deploy' // This step requires human intervention to ensure that the deployment is ready for production } } stage('Deploy to Production') { steps { script { sh """ # Use Helm to upgrade or install the application in the production environment helm upgrade --install ${APP_NAME} ${CHART_PATH} \ --namespace production \ -f ${CHART_PATH}/values-production.yaml \ --set image.tag=${env.NEW_VERSION} # This command deploys the approved version to the production environment """ } } }
Thank you for your attention!