mirror of
https://github.com/setube/ogame-vue-ts.git
synced 2026-05-12 16:05:12 +08:00
- 合并原有分离的 amd64 和 arm64 构建任务为统一的多架构构建任务 - 使用 docker/setup-qemu-action 和 docker/setup-buildx-action 支持多架构构建 - 更新 GitHub Actions 的依赖版本至最新(checkout@v4、login-action@v3、build-push-action@v6) - 修改平台配置为 linux/amd64,linux/arm64 实现一键双架构构建 - 改用 GITHUB_TOKEN 进行 GHCR 认证,提高安全性 - 优化 Docker Hub 登录逻辑,仅在配置凭据时执行 - 移除手动创建 manifest 步骤,由 build-push-action 自动处理多架构标签 - 增加对 git tag 触发的支持,实现版本化镜像推送 - 添加构建缓存支持以提升后续构建速度 - 更新镜像标签策略,同时推送 latest 和 commit SHA 标签到 GHCR 与 Docker Hub
59 lines
1.9 KiB
YAML
59 lines
1.9 KiB
YAML
name: Docker 多架构构建并发布
|
||
|
||
on:
|
||
push:
|
||
branches: [ main ]
|
||
tags: [ 'v*.*.*' ] # 打 tag 时也触发
|
||
workflow_dispatch:
|
||
|
||
permissions:
|
||
contents: read
|
||
packages: write
|
||
|
||
jobs:
|
||
build-and-push:
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- name: 检出代码
|
||
uses: actions/checkout@v4
|
||
with:
|
||
fetch-depth: 0
|
||
|
||
# QEMU 用于支持多架构构建(必须)
|
||
- name: 设置 QEMU
|
||
uses: docker/setup-qemu-action@v3
|
||
|
||
# Buildx 是目前官方唯一推荐的多架构构建方式
|
||
- name: 设置 Docker Buildx
|
||
uses: docker/setup-buildx-action@v3
|
||
|
||
# 登录 GHCR
|
||
- name: 登录 GitHub Container Registry
|
||
uses: docker/login-action@v3
|
||
with:
|
||
registry: ghcr.io
|
||
username: ${{ github.actor }}
|
||
password: ${{ secrets.GITHUB_TOKEN }} # 强烈建议直接用 GITHUB_TOKEN,不需要手动建 GHCR_TOKEN!
|
||
|
||
# 登录 Docker Hub(如果你还要推)
|
||
- name: 登录 Docker Hub
|
||
if: vars.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_TOKEN != ''
|
||
uses: docker/login-action@v3
|
||
with:
|
||
username: ${{ vars.DOCKERHUB_USERNAME }}
|
||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||
|
||
# 真正一键构建 + 推送多架构镜像(amd64 + arm64)
|
||
- name: 构建并推送多架构镜像
|
||
uses: docker/build-push-action@v6
|
||
with:
|
||
context: .
|
||
platforms: linux/amd64,linux/arm64
|
||
push: true
|
||
tags: |
|
||
ghcr.io/${{ github.repository_owner }}/ogame-vue-ts:latest
|
||
ghcr.io/${{ github.repository_owner }}/ogame-vue-ts:${{ github.sha }}
|
||
${{ vars.DOCKERHUB_USERNAME != '' && format('{0}/ogame-vue-ts:latest', vars.DOCKERHUB_USERNAME) || '' }}
|
||
${{ vars.DOCKERHUB_USERNAME != '' && format('{0}/ogame-vue-ts:{1}', vars.DOCKERHUB_USERNAME, github.sha) || '' }}
|
||
cache-from: type=gha
|
||
cache-to: type=gha,mode=max |