Coder Social home page Coder Social logo

ecs-deployment's Introduction

Todo Web Application Deployed on ECR to ECS Cluster with Jenkins Pipeline

Test Tool Tool Tool Tool Tool Tool Github top language Github language count Repository size License Github stars

About   |   Technologies   |   Requirements   |   Starting   |   Output   |   License   |   Author

🎯 About

Javascript web application 🚀 automated with Jenkins pipeline to create Docker image and push the image to AWS Elastic Container Registry (ECR) and deploy them on Elastic Container Service (ECS) Cluster.

🚀 Technologies

The following tools were used in this project:

✅ Requirements

Before starting 🏁 you need to have Git, Docker, Yarn and Node installed.

🏁 Starting

If you want to start the project locally, you can use the following commands:

# Clone this project
git clone https://github.com/devenes/todo-ecr-ecs-cluster
# Access
cd todo-ecr-ecs-cluster
# Install dependencies
yarn install --production
# Run the project
# The server will initialize in the <http://localhost:3000>
npm run start

You can run Terraform commands in the project folder:

# Run the Terraform init command
terraform init
# Run the Terraform plan command
terraform plan
# After this command, you will see the changes that will be applied to the infrastructure
# You can run the apply command to apply the changes
terraform apply --auto-approve
  • if you want to manually run
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <aws_account_id>.dkr.ecr.us-east-1.amazonaws.com
  • Then run the image
docker run --name todo -dp 80:3000 <aws_account_id>.dkr.ecr.us-east-1.amazonaws.com/devenes/to-do-app:latest
  • Delete the container
docker container stop todo
docker container rm todo
  • Createa ECS cluster with a unique name with the following command.
aws ecs create-cluster --cluster-name to-do-app
  • Register the task definition with the following command.
aws ecs register-task-definition --cli-input-json file://to-do-app.json
  • List the task definitions.
aws ecs list-task-definitions
  • Create a service with following command.

Note: securityGroups=[sg-e29b36ce] is default security group. If we don't specify any security group, aws assign default security group to the cluster.

# change the subnets and security group and make sure that the 3000 port is open
aws ecs create-service --cluster to-do-app --service-name to-do-app-service --task-definition to-do-app --desired-count 1 --launch-type "FARGATE" --network-configuration "awsvpcConfiguration={subnets=[subnet-077c9758],securityGroups=[sg-e29b36ce],assignPublicIp=ENABLED}" 

If you want to run the project in a Docker container, you can use the following command:

  • Build the Docker container image using the docker build command.
docker build -t todo-app:v1.0 .
  • Show the Docker image is created successfully.
docker image ls
  • Run todo app from the local Docker image.
docker run --name todo -d -p 80:3000 todo-app:v1.0
# The server will initialize in the <http://localhost:80>
  • List running container.
docker ps
# or
docker container ls
  • If necessary, authenticate the Docker CLI to your default ECR registry.
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <aws_account_id>.dkr.ecr.us-east-1.amazonaws.com
  • Delete the ECR repository devenes-repo/todo-app from AWS CLI.
aws ecr delete-repository \
      --repository-name devenes/to-do-app \
      --force \
      --region us-east-1
  • Delete the service and ecs cluster.
aws ecs delete-service --cluster to-do-app --service to-do-app-service --force
aws ecs delete-cluster --cluster to-do-app

📷 Expected Output

output

📚 Resources

📝 License

This project is under license from Apache. For more details, see the LICENSE file.

Made with ❤️ by devenes

 

⬆️ Back to top

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.