Full details step by step can be found on our YouTube channel Tiger4code.
This project demonstrates how to build a Docker container for a website and deploy it to AWS ECS using a GitHub Actions workflow.
-
Build the Docker image:
docker build -t github-actions-tutorial:latest . -
Run the container:
docker run -p 8080:80 github-actions-tutorial:latest
-
Open your browser and navigate to http://localhost:8080 to browse the website.
-
Create an ECR repository:
aws ecr create-repository --repository-name github-actions-tutorial
-
Log in to ECR:
aws ecr get-login-password --region <your-region> | docker login --username AWS --password-stdin <your-account-id>.dkr.ecr.<your-region>.amazonaws.com/github-actions-tutorial
-
Tag and push your image:
docker tag github-actions-tutorial:latest <your-account-id>.dkr.ecr.<your-region>.amazonaws.com/github-actions-tutorial docker push <your-account-id>.dkr.ecr.<your-region>.amazonaws.com/github-actions-tutorial
- Create a
.github/workflows/deploy.ymlfile in your repository. (Add your deployment configuration here)
-
Create an ECS cluster:
aws ecs create-cluster --cluster-name github-actions-tutorial-ecs-cluster
-
Create the ECS Task Definition:
Create an
ecs-task-def.jsonfile in your repository with the necessary configuration. -
Create the roles required for the task definition.
-
Create an ECS Security Group to allow HTTP and HTTPS traffic.
-
Create a CloudWatch log group:
aws logs create-log-group --log-group-name /ecs/github-actions-tutorial-log-group
-
Register the Task Definition:
aws ecs register-task-definition --cli-input-json file://ecs-task-def.json
Or, if using the
--profileand--regionoptions:aws ecs register-task-definition --cli-input-json "$(cat ./.aws/ecs-task-def.json)" --profile <your-profile> --region <your-region>
-
Create an ECS Service:
aws ecs create-service \ --cluster github-actions-tutorial-ecs-cluster \ --service-name github-actions-tutorial-ecs-service \ --task-definition github-actions-tutorial-task-def-family \ --desired-count 1 \ --launch-type FARGATE \ --network-configuration "awsvpcConfiguration={subnets=[<your-subnet-id>],securityGroups=[<your-security-group-id>],assignPublicIp=ENABLED}" \ --profile <your-profile> \ --region <your-region>
-
To check the status of your ECS task, run:
aws ecs describe-tasks --cluster github-actions-tutorial-ecs-cluster \ --tasks <your-task-id> \ --profile <your-profile> \ --region <your-region>
- Commit code changes to deploy code from GitHub to ECS using GitHub Actions.