Files
Mofox-Core/.github/workflows/docker-image.yml
2025-08-17 12:36:35 +08:00

82 lines
2.3 KiB
YAML

name: Docker CI
on:
push:
branches:
- master
- develop
tags:
- "v*.*.*"
- "v*"
- "*.*.*"
- "*.*.*-*"
workflow_dispatch: # 允许手动触发工作流
jobs:
build-amd64:
name: 构建 AMD64 镜像
runs-on: ubuntu-24.04
outputs:
digest: ${{ steps.build.outputs.digest }}
steps:
- name: 检出 Git 仓库
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 克隆 maim_message
uses: actions/checkout@v4
with:
repository: MaiM-with-u/maim_message
path: maim_message
- name: 克隆 MaiMBot-LPMM
uses: actions/checkout@v4
with:
repository: MaiM-with-u/MaiMBot-LPMM
path: MaiMBot-LPMM
- name: 设置 Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
- name: 登录到 Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker 元数据
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKERHUB_USERNAME }}/maibot
- name: 动态生成镜像标签
id: tag
run: |
if [ "$GITHUB_REF" == "refs/heads/master" ]; then
echo "tag=latest" >> $GITHUB_ENV
elif [ "$GITHUB_REF" == "refs/heads/develop" ]; then
echo "tag=dev" >> $GITHUB_ENV
else
echo "tag=${{ github.ref_name }}" >> $GITHUB_ENV
fi
- name: 构建并推送 AMD64 镜像
id: build
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64
labels: ${{ steps.meta.outputs.labels }}
file: ./Dockerfile
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maibot:amd64-buildcache
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maibot:amd64-buildcache,mode=max
outputs: type=image,name=${{ secrets.DOCKERHUB_USERNAME }}/maibot:${{ env.tag }},push-by-digest=true,name-canonical=true,push=true
build-args: |
BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
VCS_REF=${{ github.sha }}
BRANCH_NAME=${{ github.ref_name }}