Skip to content

Commit

Permalink
Revamp Jenkins pipeline script
Browse files Browse the repository at this point in the history
* Modified CI/CD workflow in the Jenkins pipeline script.
* Integrated Jenkins pipeline with Docker and Ansible to execute CI/CD pipeline.
* Removed Docker, Supervisor, and other configurations from the repository.
  • Loading branch information
JohnSundarraj committed Dec 15, 2023
1 parent 57c4dd0 commit 7b835eb
Show file tree
Hide file tree
Showing 16 changed files with 120 additions and 336 deletions.
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
downloads/jdk-*
downloads/*.rpm
downloads/*.deb
downloads/*.tar.gz
downloads/*.zip
downloads/*.jar
secret/*.pem
secret/*.pub
secret/node*
tmp/*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Kickstart Jenkins
The ultimate aim of this Jenkins starter-kit is to help you run build/test of sample CRM app using Jenkins freestyle and pipeline projects.
Our Jenkins starter-kit repository contains Jenkins pipeline templates and other configurations needed to implement CI/CD workflow for workloads using Jenkins.
1 change: 0 additions & 1 deletion conf/security-limits.conf

This file was deleted.

4 changes: 0 additions & 4 deletions data/.gitignore

This file was deleted.

39 changes: 0 additions & 39 deletions docker/compose/main.yml

This file was deleted.

4 changes: 0 additions & 4 deletions docker/image/context/jenkins/.gitignore

This file was deleted.

4 changes: 0 additions & 4 deletions docker/image/context/jenkins/secret/.gitignore

This file was deleted.

53 changes: 0 additions & 53 deletions docker/image/jenkins.dockerfile

This file was deleted.

1 change: 0 additions & 1 deletion downloads/readme.txt

This file was deleted.

4 changes: 0 additions & 4 deletions log/.gitignore

This file was deleted.

75 changes: 0 additions & 75 deletions pipeline/crm-stack.jenkinsfile

This file was deleted.

118 changes: 118 additions & 0 deletions pipeline/crm.jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
pipeline {
agent any
parameters {
choice(
name:'test_environment',choices:['qaa','qab'],description:'Testing environment'
)
}
environment {
TEST_ENVIRONMENT=params.test_environment.toUpperCase()
}
stages {
stage('CI: Download sources') {
steps {
sh(
script:'git clone https://github.com/sloopstash/kickstart-docker.git kickstart-docker',
returnStatus:true
)
sh(
script:'git clone https://github.com/sloopstash/kickstart-ansible.git kickstart-ansible',
returnStatus:true
)
}
}
stage('CI: Build OCI images') {
steps {
dir('kickstart-docker') {
sh 'sudo docker image build -t sloopstash/base:v1.1.1 -f image/base/1.1.1/amazon-linux-2.dockerfile image/base/1.1.1/context'
sh 'sudo docker image build -t sloopstash/nginx:v1.14.0 -f image/nginx/1.14.0/amazon-linux-2.dockerfile image/nginx/1.14.0/context'
sh 'sudo docker image build -t sloopstash/python:v2.7 -f image/python/2.7/amazon-linux-2.dockerfile image/python/2.7/context'
sh 'sudo docker image build -t sloopstash/redis:v4.0.9 -f image/redis/4.0.9/amazon-linux-2.dockerfile image/redis/4.0.9/context'
}
}
}
stage('CI: Bootstrap testing environment') {
steps {
dir('kickstart-docker') {
sh "sudo docker compose -f compose/crm.yml --env-file compose/${TEST_ENVIRONMENT}.env -p sloopstash-${params.test_environment}-crm up -d"
sh "sudo docker container exec sloopstash-${params.test_environment}-crm-app-1 pip install pytest"
}
}
}
stage('CI: Execute test cases') {
environment {
APP_SOURCE='/opt/app/source'
}
steps {
sh "sudo docker container exec --workdir ${APP_SOURCE} sloopstash-${params.test_environment}-crm-app-1 pytest --junitxml=reports.xml script/test/main.py"
}
post {
// always {
// junit 'reports.xml'
// }
success {
input 'App testing has been successful. Do you want to proceed deployment in staging environment?'
}
}
}
stage('CD: Bootstrap staging environment') {
steps {
dir('kickstart-ansible') {
sh 'sudo docker compose -f docker/compose/crm.yml --env-file docker/compose/STG.env -p sloopstash-stg-crm up -d --scale app=3 --scale nginx=2'
}
}
}
stage('CD: Execute deployment') {
steps {
dir('kickstart-ansible') {
ansiblePlaybook(
credentialsId:'ansible-node-ssh',
playbook:'playbook/redis.yml',
inventory:'inventory/stg',
tags:'setup,configure,stop,start'
)
ansiblePlaybook(
credentialsId:'ansible-node-ssh',
playbook:'playbook/crm/app.yml',
inventory:'inventory/stg',
tags:'setup,update,configure,stop,start',
limit:'sloopstash-stg-crm-app-1'
)
ansiblePlaybook(
credentialsId:'ansible-node-ssh',
playbook:'playbook/nginx.yml',
inventory:'inventory/stg',
tags:'setup,update,configure,stop,start',
limit:'sloopstash-stg-crm-nginx-1'
)
}
}
post {
success {
input 'Deployment has been successful. Do you want to proceed deployment in production environment?'
}
}
}
}
post {
always {
dir('kickstart-docker') {
sh "sudo docker compose -f compose/crm.yml --env-file compose/${TEST_ENVIRONMENT}.env -p sloopstash-${params.test_environment}-crm down"
}
dir('kickstart-ansible') {
sh 'sudo docker compose -f docker/compose/crm.yml --env-file docker/compose/STG.env -p sloopstash-stg-crm down'
}
emailext(
subject:'Jenkins: ${env.JOB_NAME} - ${currentBuild.currentResult}',
body:'${env.BUILD_NUMBER} ${env.JOB_NAME} execution ${currentBuild.currentResult}.\n Know more at ${env.BUILD_URL}.',
recipientProviders:[[$class:'DevelopersRecipientProvider'],[$class:'RequesterRecipientProvider']]
)
}
success {
cleanWs(
deleteDirs:true,
disableDeferredWipeout:true
)
}
}
}
7 changes: 0 additions & 7 deletions supervisor/conf/jenkins.ini

This file was deleted.

Loading

0 comments on commit 7b835eb

Please sign in to comment.