From 494bee4099cf2196d4b8de282719152faaa6c0ed Mon Sep 17 00:00:00 2001 From: ovdickson Date: Fri, 1 Nov 2024 17:46:45 +0100 Subject: [PATCH] adjusted workflow --- .github/workflows/build-and-push-ecr.yml | 28 +++++++++--------------- 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build-and-push-ecr.yml b/.github/workflows/build-and-push-ecr.yml index 0eff8d03..53d67b42 100644 --- a/.github/workflows/build-and-push-ecr.yml +++ b/.github/workflows/build-and-push-ecr.yml @@ -38,30 +38,19 @@ jobs: with: terraform_wrapper: false - - # Prepare ECR Repo Name if it does not already exist - - name: Prepare ECR Repo Name + - name: prepare ECR repo name based on the Github repository + shell: bash run: | set -eux - # Lowercase the repository name and replace '/' with '_' + # lowercase the name repo="${GITHUB_REPOSITORY,,}" - repo="${repo//\//_}" - echo "ECR_REPO_NAME=${repo}" >> $GITHUB_ENV - - # Check if the ECR repository exists - - name: Check if ECR Repository Exists - id: check_ecr - run: | - repo="${{ env.ECR_REPO_NAME }}" - if aws ecr describe-repositories --repository-names "$repo" >/dev/null 2>&1; then - echo "ECR_REPO_EXISTS=true" >> $GITHUB_ENV - else - echo "ECR_REPO_EXISTS=false" >> $GITHUB_ENV - fi + # replace / with _ + echo "ECR_REPO_NAME=${repo//\//_}" >> $GITHUB_ENV - name: Terraform Init + shell: bash run: | terraform init -upgrade -reconfigure \ -input=false \ @@ -70,6 +59,7 @@ jobs: working-directory: infra/terraform - name: Terraform Plan + shell: bash run: | terraform plan \ -var "repository_name=${{ env.ECR_REPO_NAME }}" \ @@ -79,6 +69,7 @@ jobs: working-directory: infra/terraform - name: Check for Terraform Plan errors + shell: bash run: | if [[ -s terraform.plan ]]; then cat terraform.plan @@ -86,7 +77,7 @@ jobs: fi - name: Create ECR repo [TF apply] - if: env.ECR_REPO_EXISTS == 'false' + shell: bash run: | terraform apply \ -var "repository_name=${{ env.ECR_REPO_NAME }}" \ @@ -120,6 +111,7 @@ jobs: registries: ${{ env.ACCOUNT_ID }} - name: Build and Push Docker Images + shell: bash id: build-publish env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}