ci(docker): 重构CI/CD流程,支持多架构构建与自动推送
- 启用push触发,支持master/dev分支及版本标签 - 新增ARM64独立构建任务,使用ubuntu-24.04-arm运行器 - 引入docker/metadata-action自动生成标签,支持分支、标签、semver及sha - 采用push-by-digest方式分别构建AMD64/ARM64镜像,最后合并多架构manifest - 移除maim_message与MaiMBot-LPMM子模块克隆步骤,镜像名由maibot改为mofox - docker-compose同步更新镜像名、容器名及挂载路径,保持与CI一致
This commit is contained in:
156
.github/workflows/docker-image.yml
vendored
156
.github/workflows/docker-image.yml
vendored
@@ -1,70 +1,51 @@
|
|||||||
name: Docker CI
|
name: Docker Build and Push
|
||||||
|
|
||||||
on:
|
on:
|
||||||
# push:
|
push:
|
||||||
# branches:
|
branches:
|
||||||
# - master
|
- master
|
||||||
# - develop
|
- dev
|
||||||
# tags:
|
tags:
|
||||||
# - "v*.*.*"
|
- "v*.*.*"
|
||||||
# - "v*"
|
- "v*"
|
||||||
# - "*.*.*"
|
- "*.*.*"
|
||||||
# - "*.*.*-*"
|
- "*.*.*-*"
|
||||||
workflow_dispatch: # 允许手动触发工作流
|
workflow_dispatch: # 允许手动触发工作流
|
||||||
|
|
||||||
|
# Workflow's jobs
|
||||||
jobs:
|
jobs:
|
||||||
build-amd64:
|
build-amd64:
|
||||||
name: 构建 AMD64 镜像
|
name: Build AMD64 Image
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
outputs:
|
outputs:
|
||||||
digest: ${{ steps.build.outputs.digest }}
|
digest: ${{ steps.build.outputs.digest }}
|
||||||
steps:
|
steps:
|
||||||
- name: 检出 Git 仓库
|
- name: Check out git repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: 克隆 maim_message
|
- name: Set up Docker Buildx
|
||||||
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
|
uses: docker/setup-buildx-action@v3
|
||||||
with:
|
with:
|
||||||
buildkitd-flags: --debug
|
buildkitd-flags: --debug
|
||||||
|
|
||||||
- name: 登录到 Docker Hub
|
# Log in docker hub
|
||||||
|
- name: Log in to Docker Hub
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Docker 元数据
|
# Generate metadata for Docker images
|
||||||
|
- name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v5
|
||||||
with:
|
with:
|
||||||
images: ${{ secrets.DOCKERHUB_USERNAME }}/maibot
|
images: ${{ secrets.DOCKERHUB_USERNAME }}/mofox
|
||||||
|
|
||||||
- name: 动态生成镜像标签
|
# Build and push AMD64 image by digest
|
||||||
id: tag
|
- name: Build and push AMD64
|
||||||
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
|
id: build
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
@@ -72,10 +53,97 @@ jobs:
|
|||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maibot:amd64-buildcache
|
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/mofox:amd64-buildcache
|
||||||
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maibot:amd64-buildcache,mode=max
|
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/mofox:amd64-buildcache,mode=max
|
||||||
outputs: type=image,name=${{ secrets.DOCKERHUB_USERNAME }}/maibot:${{ env.tag }},name-canonical=true,push=true
|
outputs: type=image,name=${{ secrets.DOCKERHUB_USERNAME }}/mofox,push-by-digest=true,name-canonical=true,push=true
|
||||||
build-args: |
|
build-args: |
|
||||||
BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
|
BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
|
||||||
VCS_REF=${{ github.sha }}
|
VCS_REF=${{ github.sha }}
|
||||||
BRANCH_NAME=${{ github.ref_name }}
|
|
||||||
|
build-arm64:
|
||||||
|
name: Build ARM64 Image
|
||||||
|
runs-on: ubuntu-24.04-arm
|
||||||
|
outputs:
|
||||||
|
digest: ${{ steps.build.outputs.digest }}
|
||||||
|
steps:
|
||||||
|
- name: Check out git repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
with:
|
||||||
|
buildkitd-flags: --debug
|
||||||
|
|
||||||
|
# Log in docker hub
|
||||||
|
- name: Log in to Docker Hub
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
|
# Generate metadata for Docker images
|
||||||
|
- name: Docker meta
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ${{ secrets.DOCKERHUB_USERNAME }}/mofox
|
||||||
|
|
||||||
|
# Build and push ARM64 image by digest
|
||||||
|
- name: Build and push ARM64
|
||||||
|
id: build
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: linux/arm64/v8
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
file: ./Dockerfile
|
||||||
|
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/mofox:arm64-buildcache
|
||||||
|
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/mofox:arm64-buildcache,mode=max
|
||||||
|
outputs: type=image,name=${{ secrets.DOCKERHUB_USERNAME }}/mofox,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 }}
|
||||||
|
|
||||||
|
create-manifest:
|
||||||
|
name: Create Multi-Arch Manifest
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
needs:
|
||||||
|
- build-amd64
|
||||||
|
- build-arm64
|
||||||
|
steps:
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
# Log in docker hub
|
||||||
|
- name: Log in to Docker Hub
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
|
# Generate metadata for Docker images
|
||||||
|
- name: Docker meta
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ${{ secrets.DOCKERHUB_USERNAME }}/mofox
|
||||||
|
tags: |
|
||||||
|
type=ref,event=branch
|
||||||
|
type=ref,event=tag
|
||||||
|
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
type=semver,pattern={{major}}
|
||||||
|
type=sha,prefix=${{ github.ref_name }}-,enable=${{ github.ref_type == 'branch' }}
|
||||||
|
|
||||||
|
- name: Create and Push Manifest
|
||||||
|
run: |
|
||||||
|
# 为每个标签创建多架构镜像
|
||||||
|
for tag in $(echo "${{ steps.meta.outputs.tags }}" | tr '\n' ' '); do
|
||||||
|
echo "Creating manifest for $tag"
|
||||||
|
docker buildx imagetools create -t $tag \
|
||||||
|
${{ secrets.DOCKERHUB_USERNAME }}/mofox@${{ needs.build-amd64.outputs.digest }} \
|
||||||
|
${{ secrets.DOCKERHUB_USERNAME }}/mofox@${{ needs.build-arm64.outputs.digest }}
|
||||||
|
done
|
||||||
@@ -1,20 +1,19 @@
|
|||||||
services:
|
services:
|
||||||
core:
|
core:
|
||||||
container_name: InkFox-Bot
|
container_name: MoFox-Bot
|
||||||
#### prod ####
|
#### prod ####
|
||||||
image: sengokucola/maibot:latest
|
image: hunuon/mofox:latest
|
||||||
# image: infinitycat/maibot:latest
|
|
||||||
#### dev ####
|
#### dev ####
|
||||||
# image: sengokucola/maibot:dev
|
# image: hunuon/mofox:dev
|
||||||
environment:
|
environment:
|
||||||
- TZ=Asia/Shanghai
|
- TZ=Asia/Shanghai
|
||||||
volumes:
|
volumes:
|
||||||
- ./docker-config/mmc/.env:/InkFox/.env # 持久化env配置文件
|
- ./docker-config/core/.env:/app/.env # 持久化env配置文件
|
||||||
- ./docker-config/mmc:/InkFox/config # 持久化bot配置文件
|
- ./docker-config/core:/app/config # 持久化bot配置文件
|
||||||
- ./data/InkFox/maibot_statistics.html:/InkFox/maibot_statistics.html #统计数据输出
|
- ./data/core/maibot_statistics.html:/app/maibot_statistics.html #统计数据输出
|
||||||
- ./data/InkFox:/InkFox/data # 共享目录
|
- ./data/app:/app/data # 共享目录
|
||||||
- ./data/InkFox/plugins:/InkFox/plugins # 插件目录
|
- ./data/core/plugins:/app/plugins # 插件目录
|
||||||
- ./data/InkFox/logs:/InkFox/logs # 日志目录
|
- ./data/core/logs:/app/logs # 日志目录
|
||||||
restart: always
|
restart: always
|
||||||
networks:
|
networks:
|
||||||
- mofox
|
- mofox
|
||||||
@@ -28,8 +27,8 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./docker-config/napcat:/app/napcat/config # 持久化napcat配置文件
|
- ./docker-config/napcat:/app/napcat/config # 持久化napcat配置文件
|
||||||
- ./data/qq:/app/.config/QQ # 持久化QQ本体
|
- ./data/qq:/app/.config/QQ # 持久化QQ本体
|
||||||
- ./data/InkFox:/InkFox/data # 共享目录
|
- ./data/app:/app/data # 共享目录
|
||||||
container_name: maim-bot-napcat
|
container_name: mofox-napcat
|
||||||
restart: always
|
restart: always
|
||||||
image: mlikiowa/napcat-docker:latest
|
image: mlikiowa/napcat-docker:latest
|
||||||
networks:
|
networks:
|
||||||
@@ -44,7 +43,7 @@ services:
|
|||||||
# ports:
|
# ports:
|
||||||
# - "10824:10824"
|
# - "10824:10824"
|
||||||
# volumes:
|
# volumes:
|
||||||
# - ./data/InkFox:/data/InkFox
|
# - ./data/chat2db:/data/app
|
||||||
# networks:
|
# networks:
|
||||||
# - mofox
|
# - mofox
|
||||||
volumes:
|
volumes:
|
||||||
|
|||||||
Reference in New Issue
Block a user