Skip to content

Commit

Permalink
adjusted workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ovdickson committed Nov 1, 2024
1 parent 7db4a4e commit 494bee4
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions .github/workflows/build-and-push-ecr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -70,6 +59,7 @@ jobs:
working-directory: infra/terraform

- name: Terraform Plan
shell: bash
run: |
terraform plan \
-var "repository_name=${{ env.ECR_REPO_NAME }}" \
Expand All @@ -79,14 +69,15 @@ jobs:
working-directory: infra/terraform

- name: Check for Terraform Plan errors
shell: bash
run: |
if [[ -s terraform.plan ]]; then
cat terraform.plan
exit 1
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 }}" \
Expand Down Expand Up @@ -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 }}
Expand Down

0 comments on commit 494bee4

Please sign in to comment.