File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 5
5
workflow_call :
6
6
7
7
jobs :
8
+ # job to check if image tag is already present in ECR
9
+ check-image-tag :
10
+ runs-on : ubuntu-latest
11
+ permissions :
12
+ id-token : write
13
+ steps :
14
+ - name : Checkout code
15
+ uses : actions/checkout@v4
16
+ - name : Configure AWS Credentials
17
+ uses : aws-actions/configure-aws-credentials@v4
18
+ with :
19
+ role-to-assume : arn:aws:iam::820242920762:role/GitHubActionsRole
20
+ aws-region : eu-west-2
21
+ - name : Login to ECR
22
+ id : login-ecr
23
+ uses : aws-actions/amazon-ecr-login@v2
24
+ - name : Check if image tag exists
25
+ id : check-if-image-exists
26
+ run : |
27
+ DOCKER_IMAGE="${{ steps.login-ecr.outputs.registry }}/mavis/webapp:${{ github.sha }}"
28
+ aws ecr describe-images --repository-name mavis/webapp --image-ids imageTag="${{ github.sha }}" --region eu-west-2
29
+ if [ $? -eq 0 ]; then
30
+ echo "Image exists skipping build and push"
31
+ echo "IMAGE_EXISTS=True" >> $GITHUB_OUTPUT
32
+ else
33
+ echo "Image does not exist"
34
+ echo "IMAGE_EXISTS=False" >> $GITHUB_OUTPUT
35
+ fi
36
+ outputs :
37
+ IMAGE_EXISTS : ${{ steps.check-if-image-exists.outputs.IMAGE_EXISTS }}
8
38
build :
39
+ if : jobs.check-image-tag.outputs.IMAGE_EXISTS == 'False'
9
40
runs-on : ubuntu-latest
10
41
steps :
11
42
- name : Checkout code
Original file line number Diff line number Diff line change 24
24
25
25
jobs :
26
26
build-and-push-image :
27
- if : github.event_name == 'workflow_dispatch'
28
27
uses : ./.github/workflows/build-and-push-image.yml
29
28
deploy-infrastructure :
30
- if : github.event_name == 'workflow_call'
31
29
needs : build-and-push-image
32
30
uses : ./.github/workflows/deploy-infrastructure.yml
33
31
with :
You can’t perform that action at this time.
0 commit comments