Skip to content

Commit

Permalink
[update]
Browse files Browse the repository at this point in the history
  • Loading branch information
alvo254 committed Jun 10, 2024
1 parent 6c36d0b commit 1661571
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
33 changes: 26 additions & 7 deletions .github/workflows/aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
# See the documentation for each action used below for the recommended IAM policies for this IAM user,
# and best practices on handling the access key credentials.



name: Deploy to Amazon ECS

on:
Expand All @@ -32,12 +34,11 @@ on:

env:
AWS_REGION: us-east-1 # set this to your preferred AWS region, e.g., us-west-1
DOCKER_USERNAME: alvin254 # set this to your Docker Hub username
DOCKER_REPOSITORY: fitnesshero # set this to your Docker Hub repository name
ECS_SERVICE: app-service # set this to your Amazon ECS service name
ECS_CLUSTER: cloudific # set this to your Amazon ECS cluster name
ECS_TASK_DEFINITION: ${{ secrets.ECS_TASK_DEFINITION }} # set this to the path to your Amazon ECS task definition file
CONTAINER_NAME: fitnesshero # set this to the name of the container in your task definition
DOCKER_USERNAME: alvin254 # set this to your Docker Hub username
DOCKER_REPOSITORY: fitnesshero # set this to your Docker Hub repository name
ECS_SERVICE: app-service # set this to your Amazon ECS service name
ECS_CLUSTER: cloudific # set this to your Amazon ECS cluster name
CONTAINER_NAME: fitnesshero # set this to the name of the container in your task definition

permissions:
contents: read
Expand All @@ -52,6 +53,23 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.8.5


- name: Terraform Init
run: terraform init

- name: Terraform Apply
id: apply
run: terraform apply -auto-approve

- name: Get ECS Task Definition ARN
id: ecs-task-def
run: echo "ECS_TASK_DEFINITION=$(terraform output -raw ecs_task_definition_arn)" >> $GITHUB_ENV

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
Expand All @@ -71,6 +89,7 @@ jobs:
echo "image=$DOCKER_USERNAME/$DOCKER_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_TASK_DEFINITION }}
Expand All @@ -83,4 +102,4 @@ jobs:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true
wait-for-service-stability: true
5 changes: 5 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ module "ecs" {
security_group = module.sg.security_group
pub_sub1 = module.vpc.pub_sub1
# container_image = "fitnesshero"
}

output "ecs_task_definition_arn" {
description = "The ARN of the ECS task definition from the module"
value = module.ecs.task_definition_arn
}

0 comments on commit 1661571

Please sign in to comment.