|
52 | 52 | role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} |
53 | 53 | - name: Create ECR repository if it doesn't exist |
54 | 54 | run: | |
55 | | - aws ecr describe-repositories --repository-names ${{ inputs.APPLICATION_NAME }} || \ |
56 | | - aws ecr create-repository --repository-name ${{ inputs.APPLICATION_NAME }} |
57 | | - LIFECYCLE_POLICY='{"rules":[{"rulePriority":1,"description":"Keep last 500 images","selection":{"tagStatus":"any","countType":"imageCountMoreThan","countNumber":500},"action":{"type":"expire"}}]}' |
| 55 | + if ! aws ecr describe-repositories --repository-names ${{ inputs.APPLICATION_NAME }} 2>/dev/null; then |
| 56 | + echo "Repository ${{ inputs.APPLICATION_NAME }} does not exist, creating it..." |
| 57 | + aws ecr create-repository --repository-name ${{ inputs.APPLICATION_NAME }} |
| 58 | + echo "Setting lifecycle policy..." |
| 59 | + else |
| 60 | + echo "Repository ${{ inputs.APPLICATION_NAME }} already exists, skipping creation" |
| 61 | + fi |
| 62 | +
|
| 63 | + echo "Applying lifecycle policies" |
| 64 | + LIFECYCLE_POLICY='{"rules":[ |
| 65 | + {"rulePriority":1,"description":"Preserve preview images","selection":{"tagStatus":"tagged","tagPatternList":["preview-*"],"countType":"sinceImagePushed","countNumber":365},"action":{"type":"expire"}}, |
| 66 | + {"rulePriority":2,"description":"Preserve production images","selection":{"tagStatus":"tagged","tagPatternList":["v*"],"countType":"imageCountMoreThan","countNumber":50},"action":{"type":"expire"}} |
| 67 | + {"rulePriority":3,"description":"Remove untagged images","selection":{"tagStatus":"untagged","countType":"sinceImagePushed","countNumber":7},"action":{"type":"expire"}} |
| 68 | + ]}' |
58 | 69 | aws ecr put-lifecycle-policy --repository-name ${{ inputs.APPLICATION_NAME }} --lifecycle-policy-text "$LIFECYCLE_POLICY" |
59 | 70 | - name: Set up Docker Buildx |
60 | 71 | uses: docker/setup-buildx-action@v2 |
|
70 | 81 | provenance: false |
71 | 82 | push: true |
72 | 83 | tags: | |
73 | | - ${{ steps.login-ecr.outputs.registry }}/${{ inputs.APPLICATION_NAME }}:preview |
| 84 | + ${{ steps.login-ecr.outputs.registry }}/${{ inputs.APPLICATION_NAME }}:preview-${{ github.event.pull_request.number }} |
74 | 85 | ${{ steps.login-ecr.outputs.registry }}/${{ inputs.APPLICATION_NAME }}:${{ github.event.pull_request.head.sha }} |
75 | 86 | comment-pr: |
76 | 87 | if: ${{ inputs.GHA_TRIGGER_EVENT != 'synchronize' }} |
|
0 commit comments