Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor (generate): Determine docker buildx platforms in VARIANTS.ps1 instead of in Dockerfile template for better template reusability #7

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion generate/definitions/VARIANTS.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @(
Expand Down
35 changes: 19 additions & 16 deletions generate/templates/.github/workflows/ci-master-pr.yml.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
'@

$local:WORKFLOW_JOB_NAMES = $VARIANTS | % { "build-$( $_['tag'].Replace('.', '-') )" }
$( $VARIANTS | % {
$VARIANTS | % {
@"


Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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'] ) {
@'
Expand All @@ -160,7 +163,7 @@ if ( $_['tag_as_latest'] ) {
run: docker logout
if: always()
'@
})
}

@"

Expand Down