From 09cab40809265bb2f9f74ecb2da551c7ef7b580b Mon Sep 17 00:00:00 2001 From: brokenpip3 Date: Thu, 15 Feb 2024 10:27:15 +0100 Subject: [PATCH 1/9] move additional build before push --- action.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/action.yml b/action.yml index 00158d2..90f86f5 100644 --- a/action.yml +++ b/action.yml @@ -291,6 +291,19 @@ runs: labels: ${{ steps.meta.outputs.labels }} load: true + - name: Optional build container for other platforms + uses: docker/build-push-action@v3 + if: ${{ inputs.build == 'true' && steps.alternative_platforms.outputs.result != '' }} + continue-on-error: true + with: + context: ${{ inputs.context_path }} + file: ${{ inputs.context_path }}/${{ inputs.dockerfile }} + build-args: ${{ inputs.build_args }} + push: ${{ inputs.dry_run != 'true' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: ${{ steps.alternative_platforms.outputs.result }} + # Scan only one container name # This is needed because if you add/enable the push to quay.io, gar or artifactory (or all of them), there is a list of images with different registries. # Both are the same but we just need one to do the scanning. Usually artifactory is the first one of the list @@ -326,19 +339,6 @@ runs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - - name: Optional build container for other platforms - uses: docker/build-push-action@v3 - if: ${{ inputs.build == 'true' && steps.alternative_platforms.outputs.result != '' }} - continue-on-error: true - with: - context: ${{ inputs.context_path }} - file: ${{ inputs.context_path }}/${{ inputs.dockerfile }} - build-args: ${{ inputs.build_args }} - push: ${{ inputs.dry_run != 'true' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - platforms: ${{ steps.alternative_platforms.outputs.result }} - - name: Save image to file uses: docker/build-push-action@v3 if: ${{ inputs.upload_artifact == 'true' && inputs.build == 'true' }} From 5f30e2ce1c8b71ea87299d8e8064184061e159ec Mon Sep 17 00:00:00 2001 From: Dhruvan Tanna Date: Thu, 15 Feb 2024 17:49:33 +0530 Subject: [PATCH 2/9] Adding platform with push --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index 90f86f5..b1b7ef1 100644 --- a/action.yml +++ b/action.yml @@ -338,6 +338,7 @@ runs: push: ${{ inputs.dry_run != 'true' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + platform: ${{ inputs.image_platforms }} - name: Save image to file uses: docker/build-push-action@v3 From e9206da080280f706858e601905272e855ae1bdf Mon Sep 17 00:00:00 2001 From: Dhruvan Tanna Date: Fri, 16 Feb 2024 13:49:24 +0530 Subject: [PATCH 3/9] Removing unnecessary section --- action.yml | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/action.yml b/action.yml index b1b7ef1..f0057a0 100644 --- a/action.yml +++ b/action.yml @@ -255,15 +255,6 @@ runs: [[ -n "${{ inputs.image_tag_string_suffix }}" ]] && _suffix="-${{ inputs.image_tag_string_suffix }}" || _suffix="" echo "ver=${_prefix}${{ steps.bump_version.outputs.new_version }}${_suffix}" >> $GITHUB_OUTPUT - - name: Check alternative platforms and strip amd64 - if: ${{ inputs.build == 'true' && inputs.image_platforms != '' }} - shell: bash - id: alternative_platforms - run: | - [[ -n "${{ inputs.image_platforms }}" ]] && _altplatforms=$(echo ${{ inputs.image_platforms }} | sed 's/linux\/amd64,//') || echo "No alternative platforms specified" - echo "DEBUG=${_altplatforms}" - echo "result=${_altplatforms}" >> $GITHUB_OUTPUT - - name: Build container meta id: meta uses: docker/metadata-action@v4 @@ -290,19 +281,7 @@ runs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} load: true - - - name: Optional build container for other platforms - uses: docker/build-push-action@v3 - if: ${{ inputs.build == 'true' && steps.alternative_platforms.outputs.result != '' }} - continue-on-error: true - with: - context: ${{ inputs.context_path }} - file: ${{ inputs.context_path }}/${{ inputs.dockerfile }} - build-args: ${{ inputs.build_args }} - push: ${{ inputs.dry_run != 'true' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - platforms: ${{ steps.alternative_platforms.outputs.result }} + platform: ${{ inputs.image_platforms }} # Scan only one container name # This is needed because if you add/enable the push to quay.io, gar or artifactory (or all of them), there is a list of images with different registries. From e44b71e52995b14ba041bf013fc9fe9a8d9b9881 Mon Sep 17 00:00:00 2001 From: Dhruvan Tanna Date: Fri, 16 Feb 2024 13:54:19 +0530 Subject: [PATCH 4/9] Correcting a typo --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index f0057a0..74aa4a3 100644 --- a/action.yml +++ b/action.yml @@ -281,7 +281,7 @@ runs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} load: true - platform: ${{ inputs.image_platforms }} + platforms: ${{ inputs.image_platforms }} # Scan only one container name # This is needed because if you add/enable the push to quay.io, gar or artifactory (or all of them), there is a list of images with different registries. @@ -317,7 +317,7 @@ runs: push: ${{ inputs.dry_run != 'true' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - platform: ${{ inputs.image_platforms }} + platforms: ${{ inputs.image_platforms }} - name: Save image to file uses: docker/build-push-action@v3 From cf127ba1321db3356f116649fe92e4c745ec2a04 Mon Sep 17 00:00:00 2001 From: Dhruvan Tanna Date: Fri, 16 Feb 2024 14:03:58 +0530 Subject: [PATCH 5/9] Removing image platforms while loading --- action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/action.yml b/action.yml index 74aa4a3..379e77e 100644 --- a/action.yml +++ b/action.yml @@ -281,7 +281,6 @@ runs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} load: true - platforms: ${{ inputs.image_platforms }} # Scan only one container name # This is needed because if you add/enable the push to quay.io, gar or artifactory (or all of them), there is a list of images with different registries. From 8bbc098807e17e428631bc453a3e22f4a830ab8f Mon Sep 17 00:00:00 2001 From: Dhruvan Tanna Date: Mon, 19 Feb 2024 16:29:36 +0530 Subject: [PATCH 6/9] Adding required logic to set amd64 default even if not specified for image build --- action.yml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 379e77e..89ba91c 100644 --- a/action.yml +++ b/action.yml @@ -30,8 +30,8 @@ inputs: default: "" required: false - image_platforms: - description: "optional additional architectures -comma separated- (right now only linux/amd64 and linux/arm64 are supported)" + alternate_platforms: + description: "optional additional architectures -comma separated- (right now only linux/amd64 and linux/arm64 are supported), linux/amd64 is always set" required: false external_tag: @@ -177,12 +177,22 @@ runs: shell: bash run: if ! (docker context ls | grep -q mycontext) ;then docker context create mycontext; fi + - name: Creating list of platforms for Image build + if: ${{ inputs.build == 'true' }} + shell: bash + id: platforms_list + # This will remove duplicates if specified, espcially if the user has specified linux/amd64 + run: | + [[ -n "${{ inputs.alternate_platforms }}" ]] && platform_list_temp="linux/amd64,${{ inputs.alternate_platforms }}" || platform_list_temp="linux/amd64" + final_platforms_list=$(echo $platform_list_temp | tr ',' '\n' | sort | uniq | paste -sd ',' -) + echo "image_platforms=${final_platforms_list}" >> $GITHUB_OUTPUT + - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v3 with: endpoint: mycontext - platforms: ${{ inputs.image_platforms }} + platforms: ${{ steps.platforms_list.outputs.image_platforms }} # Login to registries - name: Login to Artifactory @@ -316,7 +326,7 @@ runs: push: ${{ inputs.dry_run != 'true' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - platforms: ${{ inputs.image_platforms }} + platforms: ${{ steps.platforms_list.outputs.image_platforms }} - name: Save image to file uses: docker/build-push-action@v3 From 6f8b685a707aef00a6246ee956bb3ca697f6adf2 Mon Sep 17 00:00:00 2001 From: Dhruvan Tanna Date: Mon, 19 Feb 2024 17:02:51 +0530 Subject: [PATCH 7/9] Trimming whitespaces from the list --- action.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 89ba91c..e2cc717 100644 --- a/action.yml +++ b/action.yml @@ -181,9 +181,10 @@ runs: if: ${{ inputs.build == 'true' }} shell: bash id: platforms_list - # This will remove duplicates if specified, espcially if the user has specified linux/amd64 + # This will trim whitespace and remove duplicates if specified, espcially if the user has specified linux/amd64 run: | - [[ -n "${{ inputs.alternate_platforms }}" ]] && platform_list_temp="linux/amd64,${{ inputs.alternate_platforms }}" || platform_list_temp="linux/amd64" + alternate_platform=$(echo ${{ inputs.alternate_platforms }} | tr -d ' ') + [[ -n "${alternate_platform}" ]] && platform_list_temp="linux/amd64,${alternate_platform} || platform_list_temp="linux/amd64" final_platforms_list=$(echo $platform_list_temp | tr ',' '\n' | sort | uniq | paste -sd ',' -) echo "image_platforms=${final_platforms_list}" >> $GITHUB_OUTPUT From 46f8505383dc9ba05b9ecda24d969c0139de2058 Mon Sep 17 00:00:00 2001 From: Dhruvan Tanna Date: Mon, 19 Feb 2024 17:14:32 +0530 Subject: [PATCH 8/9] updating logic to trim whitespace --- action.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/action.yml b/action.yml index e2cc717..4c45fac 100644 --- a/action.yml +++ b/action.yml @@ -183,9 +183,8 @@ runs: id: platforms_list # This will trim whitespace and remove duplicates if specified, espcially if the user has specified linux/amd64 run: | - alternate_platform=$(echo ${{ inputs.alternate_platforms }} | tr -d ' ') [[ -n "${alternate_platform}" ]] && platform_list_temp="linux/amd64,${alternate_platform} || platform_list_temp="linux/amd64" - final_platforms_list=$(echo $platform_list_temp | tr ',' '\n' | sort | uniq | paste -sd ',' -) + final_platforms_list=$(echo $platform_list_temp | tr -d ' ' | tr ',' '\n' | sort | uniq | paste -sd ',' -) echo "image_platforms=${final_platforms_list}" >> $GITHUB_OUTPUT - name: Set up Docker Buildx From ef425f2102d5e9d3813f10247daf6b81f2260cae Mon Sep 17 00:00:00 2001 From: Dhruvan Tanna Date: Mon, 19 Feb 2024 17:17:43 +0530 Subject: [PATCH 9/9] Fixing platform list --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 4c45fac..f737565 100644 --- a/action.yml +++ b/action.yml @@ -183,7 +183,7 @@ runs: id: platforms_list # This will trim whitespace and remove duplicates if specified, espcially if the user has specified linux/amd64 run: | - [[ -n "${alternate_platform}" ]] && platform_list_temp="linux/amd64,${alternate_platform} || platform_list_temp="linux/amd64" + [[ -n "${{ inputs.alternate_platforms }}" ]] && platform_list_temp="linux/amd64,${{ inputs.alternate_platforms }}" || platform_list_temp="linux/amd64" final_platforms_list=$(echo $platform_list_temp | tr -d ' ' | tr ',' '\n' | sort | uniq | paste -sd ',' -) echo "image_platforms=${final_platforms_list}" >> $GITHUB_OUTPUT