Skip to content

Commit

Permalink
Tag on main as main-<sha>, and tag on tags as v0, v0.0, `v0.0…
Browse files Browse the repository at this point in the history
….0`, and `latest`
  • Loading branch information
leojonathanoh committed Mar 3, 2023
1 parent 1ad8bf6 commit 76a6cf4
Showing 1 changed file with 25 additions and 45 deletions.
70 changes: 25 additions & 45 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- main
tags:
- '**'
# Note: Remove this before merging
# TODO: Remove pull_request before merging
pull_request:
branches:
- main
Expand Down Expand Up @@ -61,6 +61,26 @@ jobs:
TAG=$( git describe --tags --dirty ) # E.g. v1.2.0-23-g60ee190
echo "TAG=$TAG" >> $GITHUB_ENV
# This step generates the docker tags
# type=ref,event=branch generates tag(s) on branch only
# type=semver generates tag(s) on tags only
# TODO: Remove `type=ref,event=pr` before merging PR
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
${{ github.repository }}
ghcr.io/${{ github.repository }}
tags: |
type=ref,event=pr
# On main. E.g. main-abc01234
type=ref,suffix=-{{sha}},event=branch
# On tags. E.g. 'v0', 'v0.0', 'v0.0.0', and 'latest'
type=semver,pattern=v{{major}}
type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern=v{{major}}.{{minor}}.{{patch}}
# See: https://github.com/docker/build-push-action/blob/v2.6.1/docs/advanced/cache.md#github-cache
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
Expand Down Expand Up @@ -97,45 +117,9 @@ jobs:
- run: |
ls -al release*/
- name: Build (PRs)
id: docker_build_pr
# Run only on pull requests
if: github.event_name == 'pull_request'
uses: docker/build-push-action@v3
with:
build-args: |
TAG=${{ env.TAG }}
context: '.'
file: Dockerfile
platforms: linux/amd64,linux/arm,linux/arm64,linux/mips64le,linux/ppc64le,linux/riscv64,linux/s390x
push: true
tags: |
${{ github.repository }}:${{ env.TAG }}
ghcr.io/${{ github.repository }}:${{ env.TAG }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

- name: Build and push (main)
id: docker_build_main
# Run only on main
if: github.ref == 'refs/heads/main'
uses: docker/build-push-action@v3
with:
build-args: |
TAG=${{ env.TAG }}
context: '.'
file: Dockerfile
platforms: linux/amd64,linux/arm,linux/arm64,linux/mips64le,linux/ppc64le,linux/riscv64,linux/s390x
push: true
tags: |
${{ github.repository }}:${{ env.TAG }}
ghcr.io/${{ github.repository }}:${{ env.TAG }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

- name: Build and push (release)
id: docker_build_release
if: startsWith(github.ref, 'refs/tags/')
- name: Build and push
# TODO: Remove pull_request before merging
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v3
with:
build-args: |
Expand All @@ -144,11 +128,7 @@ jobs:
file: Dockerfile
platforms: linux/amd64,linux/arm,linux/arm64,linux/mips64le,linux/ppc64le,linux/riscv64,linux/s390x
push: true
tags: |
${{ github.repository }}:${{ env.TAG }}
${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:${{ env.TAG }}
ghcr.io/${{ github.repository }}:latest
tags: ${{ steps.prep.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

Expand Down

0 comments on commit 76a6cf4

Please sign in to comment.