A simple application is developed to understand the DevOps CI/CD Pipeline
Before getting started, click here if you want to know what is CI/CD
CI/CD is a method to frequently deliver apps to customers by introducing automation into the stages of app development. The main concepts attributed to CI/CD are continuous integration, continuous delivery, and continuous deployment. CI/CD pipelines are designed for businesses that want to improve applications frequently and require a reliable delivery process. The added effort to standardize builds, develop tests, and automate deployments is the manufacturing process for deploying code changes.
In this project I pushed my project code to GitHub] which is linked with Jenkins, which is responsible to build, test and deploy it into production facilitating continuous integration and continuous delivery. In turn, the binaries generated from the build process will be stored in JFrog Artifactory. I developed a basic python application using Flask. I’ll walk you through the process and try to provide useful information to write code and serve it to your customers or friends. So Let’s get started!
Let’s start with a simple application. You can use this project or you can develop your own Flask Application.
Using the below commands you can run this application on your localhost.
pip install -r requirements.txt
python app.py
Our application will try to display a random message on our webpage when the user gave a string as input. Visit http://localhost:5000/username as shown below in the url.
We write code for our application and also the testcases that our application should pass. I wrote two testcases where the server status will be tested. You can explore Testing in Python to write your own testcases.
python test.py
Now we have the required files to run our application. But this project is local to our machine. So we are going to push our project or repository on GitHub.
GitHub, is a United States-based global company that provides hosting for software development version control using Git. In order to learn more about Git, Please visit my repository GitLearn. I used GitHub to upload my repository, you can use other tools as well GitLab, BitBucket, SourceFrog…
The main purpose of this step is to collaborate with our teammates and it allows your work to get out in front of the public as well. So whenever you want to change or add or delete any features you can simply change your code in your local machine and then push the changes to GitHub repository. Create a repository on GitHub and use the following commands to push your code remotely.
git init
git add *
git commit -m "commit message"
git remote add origin <url_of_your_repo>
git push origin master
Let’s say you want to add some features to your application which is already in the production stage. You will simply make the changes, write testcases for this new feature and push this feature to GitHub. Later CI/CD server which is linked with our repository will get triggered whenever a new commit is made by the user. It will build, test and deploy our application where the customer will able to use our new application.
We have our project on GitHub, but who is going to build or test and deploy it. We can do manually, but its not an ideal case to repeat the process for every new feature. So there is a need for Continous Integration. Jenkins is an open-source automation tool written in Java with plugins built for Continuous Integration purposes. Jenkins is used to build and test your software projects continuously making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build.
Create a Job on Jenkins using this tutorial. Also try to link Jenkins with your GitHub repository. While creating the Job add your GitHub repository url as shown below in the Source Management section.
In the current project I provided instructions to Jenkins, to build my python application, test it and upload the artifacts or binaries or by products to JFrog Artifactory. In order to use Jenkinsfile you need to select Pipeline option while creating while creating a Job.
In this pipeline , I’m not deploying application on sever, but when you build the Job you can use the applicayion in your localhost, port:5000. Check this tutorial for further details to use Jenkinsfile in pipeline. The Artifactory stage that used in the Jenkinsfile will be coverd below.
JFrog Artifactory is a tool designed to store the binary output of the build process for use in distribution and deployment. Artifactory provides support for a number of package formats such as Maven, Debian, NPM, Helm, Ruby, Python, and Docker.
We can store binaries of our application with different version and we can deploy or use them at any point.
choco install jfrog-cli
jfrog rt c rt-server --url=http://domain/artifactory --user=admin --password=password
jfrog rt u "path to your file" generic-local
Visit JFrog CLI for more commands.
You can deploy the application on any cloud platform or you can push the build image to docker hub.
I have used many online resources while creating the application and I would like to thank them. As I’m also in a learning stage, I would like to know your feedback and suggestions as well. So please contact me at: ritheeshbaradwaj@gmail.com.