SimpleTimeService is a minimalist microservice that returns the current timestamp and the client's IP address in JSON format. The service is containerized using Docker and deployed on AWS infrastructure using Terraform.
- Software Development: A simple microservice written in Python.
- Containerization: Dockerizing the application and publishing it to Docker Hub.
- Infrastructure-as-Code: Using Terraform to deploy the application on AWS with ECS, VPC, and an Application Load Balancer (ALB).
- CI/CD: A GitHub Actions pipeline to automate building, pushing, and deploying the application.
├── 📂 .github/workflows # GitHub Actions CI/CD pipeline
├── 📂 app # Application source code and Dockerfile
├── 📂 terraform # Terraform configuration files
Before you begin, ensure you have the following installed:
-
An AWS account with the necessary permissions to create ECS, VPC, ALB, and related resources.
-
AWS credentials configured locally using the AWS CLI:
aws configure
-
Docker Hub Account A Docker Hub account to publish the container image.
Docker Hub credentials configured locally:
docker login
docker build -t simple-time-service ./app
docker run -p 8080:8080 simple-time-service
[ http://localhost:8080 ]
{
"timestamp": "2023-10-15T12:34:56.789Z",
"ip": "192.168.1.1"
}
- Tag the image with your Docker Hub username:
docker tag simple-time-service <dockerhub-username>/simple-time-service:latest
- Push the image to Docker Hub:
docker push <dockerhub-username>/simple-time-service:latest
The Terraform configuration deploys the following AWS resources:
-
VPC: A Virtual Private Cloud with 2 public and 2 private subnets.
-
ECS Cluster: An Elastic Container Service cluster to run the container.
-
ALB: An Application Load Balancer to expose the service.
-
Security Groups: Rules to allow traffic between the ALB and ECS tasks.
aws configure # add aws creds
- Navigate to the Terraform directory:
cd terraform
- Initialize Terraform:
terraform init
- Review the execution plan:
terraform plan
- Apply the configuration to deploy the infrastructure:
terraform apply -auto-approve
After deployment, Terraform will output the ALB DNS name. Access the service at:
http://<alb-dns-name>
{
"timestamp": "2023-10-15T12:34:56.789Z",
"ip": "192.168.1.1"
}
- The repository includes a GitHub Actions workflow (ci-cd.yml) to automate:
- Building and pushing the Docker image to Docker Hub.
- Deploying the infrastructure using Terraform.
- Prerequisites
- Add the following secrets to your GitHub repository's secrets:
- DOCKERHUB_USERNAME: Your Docker Hub username.
- DOCKERHUB_TOKEN: Your Docker Hub access token.
- WS_ACCESS_KEY_ID: Your AWS access key.
- AWS_SECRET_ACCESS_KEY: Your AWS secret key.
Trigger the Pipeline Push changes to the main branch to trigger the pipeline.
-
Source-Code: https://github.com/Tanveer143s/particle41-devops-challenge-25/tree/main
-
DockerHUb Image: tanveer143/simple-time-service:latest