This repository automates the deployment of a Vite app using AWS ECS Fargate and GitHub Actions for CI/CD. The app is built with Vite, served using Nginx, and utilizes Amazon S3 and ECR.
- AWS CLI configured with admin access
- Terraform installed
- Docker installed
- SonarQube setup (optional)
- Ensure you have an AWS account with access to:
- ECR repository:
haikali3/viteops
- S3 buckets:
s3-viteops-input
ands3-viteops-output
- Necessary permissions to create ECS, IAM, and CloudWatch resources
- ECR repository:
- AWS CLI installed and configured
- Ensure Docker is installed and running
- Install Node.js (v18)
Add the following secrets to your repository for GitHub Actions:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_REGION
- Install Dependencies:
npm install
- Build the App:
npm run build
- Run Locally with Docker:
docker build -t vite-app .
docker run -p 80:80 vite-app
Access the app at http://localhost
Ensure you have Terraform installed. Run the following commands:
terraform init
terraform apply
Confirm the resource creation prompts.
- Push changes to the main or develop branch to trigger the pipeline
- The pipeline will:
- Build the Vite app
- Build and push the Docker image to Amazon ECR
- Deploy the task to AWS Fargate upon ECR image push
CloudWatch Event Rule automatically triggers the ECS task when a new image is pushed to ECR.
- Input:
s3-viteops-input
- Output:
s3-viteops-output
- Cluster Name:
fargate-cluster
- Service Name:
fargate-service
fargate_task_execution_role
: Grants ECS task access to S3 and ECRcloudwatch_events_role
: Allows CloudWatch to trigger ECS tasks
- Located in
.github/workflows/deploy.yml
aws ecr get-login-password --region ap-southeast-1 | docker login --username AWS --password-stdin <account_id>.dkr.ecr.ap-southeast-1.amazonaws.com
docker tag vite-app:latest <account_id>.dkr.ecr.ap-southeast-1.amazonaws.com/haikali3/viteops:latest
docker push <account_id>.dkr.ecr.ap-southeast-1.amazonaws.com/haikali3/viteops:latest
Run Terraform destroy to delete all remaining resources:
terraform destroy
- Ensure subnets and security groups in
main.tf
are correctly configured for your environment - Replace
<account_id>
with your AWS account ID