From 051b30364b9944b899bf4a92392dd5deee9a5c0b Mon Sep 17 00:00:00 2001 From: Leonard Jonathan Oh Date: Wed, 15 Sep 2021 16:26:33 +0000 Subject: [PATCH] Refactor (generate): Determine docker buildx platforms in VARIANTS.ps1 instead of in Dockerfile template for better template reusability --- generate/definitions/VARIANTS.ps1 | 9 ++++- .../.github/workflows/ci-master-pr.yml.ps1 | 35 ++++++++++--------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/generate/definitions/VARIANTS.ps1 b/generate/definitions/VARIANTS.ps1 index 4a5069d..3e2cd24 100644 --- a/generate/definitions/VARIANTS.ps1 +++ b/generate/definitions/VARIANTS.ps1 @@ -25,9 +25,16 @@ $VARIANTS = @( @{ # Metadata object _metadata = @{ - components = $subVariant['components'] distro = $variant['distro'] distro_version = $variant['distro_version'] + platforms = & { + if ($variant -in @( '3.3', '3.4', '3.5' ) ) { + 'linux/amd64' + }else { + 'linux/386,linux/amd64,linux/arm,linux/arm64,linux/s390x' + } + } + components = $subVariant['components'] } # Docker image tag. E.g. '3.8-curl' tag = @( diff --git a/generate/templates/.github/workflows/ci-master-pr.yml.ps1 b/generate/templates/.github/workflows/ci-master-pr.yml.ps1 index d28d631..417262a 100644 --- a/generate/templates/.github/workflows/ci-master-pr.yml.ps1 +++ b/generate/templates/.github/workflows/ci-master-pr.yml.ps1 @@ -13,7 +13,7 @@ jobs: '@ $local:WORKFLOW_JOB_NAMES = $VARIANTS | % { "build-$( $_['tag'].Replace('.', '-') )" } -$( $VARIANTS | % { +$VARIANTS | % { @" @@ -97,18 +97,21 @@ $( $VARIANTS | % { DOCKERHUB_REGISTRY_USER: ${{ secrets.DOCKERHUB_REGISTRY_USER }} DOCKERHUB_REGISTRY_PASSWORD: ${{ secrets.DOCKERHUB_REGISTRY_PASSWORD }} + +'@ +@" - name: Build (PRs) id: docker_build_pr # Run only on pull requests if: github.event_name == 'pull_request' uses: docker/build-push-action@v2 with: - context: ${{ steps.prep.outputs.CONTEXT }} - platforms: linux/386,linux/amd64,linux/arm,linux/arm64,linux/s390x + context: `${{ steps.prep.outputs.CONTEXT }} + platforms: $( $_['_metadata']['platforms'] -join ',' ) push: false tags: | - ${{ github.repository }}:${{ steps.prep.outputs.VARIANT_TAG_WITH_REF }} - ${{ github.repository }}:${{ steps.prep.outputs.VARIANT_TAG_WITH_REF_AND_SHA_SHORT }} + `${{ github.repository }}:`${{ steps.prep.outputs.VARIANT_TAG_WITH_REF }} + `${{ github.repository }}:`${{ steps.prep.outputs.VARIANT_TAG_WITH_REF_AND_SHA_SHORT }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache @@ -118,12 +121,12 @@ $( $VARIANTS | % { if: github.ref == 'refs/heads/master' uses: docker/build-push-action@v2 with: - context: ${{ steps.prep.outputs.CONTEXT }} - platforms: linux/386,linux/amd64,linux/arm,linux/arm64,linux/s390x + context: `${{ steps.prep.outputs.CONTEXT }} + platforms: $( $_['_metadata']['platforms'] -join ',' ) push: true tags: | - ${{ github.repository }}:${{ steps.prep.outputs.VARIANT_TAG_WITH_REF }} - ${{ github.repository }}:${{ steps.prep.outputs.VARIANT_TAG_WITH_REF_AND_SHA_SHORT }} + `${{ github.repository }}:`${{ steps.prep.outputs.VARIANT_TAG_WITH_REF }} + `${{ github.repository }}:`${{ steps.prep.outputs.VARIANT_TAG_WITH_REF_AND_SHA_SHORT }} cache-to: type=local,dest=/tmp/.buildx-cache - name: Build and push (release) @@ -133,15 +136,15 @@ $( $VARIANTS | % { if: github.ref == 'refs/heads/release' uses: docker/build-push-action@v2 with: - context: ${{ steps.prep.outputs.CONTEXT }} - platforms: linux/386,linux/amd64,linux/arm,linux/arm64,linux/s390x + context: `${{ steps.prep.outputs.CONTEXT }} + platforms: $( $_['_metadata']['platforms'] -join ',' ) push: true tags: | - ${{ github.repository }}:${{ steps.prep.outputs.VARIANT_TAG }} - ${{ github.repository }}:${{ steps.prep.outputs.VARIANT_TAG_WITH_REF }} - ${{ github.repository }}:${{ steps.prep.outputs.VARIANT_TAG_WITH_REF_AND_SHA_SHORT }} + `${{ github.repository }}:`${{ steps.prep.outputs.VARIANT_TAG }} + `${{ github.repository }}:`${{ steps.prep.outputs.VARIANT_TAG_WITH_REF }} + `${{ github.repository }}:`${{ steps.prep.outputs.VARIANT_TAG_WITH_REF_AND_SHA_SHORT }} -'@ +"@ if ( $_['tag_as_latest'] ) { @' @@ -160,7 +163,7 @@ if ( $_['tag_as_latest'] ) { run: docker logout if: always() '@ -}) +} @"