build multiple flavors at the same time. handle tags for branches

This commit is contained in:
Jason Kulatunga 2023-07-08 09:37:51 -07:00
parent f1f2da2dd3
commit 25ae2c669c
No known key found for this signature in database
1 changed files with 13 additions and 6 deletions

View File

@ -1,7 +1,7 @@
name: Docker name: Docker
on: on:
push: push:
branches: [ main, sandbox ] branches: [ main, beta ]
# Publish semver tags as releases. # Publish semver tags as releases.
tags: [ 'v*.*.*' ] tags: [ 'v*.*.*' ]
@ -21,7 +21,9 @@ jobs:
contents: read contents: read
packages: write packages: write
id-token: write id-token: write
strategy:
matrix:
flavor: [main, sandbox]
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v2
@ -45,10 +47,15 @@ jobs:
uses: docker/metadata-action@v4 uses: docker/metadata-action@v4
with: with:
flavor: | flavor: |
latest=${{ github.event_name == 'push' && contains(github.ref, 'refs/tags/') }} # only latest if push has a tag and we're building the "main" flavor
latest=${{ github.event_name == 'push' && matrix.flavor == 'main' && contains(github.ref, 'refs/tags/') }}
tags: | tags: |
type=ref,enable=true,event=branch # if this is a tag'd build, prefix it with the flavor (eg. main-v1.2.3 and sandbox-v1.2.3)
type=ref,enable=true,event=tag type=ref,event=tag,prefix=${{ matrix.flavor }}-
# if this is a main branch build, just tag it with the flavor (eg. main and sandbox)
type=raw,value=${{ matrix.flavor }},enable=${{ github.ref_name == 'main' }}
# if this is a (non main) branch build, tag it with the flavor and branch name (eg. main-branch and sandbox-branch)
type=ref,event=branch,prefix=${{ matrix.flavor }}-,enable=${{ matrix.flavor != 'main' }}
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Build and push Docker image with Buildx (don't push on PR) # Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action # https://github.com/docker/build-push-action
@ -63,4 +70,4 @@ jobs:
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
build-args: | build-args: |
FASTEN_ENV=${{ github.ref_name == 'sandbox' && 'sandbox' || 'prod' }} FASTEN_ENV=${{ matrix.flavor == 'sandbox' && 'sandbox' || 'prod' }}