Automate Your Deployment: Step-by-Step Guide to Deploying a Web App with Jenkins on AWS EC2
Pre-requisites
Building the docker image
- Create docker-compose.yml with jenkins service and run docker-compose
nano docker-compose.yml
docker-compose up -d
At this point the jenkins service is running on port 8080 of our EC2 instance but we cannot access it because this port is closed in the EC2 security group
Open port 8080
- Go to EC2 dashboard
- Open Security groups
- Press Edit inbound rules & Add rule
Jenkins website
- Access public_ipv4:8080
Where is the password ?
docker ps
docker logs <ID>
Then select Install suggested plugins and create the user.
Nodejs Plugin Configuration
The first step to upload a node.js application is to install the Node.js plugin, since jenkins is developed in java and does not have node.js applications by default
- Go to Manage jenkins -> Plugins
- Search Nodejs plugin and install without restart
- Go to Manage jenkins -> Tools
- Search NodeJs Installations and Add NodeJs
GitHub Repository Integration
- Fork the project
- Add Webhook
Why is a webhook added?
The primary objective of this configuration is to enable Jenkins to receive automatic notifications whenever a commit is made to the GitHub repository
- Go to NodeJs repository -> Click Settings -> Webhook (Left panel)
Add ssh keys
Adding an SSH key to your GitHub profile is especially useful when you are working with private repositories.
- Open bash shell inside jenkins container -> Run ssh-keygen
cat /var/jenkins_home/.ssh/id_rsa.pub
- Go to Github -> Profile -> Settings
- SSH and GPG keys -> Add new SSH key -> Add SSH key
Deploy App
- Go to Jenkins Website -> New Job-> Select Pipeline
Get url of github
OK guys this nodejs application is exposed through port 8000 so we have to open the port in the docker-compose.yml and in the security group.
Let’s make a small change in the project and apply commit
Open Console Log
- Open Ip:8000
In the next tutorial , we’ll enrich our workflow by integrating a powerful code analysis tool for enhanced development
Top comments (0)