Giter Site home page Giter Site logo

nirmalnaveen20 / node-cicd Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 65 KB

Deploying a Node.js application on Amazon Web Services (AWS) using the Elastic Container Service (ECS) Fargate and Elastic Container Registry (ECR).

Dockerfile 2.16% JavaScript 67.55% EJS 30.29%
aws aws-ecs devops devops-project fargate jenkins

node-cicd's Introduction

Web application deploy into Kubernetes cluster

This mini project takes you on a journey through deploying a Node.js application on Amazon Web Services (AWS) using the Elastic Container Service (ECS) Fargate and Elastic Container Registry (ECR). We’ll explore the underlying technologies, tools, and steps required to achieve this feat.

AWS ECS Fargate: A serverless compute engine for containers that allows you to run containers without the need to manage the underlying infrastructure.

AWS ECR: A fully managed Docker container registry that makes it easy to store, manage, and deploy Docker container images.

Steps

Step 1. AWS setup & cloning the source code from GitHub

Login to AWS Console and create an EC2 instance and allow port 8000 in inbound rules.

Name: ECR_ECS, AMI: Ubuntu 22.04, type:t2.micro > Launch Instance

Use name as you preferd i used nodecicd-server

git clone https://github.com/NirmalNaveen20/node-cicd.git

Step 2. Create IAM user and Installation of AWS CLI and Docker.

Write the policies required for accessing the ECR.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ecr:GetDownloadUrlForLayer",
                "ecr:BatchGetImage",
                "ecr-public:BatchCheckLayerAvailability",
                "ecr-public:PutImage",
                "ecr-public:DescribeRepositories",
                "ecr-public:GetRepositoryPolicy",
                "ecr:ListImages",
                "ecr-public:DeleteRepository",
                "ecr-public:CreateRepository",
                "ecr-public:GetAuthorizationToken",
                "sts:GetServiceBearerToken",
                "ecr-public:InitiateLayerUpload",
                "ecr-public:UploadLayerPart",
                "ecr-public:CompleteLayerUpload"
            ],
            "Resource": "*"
        }
    ]
}

User is created successfully but there is not any access key that key we have to Create.

Click on create access key.

Access key is created successfully done.

Install AWS CLI

sudo apt-get install awscli

Install Docker. Docker installation doumentaion

Add ubuntu user to docker group sudo usermod -aG docker ubuntu

Connect the EC2 instance with AWS management console through awscli.

aws configure

Step 3. Create container registry on ECR and Push docker image to ECR

  • Go to AWS ECR in the AWS management console.

  • Create a repository. I have selected the public repository and the repo name.

  • Select all the operating systems and versions according to the OS of Fargate you would select. Finally, create the repository.

  • Now go to instance and write a Dockerfile to build Docker image.

  • Now, we will run the given commands that will be given in the “View Push Command” on the EC2 instance.

  • Now Run first command to authenticate your docker client to your container registry.

  • Push docker image to ECR repository

  • After the image push, you can check the ECR for the image

  • Build docker image with tag docker build -t <tag-name> .

Step 4. Create a Cluster in ECS.

  • Navigate to the ECS service in the AWS console.

  • Create a cluster in ECS.

  • Provide the Cluster name, VPC and subnet you want your application to be available on.

We used to run docker run to create a container in the EC2 instance out of the docker image. That was nothing but a task. Therefore let’s create a task definition for our cluster.

Now, we will configure a task definition here, by providing the Task Name, Container Name, and URL of the image that is in the Repository and clicking on “Create”.

Now, click on “Create service”.

Choose the cluster. Select the launch type to be Fargate.

The task is now deployed to the cluster.

Navigate to the ENI ID in the task.

Go to the security group URL.

Navigate to the Inbound rule in the security group and open the Port 8000 which is HTTP and select my IP to have access for myself.

Copy the Public Ip of the Container with port 8000, and the site will be live.

⚠Note: Don’t forget to Stop or Delete all clusters and services of ECS otherwise this will cost you without knowing you.⚠

Author

Logo

node-cicd's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.