mirror of
https://github.com/mivodev/mivo.git
synced 2026-01-26 21:41:59 +07:00
92 lines
3.0 KiB
YAML
92 lines
3.0 KiB
YAML
name: Docker Build & Publish
|
|
|
|
on:
|
|
push:
|
|
branches: [ "main", "master" ]
|
|
# Publish semver tags as releases.
|
|
tags: [ 'v*.*.*' ]
|
|
pull_request:
|
|
branches: [ "main", "master" ]
|
|
|
|
env:
|
|
# Use docker.io for Docker Hub if empty
|
|
REGISTRY: ghcr.io
|
|
# github.repository as <account>/<repo>
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
# Map secrets to env for availability in 'if' conditions
|
|
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
|
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
|
|
|
jobs:
|
|
build:
|
|
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
# Set up Docker Buildx (required for caching)
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
# Login against GHCR
|
|
- name: Log into registry ${{ env.REGISTRY }}
|
|
if: github.event_name != 'pull_request'
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
# Login against Docker Hub (Optional fallback if secrets exist)
|
|
- name: Log into Docker Hub
|
|
if: github.event_name != 'pull_request' && env.DOCKER_USERNAME != ''
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: docker.io
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
|
|
# Extract metadata (tags, labels) for Docker
|
|
# https://github.com/docker/metadata-action
|
|
- name: Extract Docker metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: |
|
|
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
docker.io/${{ env.IMAGE_NAME }}
|
|
tags: |
|
|
type=raw,value=edge,enable={{is_default_branch}}
|
|
type=ref,event=tag
|
|
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }}
|
|
|
|
# Build and push Docker image with Buildx (don't push on PR)
|
|
# https://github.com/docker/build-push-action
|
|
- name: Build and push Docker image
|
|
id: build-and-push
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
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
|
|
|
|
# Update Docker Hub Description (README)
|
|
# https://github.com/peter-evans/dockerhub-description
|
|
- name: Update Docker Hub Description
|
|
if: github.event_name != 'pull_request'
|
|
uses: peter-evans/dockerhub-description@v4
|
|
with:
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
repository: ${{ env.IMAGE_NAME }}
|
|
short-description: ${{ github.event.repository.description }}
|
|
readme-filepath: ./DOCKER_README.md
|