Skip to content

Commit

Permalink
imp #12: use the docker meta for both the dockerhub+github
Browse files Browse the repository at this point in the history
  • Loading branch information
donkeyx authored and David Binney committed Sep 25, 2023
1 parent ece2358 commit 85bbd0f
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Cache Go packages and Docker layers
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
Expand All @@ -32,15 +32,15 @@ jobs:
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: 1.21
go-version: 1.17

- name: Cache Go packages (reuse cache from 'cache' job)
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
Expand All @@ -50,48 +50,63 @@ jobs:
go-${{ runner.os }}-
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Docker meta
id: meta
- name: Docker meta (GHCR)
id: meta-gh
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/donkeyx/cluster-utils-api
docker.io/donkeyx/cluster-utils-api
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
- name: Login to GHCR
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push to GHCR
uses: docker/build-push-action@v3
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta-gh.outputs.tags }}
labels: ${{ steps.meta-gh.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Docker meta (Docker Hub)
id: meta-dh
uses: docker/metadata-action@v4
with:
images: |
docker.io/donkeyx/cluster-utils-api
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
- name: Login to Docker Hub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Build and push to Docker Hub
uses: docker/build-push-action@v3
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: docker.io/donkeyx/cluster-utils-api:{{ steps.meta.outputs.tags }}
tags: ${{ steps.meta-dh.outputs.tags }} # Use the same tags as generated for GHCR
labels: ${{ steps.meta-dh.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

0 comments on commit 85bbd0f

Please sign in to comment.