From c6a6ea0848d4795065566464257c359bc1e4dfd4 Mon Sep 17 00:00:00 2001 From: Joshua Burns Date: Mon, 11 Sep 2023 16:42:28 -0700 Subject: [PATCH] more debugging --- .github/workflows/build-infra.yaml | 29 ++++++++++++++++++++++++++--- terraform/_outputs.tf | 4 ++-- terraform/ecs.tf | 2 +- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-infra.yaml b/.github/workflows/build-infra.yaml index 94fd4ba..30d263e 100644 --- a/.github/workflows/build-infra.yaml +++ b/.github/workflows/build-infra.yaml @@ -38,11 +38,13 @@ jobs: run: | sudo apt install jq tree - - name: Get ECR arn + ## Fetch output from our terraform + - name: Pull Terrafrom output into GitHub Action ENV run: | - pwd - tree -dL 2 echo "ecr_repository_url=$(terragrunt output --json | jq .ecr_repository_url.value -r)" >> $GITHUB_ENV + echo "ecs_task_arn=$(terragrunt output --json | jq .ecs_task_arn.value -r)" >> $GITHUB_ENV + echo "ecs_service_arn=$(terragrunt output --json | jq .ecs_service_arn.value -r)" >> $GITHUB_ENV + echo "ecs_cluster_arn=$(terragrunt output --json | jq .ecs_cluster_arn.value -r)" >> $GITHUB_ENV working-directory: terraform - name: Fetch ECS Repo Url @@ -62,3 +64,24 @@ jobs: with: push: true tags: ${{ env.ecr_repository_url }}:latest , ${{ env.ecr_repository_url }}:${{ github.sha }} + + - name: Pull task-definition.json to update ECS cluster + id: pull-ecs-task-definition + run: | + aws ecs describe-task-definition --task-definition ${{ env.ecs_task_arn }} --region ${{ env.AWS_REGION }} --output json >> task-definition.json + + - name: Render Amazon ECS task definition + id: render-web-container + uses: aws-actions/amazon-ecs-render-task-definition@v1 + with: + task-definition: task-definition.json + container-name: knowledgeshare-ui + image: ${{ env.ecr_repository_url }}:latest + environment-variables: "LOG_LEVEL=info" + + - name: Deploy to Amazon ECS service + uses: aws-actions/amazon-ecs-deploy-task-definition@v1 + with: + task-definition: ${{ steps.render-web-container.outputs.task-definition }} + service: ${{ env.ecs_service_arn }} + cluster: ${{ env.ecs_cluster_arn }} diff --git a/terraform/_outputs.tf b/terraform/_outputs.tf index 30e3995..99a5ac5 100644 --- a/terraform/_outputs.tf +++ b/terraform/_outputs.tf @@ -18,7 +18,7 @@ output "ecs_task_arn" { description = "ARN of the ECS task definition" } -output "ecs_service_id" { +output "ecs_service_arn" { value = aws_ecs_service.knowledgeshare_ui_service.id - description = "ID of the ECS Service" + description = "ARN of the ECS Service" } diff --git a/terraform/ecs.tf b/terraform/ecs.tf index 4bb474b..c3ec34f 100644 --- a/terraform/ecs.tf +++ b/terraform/ecs.tf @@ -9,7 +9,7 @@ resource "aws_ecs_cluster" "knowledgeshare_ui_ecs_cluster" { resource "aws_ecs_task_definition" "knowledgeshare_ui_task" { family = "knowledgeshare-service" container_definitions = jsonencode([{ - name = "knowledgeshare-ui" + name = "knowledgeshare-ui" # TODO make this a variable that can be made into output so we can fetch programatically image = "${aws_ecr_repository.knowledgeshare_ui_ecr.repository_url}:latest" memory = 512 essential = true