Introduction
In my recent post, I provided a summary of our journey thus far in implementing an e-commerce website, evolving from a basic to a more advanced architecture. If you missed the post, you could find it here:
In this article, we will delve into the utilization of containers in our website deployment strategy. The benefits of using containers include:
Isolation: Containers provide a lightweight, isolated environment for running applications, ensuring that they operate independently without interference from other processes.
Portability: With containers, we can package our application along with its dependencies into a single unit, making it easy to deploy and run consistently across different environments, from development to production.
Scalability: Containers allow us to scale our application horizontally by spinning up multiple instances of the same container, enabling us to handle increased traffic and workload demands more effectively.
Consistency: Containers ensure consistency between development, testing, and production environments, minimizing compatibility issues and reducing the likelihood of deployment errors.
We'll leverage AWS Elastic Container Registry (ECR) to store our Docker images, Amazon Elastic Container Service (ECS) to deploy our containerized website and Terraform as our infrastructure-as-code tool.
Before diving into the utilization of containers in our website deployment strategy, it's essential to understand the prerequisites.
- Docker Account: A basic understanding of Docker containerization technology is required to comprehend container deployment concepts effectively. Ensure that docker daemon is running on your local machine.
- AWS Account: Access to an AWS (Amazon Web Services) account is necessary to utilize AWS Elastic Container Registry (ECR) and Amazon Elastic Container Service (ECS) for container storage and deployment.
Step 1: Clone the Terraform Code
By cloning the Terraform code, we'll have access to the infrastructure-as-code configurations needed for our deployment process.
Clone Repository: Use the git clone command to clone the Terraform code repository to your local machine. Ensure that you have Git installed and configured on your system.
https://github.com/Samuel7050/Dynamic_webserver_with_Terraform.git
Navigate to Repository: Change directory to the folder name containerized_website.
Step 2: Reviewing the Content of the Terraform Codes
Now that we've cloned the Terraform code repository, let's take a closer look at its contents to familiarize ourselves with the infrastructure-as-code configurations.
We are introducing Amazon ECR and Amazon ECS modules into the existing Terraform codes used in the previous articles.
Amazon ECR – This module will create:
- private repository on Amazon ECR
- an ECR policy that we enable the AWS user account to get and put images in the repository.
- build Docker image from the app folder.
- push the image to the repository.
Dockerfile
Docker Provider- we will be using a docker provider with the required authentication to AWS ECR
Amazon ECS – This module will create:
- an ECS cluster
- a task execution role and policy
- a task definition
- ECS service
Step 3: Running Terraform Commands
Below main.tf file defines all the infrastructure that will be deployed after running the terraform commands
Initialize: Initialize Terraform in the project directory to download necessary plugins and modules.
Run Terraform init
Plan: Generate an execution plan to preview the changes that Terraform will make to the infrastructure
Run Terraform plan
Apply: Apply the Terraform execution plan to create infrastructure resources as needed. Respond with yes to confirm the execution plan.
Run Terraform apply
Confirm Resources deployed on AWS
VPC and its dependencies
AWS ECR
AWS ECS
ACM and Route53
Update the Nameservers on your domain name registrar. Am using Namecheap as its updated as shown below
Step 4: Website Test
To confirm that our containerized website is up and running, we load our custom domain on our web browser.
To Clean up: Run terraform destroy
Thanks for Reading!!!
Top comments (0)