Skip to content

Update docker-ci-ghcr.yml #56

Update docker-ci-ghcr.yml

Update docker-ci-ghcr.yml #56

name: Build and Push to GHCR & Docker Hub
on:
release:
types: [published]
push:
branches: [ main, master ]
tags: [ 'v*.*.*' ]
pull_request:
branches: [ main, master ]
workflow_dispatch:
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write # Needed for GHCR
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Login to GHCR
- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Login to Docker Hub (only on releases/tags)
- name: Login to Docker Hub
if: github.event_name == 'release' || startsWith(github.ref, 'refs/tags/v')
uses: docker/login-action@v3
with:
username: 1minds3t
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Extract metadata/tags for BOTH registries
- name: Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository }}
${{ (github.event_name == 'release' || startsWith(github.ref, 'refs/tags/v')) && '1minds3t/omnipkg' || '' }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable={{is_default_branch}}
type=sha
# Build and push
- name: Build and push
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 }}
cache-from: type=gha
cache-to: type=gha,mode=max