Skip to content

Docker Build and Publish - Dev #8

Docker Build and Publish - Dev

Docker Build and Publish - Dev #8

name: Docker Build and Publish - Dev
on:
workflow_dispatch:
env:
# DOCKERHUB_REPO: ${{ secrets.DOCKERHUB_USERNAME }}/video-watchdog
GHCR_REPO: ghcr.io/${{ github.repository }}
CODE_BRANCH: dev
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
ref: ${{ env.CODE_BRANCH }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# - name: Log in to Docker Hub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
# ${{ env.DOCKERHUB_REPO }}
${{ env.GHCR_REPO }}
flavor: |
latest=false
tags: |
# 当通过 Tag 触发时,输出对应的 Tag
type=ref,event=tag
# 当手动触发时,输出代码所在分支名
type=raw,value=${{ env.CODE_BRANCH }}
# 仅当通过 Tag 触发时,输出 latest 标签
type=raw,value=latest,enable=${{ github.ref_type == 'tag' }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# cache-from: type=gha
# cache-to: type=gha,mode=max