Deploy a New Version of the Application (v2)

Deploy a New Version of the Application (v2)

you deployed version 1 of the application. Today, Jules (the developer) sends you a message: "I fixed several bugs and added a new feature. Please deploy Version 2." As a DevOps Engineer, you do not change the code. You receive the updated code and deploy the new version safely. Learning Objectives By the end of this lab, you will: Pull the latest code from GitHub Build a new Docker image Tag the image as v2 Push the new image to Amazon ECR Update the ECS Task Definition Deploy the new version to ECS Verify that the new version is running Understand rolling deployments Architecture Developer │ ▼ Updated Source Code │ ▼ Docker Image v2 │ ▼ Amazon ECR │ ▼ New ECS Task Definition │ ▼ ECS Service Update │ ▼ Application Load Balancer │ ▼ Users See Version 2 Enter fullscreen mode Exit fullscreen mode Step 1 – Receive the Updated Code The developer pushes new code to GitHub. Open the updated project. Why? Developers continuously improve applications by fixing bugs and adding features. Step 2 – Build a New Docker Image docker build -t restaurant-app:v2 . Enter fullscreen mode Exit fullscreen mode Verify: docker images Enter fullscreen mode Exit fullscreen mode You should now see: restaurant-app:v1 restaurant-app:v2 Enter fullscreen mode Exit fullscreen mode Why? Every application change requires a new Docker image. Never overwrite an existing image with the same version tag. Step 3 – Test Version 2 docker run -p 3000:3000 restaurant-app:v2 Enter fullscreen mode Exit fullscreen mode Verify the application works. Why? Always test before deploying. Step 4 – Tag the Image docker tag restaurant-app:v2 ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/restaurant-app:v2 Enter fullscreen mode Exit fullscreen mode Step 5 – Push Version 2 to Amazon ECR docker push ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/restaurant-app:v2 Enter fullscreen mode Exit fullscreen mode Open Amazon ECR. Verify that both images exist: v1 v2 Enter fullscreen mode Exit fullscreen mode Why? Keeping multiple image versions allows you to roll back if something goes wrong. Step 6 – Create a New ECS Task Definition Revision Open Amazon ECS. Select the existing Task Definition. Click Create New Revision. Change only the image URI from: restaurant-app:v1 Enter fullscreen mode Exit fullscreen mode to restaurant-app:v2 Enter fullscreen mode Exit fullscreen mode Save the new revision. Why? Task Definitions are versioned. Instead of editing the old one, AWS creates a new revision for each deployment. Step 7 – Update the ECS Service Select your ECS Service. Click Update Service. Choose the latest Task Definition revision. Deploy. Why? The ECS Service replaces old containers with new ones using the updated image. Step 8 – Watch the Rolling Deployment Open the ECS Service. Observe: New task starts. Health checks pass. Old task stops. New task becomes active. Why? This is called a rolling deployment. It helps reduce downtime because the new container starts before the old one is removed. Step 9 – Test the Application Open the ALB DNS name. Verify that Version 2 is displayed or that the new feature is available. Lab Complete You have successfully: Deployed Version 2 Created a new Docker image Pushed it to ECR Created a new Task Definition revision Updated the ECS Service Completed a rolling deployment Questions Why did we create a new image instead of modifying v1? Why is a new Task Definition revision required? What is a rolling deployment? How does ECS reduce downtime during deployments? Why is it useful to keep old image versions in ECR? What would you do if Version 2 failed after deployment?

Original Source

Read the full article at Dev →

KhanList aggregates and links to publicly available news content. We do not host full articles from third-party sources. Always verify important information with original sources.