@@ -9,44 +9,98 @@ inputs:
99 description : " The ARN of the AWS github-ci role to use to push to ECR"
1010 required : true
1111 ECR_REPOSITORY :
12- description : " The name of the ECR repository"
13- required : true
12+ description : " The name of the ECR repository. Required if ECR_REPOSITORIES is not set"
13+ required : false
14+ ECR_REPOSITORIES :
15+ description : " The names of the ECR repositories. Required if ECR_REPOSITORY is not set"
16+ required : false
1417 WORKING_DIRECTORY :
1518 description : " The working directory to use"
1619 required : false
1720 default : " ."
21+ CUSTOM_BUILD_SCRIPT :
22+ description : " The custom build script to use"
23+ required : false
1824
1925runs :
2026 using : " composite"
2127 steps :
22- - name : 🔐 Configure AWS credentials
23- uses : aws-actions/configure-aws-credentials@v4
24- with :
25- role-to-assume : ${{ inputs.AWS_ROLE_ARN }}
26- role-session-name : GitHub-Action-Role
27- aws-region : ${{ inputs.AWS_REGION }}
28-
29- - name : 🔓 Login to Amazon ECR
30- id : login-ecr
31- uses : aws-actions/amazon-ecr-login@v2
32-
33- - name : 🐳 Docker Metadata
34- uses : docker/metadata-action@v5
35- id : meta
36- with :
37- images : " ${{ steps.login-ecr.outputs.registry }}/${{ inputs.ECR_REPOSITORY }}"
38- tags : |
39- latest
40- type=sha,prefix=sha-,format=long
41- type=ref,event=branch
42- type=ref,event=pr
43- type=ref,event=tag
44-
45- - name : 🏗️ Build and push
46- if : steps.check-image-tag.outputs.exists != 'true'
47- uses : docker/build-push-action@v5
48- with :
49- push : true
50- tags : ${{ steps.meta.outputs.tags }}
51- labels : ${{ steps.meta.outputs.labels }}
52- context : ${{ inputs.WORKING_DIRECTORY }}
28+ - name : 🔐 Configure AWS credentials
29+ uses : aws-actions/configure-aws-credentials@v4
30+ with :
31+ role-to-assume : ${{ inputs.AWS_ROLE_ARN }}
32+ role-session-name : GitHub-Action-Role
33+ aws-region : ${{ inputs.AWS_REGION }}
34+
35+ - name : 🔓 Login to Amazon ECR
36+ id : login-ecr
37+ uses : aws-actions/amazon-ecr-login@v2
38+
39+ - name : 🧩 Parse ECR repositories
40+ id : parse
41+ shell : bash
42+ run : |
43+ if [ -n "${{ inputs.ECR_REPOSITORIES }}" ]; then
44+ repos=$(echo "${{ inputs.ECR_REPOSITORIES }}" | tr ',' '\n')
45+ elif [ -n "${{ inputs.ECR_REPOSITORY }}" ]; then
46+ repos="${{ inputs.ECR_REPOSITORY }}"
47+ else
48+ echo "Error: Either ECR_REPOSITORY or ECR_REPOSITORIES must be provided."
49+ exit 1
50+ fi
51+
52+ echo "repos<<EOF" >> $GITHUB_OUTPUT
53+ echo "$repos" >> $GITHUB_OUTPUT
54+ echo "EOF" >> $GITHUB_OUTPUT
55+
56+ # Build a multiline string of full ECR paths
57+ images=""
58+ for repo in $repos; do
59+ images="$images\n${{ steps.login-ecr.outputs.registry }}/${repo}"
60+ done
61+
62+ # Write images to this step's output
63+ echo "images<<EOF" >> $GITHUB_OUTPUT
64+ echo -e "$images" >> $GITHUB_OUTPUT
65+ echo "EOF" >> $GITHUB_OUTPUT
66+
67+ - name : 🐳 Docker Metadata
68+ uses : docker/metadata-action@v5
69+ id : meta
70+ with :
71+ images : " ${{ steps.parse.outputs.images }}"
72+ tags : |
73+ latest
74+ type=sha,prefix=sha-,format=long
75+ type=ref,event=branch
76+ type=ref,event=pr
77+ type=ref,event=tag
78+
79+ - name : 🏗️ Build and push
80+ if : ${{ !inputs.CUSTOM_BUILD_SCRIPT }}
81+ uses : docker/build-push-action@v5
82+ with :
83+ push : true
84+ tags : ${{ steps.meta.outputs.tags }}
85+ labels : ${{ steps.meta.outputs.labels }}
86+ context : ${{ inputs.WORKING_DIRECTORY }}
87+
88+ - name : 🏗️ Build and push images with custom script
89+ if : ${{ inputs.CUSTOM_BUILD_SCRIPT }}
90+ shell : bash
91+ working-directory : ${{ inputs.WORKING_DIRECTORY }}
92+ run : |
93+ ${{ inputs.CUSTOM_BUILD_SCRIPT }}
94+ repos="${{ steps.parse.outputs.repos }}"
95+ tags="${{ steps.meta.outputs.tags }}"
96+ for repo in $repos; do
97+ echo "Processing repository: $repo"
98+ for tag in $tags; do
99+ if [[ $tag == *"$repo"* ]]; then
100+ echo "Tagging and pushing: $tag for image $repo"
101+ docker tag "$repo" "$tag"
102+ docker push "$tag"
103+ fi
104+ done
105+ done
106+
0 commit comments