A simple DevOps Project (CI/CD) with Jenkins, Docker, and Ansible.
-
Developer Pushes Code:
- Developers push their code changes to a Git repository.
-
Jenkins Pulls Code:
- Jenkins is configured to pull the latest code from the Git repository whenever a change is detected.
-
Jenkins Builds Docker Image:
- Jenkins builds a Docker image from the pulled code.
-
Push Docker Image:
- The Docker image is pushed to a Docker registry for storage and further use.
-
Ansible Deployment:
- Ansible pulls the Docker image from the registry and deploys it to the development environment.
- Ansible can also push the image to other environments (e.g., staging, production).
- Jenkins: Ensure Jenkins is installed and running.
- Docker: Ensure Docker is installed and running.
- Ansible: Ensure Ansible is installed and configured.
- Git: Ensure Git is installed and your repository is set up.
-
Install Required Plugins:
- Docker Pipeline Plugin
- Git Plugin
- Ansible Plugin
-
Configure Jenkins Pipeline:
- Create a new pipeline job in Jenkins.
- Add your Git repository URL.
- Write a Jenkinsfile in your repository to define the build, push, and deployment steps.
- Dockerfile:
- Please make sure you have a Dockerfile in your repository that Jenkins will use to build the Docker image.
- Inventory and Playbook:
- Create an inventory file listing your target servers.
- Write an Ansible playbook to handle the deployment of the Docker image.
pipeline {
agent any
stages {
stage('building image') {
steps {
sh 'docker image build -t $JOB_NAME:v1.$BUILD_ID .'
sh 'docker image tag $JOB_NAME:v1.$BUILD_ID alilotfi/$JOB_NAME:latest'
}
}
stage('Ansible version') {
steps {
script {
sh 'ansible --version'
}
}
}
stage('Ansible Deploy') {
steps {
sh 'ansible-playbook -i /etc/ansible/hosts -u ubuntu /var/lib/jenkins/workspace/jenkins-docker-ansible/ansible/play.yml'
}
}
}
}
-
Trigger the Pipeline:
- Push code changes to your Git repository.
- Jenkins will automatically trigger the pipeline.
-
Monitor the Pipeline:
- Monitor the pipeline's progress in the Jenkins dashboard.
- Ensure each stage is completed successfully.
This setup provides a straightforward CI/CD pipeline leveraging Jenkins, Docker, and Ansible to automate code integration, build, and deployment processes. Customize the provided examples to fit your specific project needs.