8000 GitHub - Blackstaxs/Chat-App-using-Socket.io: A simple chat app using socket.io
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Blackstaxs/Chat-App-using-Socket.io

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

STEPS

mkdir terraform-files
cd terraform-files
nano main.tf 

provider "aws" {
  region = "us-west-2"
}

resource "aws_vpc" "my_vpc" {
  cidr_block = "10.0.0.0/16"
}

resource "aws_subnet" "public_subnet_a" {
  vpc_id            = aws_vpc.my_vpc.id
  cidr_block        = "10.0.1.0/24"
  availability_zone = "us-west-2a"
}

resource "aws_subnet" "public_subnet_b" {
  vpc_id            = aws_vpc.my_vpc.id
  cidr_block        = "10.0.2.0/24"
  availability_zone = "us-west-2b"
}

resource "aws_internet_gateway" "my_igw" {
  vpc_id = aws_vpc.my_vpc.id
}

resource "aws_route_table" "public_route_table" {
  vpc_id = aws_vpc.my_vpc.id

  route {
    cidr_block = "0.0.0.0/0"
    gateway_id = aws_internet_gateway.my_igw.id
  }
}

resource "aws_route_table_association" "public_subnet_a_association" {
  subnet_id      = aws_subnet.public_subnet_a.id
  route_table_id = aws_route_table.public_route_table.id
}

resource "aws_route_table_association" "public_subnet_b_association" {
  subnet_id      = aws_subnet.public_subnet_b.id
  route_table_id = aws_route_table.public_route_table.id
}

resource "aws_instance" "ec2_instance_a" {
  ami           = "ami-00af37d1144686454"  # Amazon Linux 2 AMI ID for us-west-2 region
  instance_type = "t2.micro"
  subnet_id     = aws_subnet.public_subnet_a.id
  associate_public_ip_address = true
  key_name      = "key-name"   #change this line for your key

  security_groups = [aws_security_group.alb_sg.id]

  tags = {
    Name = "EC2 Instance A"
  }
}

resource "aws_instance" "ec2_instance_b" {
  ami           = "ami-00af37d1144686454"  # Amazon Linux 2 AMI ID for us-west-2 region
  instance_type = "t2.micro"
  subnet_id     = aws_subnet.public_subnet_b.id
  associate_public_ip_address = true
  key_name      = "key-name"   #change this line for your key

  security_groups = [aws_security_group.alb_sg.id]

  tags = {
    Name = "EC2 Instance B"
  }
}

resource "aws_security_group" "alb_sg" {
  name_prefix = "alb-sg-"
  vpc_id      = aws_vpc.my_vpc.id

  ingress {
    from_port   = 22
    to_port     = 22
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
  
  ingress {
    from_port   = 0
    to_port     = 65535
    protocol    = "udp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  ingress {
    from_port   = -1
    to_port     = -1
    protocol    = "icmp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  egress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

resource "aws_alb" "example" {
  name            = "example-alb"
  subnets         = [aws_subnet.public_subnet_a.id, aws_subnet.public_subnet_b.id]
  security_groups = [aws_security_group.alb_sg.id]
}

resource "aws_alb_target_group" "example" {
  name     = "example-target-group"
  port     = 80
  protocol = "HTTP"
  vpc_id   = aws_vpc.my_vpc.id
}

resource "aws_alb_listener" "example" {
  load_balancer_arn = aws_alb.example.arn
  port              = 80
  protocol          = "HTTP"

  default_action {
    target_group_arn = aws_alb_target_group.example.arn
    type             = "forward"
  }
}

resource "aws_alb_target_group_attachment" "example" {
  target_group_arn = aws_alb_target_group.example.arn
  target_id        = aws_instance.ec2_instance_a.id
  port             = 80
}

output "ec2_instance_a_public_ip" {
  value = aws_instance.ec2_instance_a.public_ip
}

output "ec2_instance_b_public_ip" {
  value = aws_instance.ec2_instance_b.public_ip
}

terraform init
terraform apply

ssh -i "key-name.pem" ec2-user@public_IP 

sudo yum update

sudo amazon-linux-extras install ansible2

nano install_node.yml

---
- name: Install Node.js using Nodesource
  hosts: localhost
  become: true

  tasks:
    - name: Install required dependencies
      become: yes
      yum:
        name: curl
        state: present

    - name: Add Node.js 14.x repository
      become: yes
      shell: curl -sL https://rpm.nodesource.com/setup_14.x | bash -

    - name: Install Node.js package
      become: yes
      yum:
        name: nodejs
        state: present


ansible-playbook install_node.yml

sudo yum install -y git

git clone https://github.com/abkunal/Chat-App-using-Socket.io.git

cd Chat-App-using-Socket.io

nano package.json

{
  "name": "chatapp",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "start": "node app.js", 
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Kunal Yadav",
  "license": "ISC",
  "dependencies": {
    "socket.io": "^2.0.3",
    "express": "*"
  }
}

npm start

nano deploy_app.yml

---
- name: Install app
  hosts: localhost
  become: true

  tasks:
    - name: Clone your application code from Git
      git:
        repo: https://github.com/abkunal/Chat-App-using-Socket.io.git
        dest: ~/chat_app
        version: master

    - name: Install Node.js application dependencies
      command: npm install
      args:
        chdir: ~/chat_app

    - name: Install PM2
      npm:
        name: pm2
        global: yes

    - name: Start the Node.js application using PM2
      command: pm2 start app.js
      args:
        chdir: ~/chat_app

ansible-playbook deploy_app.yml

pm2 list

http://public_Ip:5000 (ex. http://52.13.27.43:5000)

About

A simple chat app using socket.io

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 65.8%
  • HTML 18.7%
  • CSS 15.3%
  • Procfile 0.2%
0