67 lines
2.3 KiB
YAML
67 lines
2.3 KiB
YAML
# 每次 push 到 master(或打 v* 标签)后,自动构建 Docker 镜像并推送到 Docker Hub。
|
||
# 之后服务器上只需 `docker compose pull && docker compose up -d`,不需要人工 docker push。
|
||
#
|
||
# 镜像地址:nameguoguo/daily-checkin-panel
|
||
# 标签:latest(master)、v2.18.0 / v2.18 这种语义化标签(打 tag 时)、sha(每次提交)
|
||
#
|
||
# 需要的仓库密钥(GitHub 仓库 → Settings → Secrets and variables → Actions → New repository secret):
|
||
# DOCKERHUB_USERNAME = 你的 Docker Hub 用户名(nameguoguo)
|
||
# DOCKERHUB_TOKEN = Docker Hub → Account Settings → Security → Access Tokens → 新建(Read & Write)
|
||
# 密钥配好之前 workflow 会跳过推送(只构建不推送,避免红叉)。
|
||
|
||
name: 构建并发布 Docker 镜像
|
||
|
||
on:
|
||
push:
|
||
branches: [master]
|
||
tags: ['v*']
|
||
workflow_dispatch:
|
||
|
||
permissions:
|
||
contents: read
|
||
|
||
jobs:
|
||
docker:
|
||
runs-on: ubuntu-latest
|
||
# 密钥没配好之前只构建不推送,避免 fork 或未配密钥时红叉
|
||
env:
|
||
PUSH_IMAGE: ${{ secrets.DOCKERHUB_TOKEN != '' }}
|
||
steps:
|
||
- name: 拉代码
|
||
uses: actions/checkout@v4
|
||
|
||
- name: 准备多架构构建
|
||
uses: docker/setup-qemu-action@v3
|
||
|
||
- name: 准备 buildx
|
||
uses: docker/setup-buildx-action@v3
|
||
|
||
- name: 登录 Docker Hub
|
||
if: ${{ env.PUSH_IMAGE == 'true' }}
|
||
uses: docker/login-action@v3
|
||
with:
|
||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||
|
||
- name: 生成镜像标签
|
||
id: meta
|
||
uses: docker/metadata-action@v5
|
||
with:
|
||
images: nameguoguo/daily-checkin-panel
|
||
tags: |
|
||
type=raw,value=latest,enable={{is_default_branch}}
|
||
type=semver,pattern={{version}}
|
||
type=semver,pattern={{major}}.{{minor}}
|
||
type=sha,prefix=,format=short
|
||
|
||
- name: 构建并推送(amd64 + arm64,NAS/树莓派也能跑)
|
||
uses: docker/build-push-action@v6
|
||
with:
|
||
context: .
|
||
platforms: linux/amd64,linux/arm64
|
||
push: ${{ env.PUSH_IMAGE == 'true' }}
|
||
tags: ${{ steps.meta.outputs.tags }}
|
||
labels: ${{ steps.meta.outputs.labels }}
|
||
cache-from: type=gha
|
||
cache-to: type=gha,mode=max
|