DEV Community

Cover image for Automating CI/CD: Setting Up a Node.js Pipeline with Jenkins, Docker, and AWS
Lester Diaz Perez
Lester Diaz Perez

Posted on • Edited on

Automating CI/CD: Setting Up a Node.js Pipeline with Jenkins, Docker, and AWS

Automate Your Deployment: Step-by-Step Guide to Deploying a Web App with Jenkins on AWS EC2

Pre-requisites

  1. EC2 instance
  2. Installed Docker & Docker Compose
  3. Nodejs app

Building the docker image



nano docker-compose.yml
docker-compose up -d


Enter fullscreen mode Exit fullscreen mode

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

  1. Go to EC2 dashboard
  2. Open Security groups Security Groups
  3. Press Edit inbound rules & Add rule

Add rule

Jenkins website

  • Access public_ipv4:8080

Image description

Where is the password ?

docker ps

ID

docker logs <ID>

Image description

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

  1. Go to Manage jenkins -> Plugins
  2. Search Nodejs plugin and install without restart
  3. Go to Manage jenkins -> Tools
  4. Search NodeJs Installations and Add NodeJs

Add NodeJS version

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)

Image description

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

Docker exec

Inside container

cat /var/jenkins_home/.ssh/id_rsa.pub

  • Go to Github -> Profile -> Settings

Settings Github

  • SSH and GPG keys -> Add new SSH key -> Add SSH key

Image description

Deploy App

  • Go to Jenkins Website -> New Job-> Select Pipeline

Image description

Image description

Image description

Get url of github

Image description

Image description

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.

Image description

Let’s make a small change in the project and apply commit

Image description

Open Console Log

Image description

  • Open Ip:8000

Image description

In the next tutorial , we’ll enrich our workflow by integrating a powerful code analysis tool for enhanced development


LinkedIn

Top comments (0)