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

GitHub

View Github