From 892a4ec4551a7e89a95cc3341483720d9af1658c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=8E=E5=A4=A9=E5=A5=BD=E5=83=8F=E6=B2=A1=E4=BB=80?= =?UTF-8?q?=E4=B9=88?= Date: Sat, 18 Oct 2025 20:58:47 +0800 Subject: [PATCH] =?UTF-8?q?ci(docker):=20=E9=87=8D=E6=9E=84CI/CD=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=EF=BC=8C=E6=94=AF=E6=8C=81=E5=A4=9A=E6=9E=B6=E6=9E=84?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E4=B8=8E=E8=87=AA=E5=8A=A8=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 启用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一致 --- .github/workflows/docker-image.yml | 156 +++++++++++++++++++++-------- docker-compose.yml | 25 +++-- 2 files changed, 124 insertions(+), 57 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 6ba5af06b..034539632 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -1,70 +1,51 @@ -name: Docker CI +name: Docker Build and Push on: - # push: - # branches: - # - master - # - develop - # tags: - # - "v*.*.*" - # - "v*" - # - "*.*.*" - # - "*.*.*-*" + push: + branches: + - master + - dev + tags: + - "v*.*.*" + - "v*" + - "*.*.*" + - "*.*.*-*" workflow_dispatch: # 允许手动触发工作流 +# Workflow's jobs jobs: build-amd64: - name: 构建 AMD64 镜像 + name: Build AMD64 Image runs-on: ubuntu-24.04 outputs: digest: ${{ steps.build.outputs.digest }} steps: - - name: 检出 Git 仓库 + - name: Check out git repository 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 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 with: buildkitd-flags: --debug - - name: 登录到 Docker Hub + # Log in docker hub + - name: Log in to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Docker 元数据 + # Generate metadata for Docker images + - name: Docker meta id: meta uses: docker/metadata-action@v5 with: - images: ${{ secrets.DOCKERHUB_USERNAME }}/maibot + images: ${{ secrets.DOCKERHUB_USERNAME }}/mofox - - 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 镜像 + # Build and push AMD64 image by digest + - name: Build and push AMD64 id: build uses: docker/build-push-action@v5 with: @@ -72,10 +53,97 @@ jobs: 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 }},name-canonical=true,push=true + cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/mofox:amd64-buildcache + cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/mofox:amd64-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 }} - 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 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 89d039a97..e7fe3cdb2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,20 +1,19 @@ services: core: - container_name: InkFox-Bot + container_name: MoFox-Bot #### prod #### - image: sengokucola/maibot:latest - # image: infinitycat/maibot:latest + image: hunuon/mofox:latest #### dev #### - # image: sengokucola/maibot:dev + # image: hunuon/mofox:dev environment: - TZ=Asia/Shanghai volumes: - - ./docker-config/mmc/.env:/InkFox/.env # 持久化env配置文件 - - ./docker-config/mmc:/InkFox/config # 持久化bot配置文件 - - ./data/InkFox/maibot_statistics.html:/InkFox/maibot_statistics.html #统计数据输出 - - ./data/InkFox:/InkFox/data # 共享目录 - - ./data/InkFox/plugins:/InkFox/plugins # 插件目录 - - ./data/InkFox/logs:/InkFox/logs # 日志目录 + - ./docker-config/core/.env:/app/.env # 持久化env配置文件 + - ./docker-config/core:/app/config # 持久化bot配置文件 + - ./data/core/maibot_statistics.html:/app/maibot_statistics.html #统计数据输出 + - ./data/app:/app/data # 共享目录 + - ./data/core/plugins:/app/plugins # 插件目录 + - ./data/core/logs:/app/logs # 日志目录 restart: always networks: - mofox @@ -28,8 +27,8 @@ services: volumes: - ./docker-config/napcat:/app/napcat/config # 持久化napcat配置文件 - ./data/qq:/app/.config/QQ # 持久化QQ本体 - - ./data/InkFox:/InkFox/data # 共享目录 - container_name: maim-bot-napcat + - ./data/app:/app/data # 共享目录 + container_name: mofox-napcat restart: always image: mlikiowa/napcat-docker:latest networks: @@ -44,7 +43,7 @@ services: # ports: # - "10824:10824" # volumes: - # - ./data/InkFox:/data/InkFox + # - ./data/chat2db:/data/app # networks: # - mofox volumes: