Share
Explore

Building our own CI CD Pipeline to learn the process

Consume this content in connection with this lab:

This lab workbook will be what we use to organize ourselves for the Project.
This lab workbook shows the workflows we use to combine:
A. Software Engineering: Deploying the code from our GitHub Repository. The technical aspect of writing and building the software, getting it running, and deploying our Application to a Server for users to connect to our application and send prompt queries to it.
B. Software project management aspect: Which is the business process methodologies of writing down all the requirements of our Project, and planning the work of getting it down and delivered.


image.png

Setting up a lab for students to build their own CI/CD pipeline using Python involves a few key steps that integrate both conceptual learning and practical application:
Conceptual Understanding:
Introduce the students to Continuous Integration (CI) and Continuous Deployment (CD) concepts.
Explain the importance of automation in software development life cycles.
Tools Overview:
Provide an overview of the tools involved, such as Git for version control, Jenkins for automation, Docker for containerization, and Ansible for configuration management.
Environment Setup:
Have students set up a virtual environment using VMWare or any other virtualization software.
Guide them through installing Python, Git, Jenkins, Docker, and Ansible on their virtual machines.
Version Control System Integration:
Teach students how to set up a Git repository and how to trigger builds using Git hooks upon commit events.
Pipeline Scripting:
Instruct students on writing Jenkins pipeline scripts using Python, which will define the build, test, and deploy stages.
megaphone

Creating a Jenkins pipeline script in Python involves writing a Jenkinsfile, which is a text file that contains the definition of a Jenkins Pipeline and is checked into source control. Here's a high-level description of what the code for a Jenkins pipeline might include for building, testing, and deploying a Python application:

Define Pipeline Stages:
Use pipeline block to define all the stages.
Create stages for Build, Test, and Deploy.
Build Stage:
Check out the source code from the Git repository.
Install dependencies using pip.
Test Stage:
Run unit tests using a testing framework like pytest.
Optionally include code for generating a test report.
Deploy Stage:
If the tests pass, deploy the application to a server or platform.
Use Ansible playbook or similar to manage deployment.
Post Actions:
Define post-build actions like sending notifications.
Here's a simplified snippet of what a Jenkinsfile could look like:
groovyCopy code
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'pip install -r requirements.txt'
}
}
stage('Test') {
steps {
sh 'pytest'
}
}
stage('Deploy') {
steps {
// An example of a conditional step for deployment
when {
branch 'main'
}
sh './deploy.sh'
}
}
}
post {
success {
// Code for notification of successful build
}
failure {
// Code for notification of failed build
}
}
}

This Jenkinsfile is written in Groovy scripting language which is used by Jenkins pipeline, but it is initiated and managed by your Python application's build, test, and deployment processes. The actual Python code would be in your application's source code and the scripts you might call from this Jenkinsfile (like deploy.sh).
Build Automation:
Demonstrate how to automate Python project builds using Jenkins and how to handle dependencies.
Testing:
Show students how to automate testing using Python testing frameworks and how test results can affect the pipeline.
Deployment:
Introduce containerization with Docker and orchestration.
Guide students through writing Ansible playbooks for deployment.
Monitoring & Feedback:
Discuss the importance of monitoring builds and deployments and setting up notification systems for feedback.
Lab Exercises:
Provide practical exercises where students can simulate commit events, write pipeline scripts, and automate the entire process from commit to deployment.
Project Assignment:
Assign a project where each student or group must set up a complete CI/CD pipeline for a simple Python application, documenting their process.
This setup allows students to learn by doing, giving them hands-on experience with the tools and practices that are crucial in modern software development.
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.