Skip to content

Commit

Permalink
[feat] push images only if for push event
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyBoWu committed Apr 12, 2024
1 parent 6da78bf commit 3e1745d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/reusable-ecr-build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
-t ${{ secrets.AWS_ACCOUNT_TARGET }}.dkr.ecr.${{ inputs.ecr-repo-aws-region }}.amazonaws.com/${{ inputs.ecr-repo }}:latest .
- name: Run Trivy vulnerability scanner
id: trivy
uses: aquasecurity/trivy-action@d710430a6722f083d3b36b8339ff66b32f22ee55 # v0.19.0
with:
image-ref: ${{ secrets.AWS_ACCOUNT_TARGET }}.dkr.ecr.${{ inputs.ecr-repo-aws-region }}.amazonaws.com/${{ inputs.ecr-repo }}:${{ github.sha }}
Expand All @@ -62,6 +63,8 @@ jobs:
aws ecr get-login-password --region ${{ inputs.ecr-repo-aws-region }} | docker login --username AWS --password-stdin ${{ secrets.AWS_ACCOUNT_TARGET }}.dkr.ecr.${{ inputs.ecr-repo-aws-region }}.amazonaws.com
- name: Docker push to AWS ECR
# Push the image to Amazon ECR only if the Trivy scan passes and the event is a push event
if: ${{ github.event_name == 'push' && steps.trivy.outputs.exit-code == 0 }}
run: |
docker push ${{ secrets.AWS_ACCOUNT_TARGET }}.dkr.ecr.${{ inputs.ecr-repo-aws-region }}.amazonaws.com/${{ inputs.ecr-repo }}:${{ github.sha }}
docker push ${{ secrets.AWS_ACCOUNT_TARGET }}.dkr.ecr.${{ inputs.ecr-repo-aws-region }}.amazonaws.com/${{ inputs.ecr-repo }}:latest
Expand Down

0 comments on commit 3e1745d

Please sign in to comment.