This project demonstrates how to deploy a Python application on AWS EC2 using Jenkins Pipeline and GitHub.
-
Server 1 (Jenkins Server)
- Runs Jenkins.
- Pulls source code from GitHub.
- Deploys application to remote EC2 server via SSH.
-
Server 2 (App Server)
- Runs the Python application.
- Receives code and dependencies from Jenkins.
-
GitHub
- Stores the application code and Jenkins pipeline (
Jenkinsfile).
- Stores the application code and Jenkins pipeline (
-
Two AWS EC2 instances:
- Jenkins Server (Ubuntu 22.04 recommended).
- Python App Server (Ubuntu 22.04 with Python 3.12+).
-
Installed on Jenkins Server:
- Jenkins
- Git
- SSH keys (added to Jenkins credentials)
-
Installed on App Server:
- Python 3.12+
python3-pip,python3-venv- OpenSSH (
openssh-server,openssh-client) - Security group opened for app port (e.g., 5000)
The CI/CD pipeline is defined in the Jenkinsfile:
-
Clone Repo
- Pulls the latest code from GitHub.
-
Deploy to Server
- Connects to the App Server via SSH.
- Creates the app directory and copies code/files.
-
Install & Run App
- Installs dependencies in a Python virtual environment.
- Starts the application using
nohup.
-
Push your code and
Jenkinsfileto GitHub. -
Configure a Jenkins Pipeline job linked to this repository.
-
Add EC2 server credentials in Jenkins:
- Kind: SSH Username with private key
- ID:
SERVER1 - Username:
ubuntu - Private Key: contents of your
.pemfile
-
Run the pipeline in Jenkins.
-
Access the app in your browser at:
http://<APP_SERVER_PUBLIC_IP>:5000
.
βββ app.py # Main Python app
βββ requirements.txt # Python dependencies
βββ Dockerfile # (Optional) Docker setup
βββ Jenkinsfile # CI/CD pipeline
βββ README.md # Documentation
βββ test/ # Tests
π Notes
Each deployment uses nohup to run the app in the background.
You may want to use systemd or Docker for production deployments.
Ensure old processes are cleaned up if re-running multiple times.



