Skip to content

mohamedsorour1998/Complete-DevOps-Project-1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Complete DevOps Project 1: Infrastructure Pipeline for Node.js Application

Introduction

This guide walks through creating an infrastructure pipeline to deploy a Node.js application using Terraform, Jenkins, Ansible, Docker and Slack. The application will be hosted on an EC2 instance within a private VPC and exposed on port 3000 via an Application Load Balancer. Screenshot 2023-04-24 180514

Prerequisites

  • AWS account with appropriate permissions
  • Terraform installed
  • Jenkins installed
  • Ansible installed
  • Docker installed
  • Slack installed
  • Git installed
  • A sample Node.js application

Step by Step Guide

1. Set up Terraform to do a bastian host configuration

Screenshot 2023-04-24 181553 Create a main.tf file to define your AWS infrastructure. Also create other infrastructure files, This includes files for:

  • A VPC
  • Private and public subnets, route tables, and internet gateways, and NAT gateway with elastic ip Screenshot 2023-04-24 020131
  • Security groups for a bastion host and your application
  • An EC2 instance for the bastion host, which will be used to access your private subnet
  • An EC2 instance for your application server, running Amazon Linux
  • An Application Load Balancer to expose your application

2. Configure Jenkins to use the private subnet and bastion host

Create an SSH config file ~/.ssh/config to proxy into your private subnet through the bastion host. Screenshot 2023-04-24 180106

3. Configure Ansible

  • Create an inventory file inventory.ini which will contain the IP address of your bastion host and application server (private subnet)
  • Create a playbook jenkins_master.yml to configure your bastian server as a Jenkins master Screenshot 2023-04-23 163330
  • Create a playbook jenkins_slave.yml to configure your application server as a Jenkins slave Screenshot 2023-04-23 233316

4. Configure the slave in the Jenkins dashboard

Add a new node in the Jenkins dashboard pointing to your application server. Screenshot 2023-04-23 175221 Screenshot 2023-04-23 175118

5. Create a Jenkins pipeline to deploy your application

Create a Jenkinsfile in your Node.js application repository to:

  • Check out code from the main branch
  • build the docker image for the docker file in the repository
  • The docker will: Install Node.js dependencies with npm install and start the application with npm start exposed on port 3000
  • Jenkins will push the docker image to Docker Hub
  • Jenkins slack notfier will send a notification in slack that the pipline is completed successfully and the docker image is pushed to docker hub Screenshot 2023-04-23 201825 Screenshot 2023-04-23 201920 Screenshot 2023-04-24 002819 Screenshot 2023-04-24 002900 Screenshot 2023-04-24 004956

6. Run the container on the application server

  • pull the docker image from Docker Hub
  • run the docker image on the application server

7. Test your application

curl on your Application server URL to test connectivity. Screenshot 2023-04-24 015544

Documentation

See the README.MD file for full documentation.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors