Continuous Integration (CI) and Continuous Deployment (CD) are crucial components of modern software development, ensuring rapid and reliable delivery of applications. In this guide, we will walk through the steps to set up an automated CI/CD pipeline for a Node.js application using AWS EC2, Docker, GitHub, and Jenkins.
To begin, make sure you have the following prerequisites in place:
- AWS EC2 instance
- Jenkins installed
- Docker and Docker-compose installed
- GitHub account
- GitHub integration plugin installed in Jenkins
- Launch EC2 Instance: Launch an AWS EC2 instance and ensure that you have the necessary permissions.
- Install Jenkins, Docker, and Docker-compose: Follow the provided links for instructions on installing Jenkins, Docker, and Docker-compose.
- Fork and Clone Repository: Clone the repository onto your EC2 instance using the following commands git clone
- Create SSH Keys: Generate SSH public and private keys on your EC2 instance:ssh-keygen cd .ssh cat id_rsa cat id_rsa.pub
- Configuring GitHub:In GitHub, go to Account Settings, click on SSH and GPG keys, and add the public IP of your EC2 instance.Configure GitHub Webhook: In your repository settings, click on Webhooks, add a webhook with the Jenkins environment URL, and set the payload URL to https://your-jenkins-ip/github-webhook/.
- Configuring Jenkins:Install the GitHub integration plugin in Jenkins.Create a freestyle project, configure the GitHub project URL, and set up the Git repository credentials.
- Jenkins CI/CD Pipeline Steps:Configure the build trigger to use GitHub hook trigger for GITScm polling.Set up build steps using Docker-compose commands to build and deploy the Node.js application.Example Build Steps:echo "starting container" docker-compose down docker-compose up -d --no-deps --build <service_name>
- Check Webhook Connection: Verify the webhook connection by checking for a green checkmark in the GitHub project.
- Run the Pipeline: Go to the Jenkins dashboard, click on the project, and build the project to trigger the CI/CD pipeline.
- Access Application: Access the application at https://public_ip_of_instance:8000 in a web browser.
After completing the setup, any changes pushed to the GitHub main branch will trigger the Jenkins pipeline automatically. Monitor the Jenkins dashboard for build statuses and access the deployed application to verify the changes.
Contributions to this project are welcome. If you have any suggestions, enhancements, or bug fixes, follow these steps:
- Fork the project.
- Create a new branch for your feature (e.g., git checkout -b feature/AmazingFeature).
- Commit your changes (git commit -m 'Add some AmazingFeature').
- Push to the branch (git push origin feature/AmazingFeature).
- Open a Pull Request.
Your contributions are highly appreciated in making this CI/CD pipeline more robust and efficient.