jenkins docker cicd pipeline set up
- Install Required Tools: Install Docker, Jenkins, Git, and VS Code on your local machine.
- Create a GitHub Repo: Store your Python application.
- Write a Simple Python App: app.py (Basic app).
- Write a Dockerfile: Defines how to containerize the app.
- Write a Jenkinsfile: CI/CD pipeline for build, test, and deploy.
- Run Jenkins in Docker: Start Jenkins and configure it.
- Connect Jenkins to GitHub: Set up a webhook to trigger builds.
- Deploy Locally: Build and run the container using Jenkins.
You need to install:
- Git
- Docker
- Jenkins
- host jenkins on the cloud or create a private tunnel from localhost to the internet so jenkins can communicate with your github repo
- a github repo to store all your code
Jenkins uses java so need to install java jdk on your local machine and then also download and install jenkins properly. Figure that out and then once its installed, go to your cmd
and run the following to get jenkins running on your local depending on where you installed it and saved it on your computer (keep track of that).
java -jar "C:\Program Files\Jenkins\jenkins.war"
Once it is up and running you should be able to go to your `services` on your computer and see jenkins running:
Go to Manage Jenkins → Manage Plugins → Install:
- 🟢 Git Plugin
- 🟢 GitHub Plugin
- 🟢 Pipeline Plugin
- 🟢 Docker Pipeline Plugin
jenkins_docker_pipeline/
│── Dockerfile
│── app.py
│── requirements.txt
│── Jenkinsfile
│── README.md
Take a look at the Jenkinsfile
. This file clones this repo, builds the docker image, and runs the container, each time it is triggered. Settings within the Jenkins dashboard needs to be configured to get this done.
Take a look at the Dockerfile
.
This Dockerfile:
Uses Python 3.12
Copies project files
Installs dependencies
Runs app.py on port 8080
Inside Jenkins:
- Create a New Job → Select Pipeline
- Pipeline Definition → Use Pipeline Script from SCM
- Set Repository URL → https://github.com/thatwonguy/jenkins_docker_pipeline.git
- Set Branch →
master
(make sure to select master or chooses the correct branch which requires more configurations) - Save & Build Now
This is where you either need to host jenkins on the cloud or use private tunneling to expose the port to on the internet some other way to allow for automatation to take place anytime a change is made to your master
branch.
ngrok http 8080
Whatever url you expose needs to be configured in Github:
Set GitHub Webhook
- Go to GitHub Repo → Settings → Webhooks
- Add Webhook:
- Payload URL:
https://your-url-where-to-localhost-etc/github-webhook/
(make sure the forward slash and "/github-webook/" appears at the end EXACTLY or you will get a302 error response
) - Content Type: application/json
- Trigger Events: Pushes
- Payload URL:
- Save & Test → Ensure 200 OK response.
✅ Jenkins Installed & Configured
✅ Docker Installed & Running in Jenkins
✅ Jenkins Pipeline with Docker
✅ GitHub Webhook Triggers Auto Builds
✅ ngrok Setup for Webhooks
🎉 Your Jenkins + Docker CI/CD Pipeline is Ready and should be working now! 🚀
To use Github Actions you need to simply create a yaml file in the .github/workflows/your_yaml_file.yml
and the instructions in the yaml will be executed on your repo! Check out the goodies in there, its an alternative to jenkins! One github action yaml file is a basic one and can be tested in local environment. The other one actually creates an artifact of this app and can be used for multi-stage deployment etc for enterprise level execution setups!