Update docker-image.yml
This commit is contained in:
96
.github/workflows/docker-image.yml
vendored
96
.github/workflows/docker-image.yml
vendored
@@ -1,66 +1,54 @@
|
|||||||
name: Docker 构建与推送
|
name: Docker 镜像构建与推送
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches: [ "master", "develop" ] # 触发分支
|
||||||
- master
|
|
||||||
tags:
|
|
||||||
- "v*.*.*"
|
|
||||||
- "v*"
|
|
||||||
- "*.*.*"
|
|
||||||
- "*.*.*-*"
|
|
||||||
workflow_dispatch: # 允许手动触发工作流
|
workflow_dispatch: # 允许手动触发工作流
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-amd64:
|
|
||||||
name: 构建 AMD64 镜像
|
build:
|
||||||
runs-on: ubuntu-24.04
|
|
||||||
outputs:
|
runs-on: ubuntu-latest
|
||||||
digest: ${{ steps.build.outputs.digest }}
|
env:
|
||||||
|
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USERNAME }} # Docker Hub 用户名
|
||||||
|
DATE_TAG: $(date -u +'%Y-%m-%dT%H-%M-%S') # 用于生成时间戳标签
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: 检出 Git 仓库
|
- name: 检出代码
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
# 克隆所需依赖
|
- name: 设置 Docker Buildx
|
||||||
- name: 克隆 maim_message
|
uses: docker/setup-buildx-action@v3
|
||||||
run: git clone https://github.com/MaiM-with-u/maim_message maim_message
|
|
||||||
|
|
||||||
- name: 克隆 lpmm
|
- name: 登录 Docker Hub
|
||||||
run: git clone https://github.com/MaiM-with-u/MaiMBot-LPMM.git MaiMBot-LPMM
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }} # Docker Hub 用户名
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }} # Docker Hub 密码
|
||||||
|
|
||||||
- name: 设置 Docker Buildx
|
- name: 克隆 maim_message 仓库
|
||||||
uses: docker/setup-buildx-action@v3
|
run: git clone https://github.com/MaiM-with-u/maim_message maim_message
|
||||||
with:
|
|
||||||
buildkitd-flags: --debug
|
|
||||||
|
|
||||||
# 登录 Docker Hub
|
- name: 确定镜像标签
|
||||||
- name: 登录到 Docker Hub
|
id: tags
|
||||||
uses: docker/login-action@v3
|
run: |
|
||||||
with:
|
if [ "${{ github.ref_name }}" == "master" ]; then
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
echo "tags=${{ secrets.DOCKERHUB_USERNAME }}/maimbot-adapter:latest,${{ secrets.DOCKERHUB_USERNAME }}/maimbot-adapter:master-$(date -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
elif [ "${{ github.ref_name }}" == "develop" ]; then
|
||||||
|
echo "tags=${{ secrets.DOCKERHUB_USERNAME }}/maimbot-adapter:dev,${{ secrets.DOCKERHUB_USERNAME }}/maimbot-adapter:develop-$(date -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
# 生成 Docker 镜像元数据
|
- name: 构建并推送 Docker 镜像
|
||||||
- name: Docker 元数据
|
uses: docker/build-push-action@v5
|
||||||
id: meta
|
with:
|
||||||
uses: docker/metadata-action@v5
|
context: . # 构建上下文
|
||||||
with:
|
file: ./Dockerfile # Dockerfile 路径
|
||||||
images: ${{ secrets.DOCKERHUB_USERNAME }}/maibot
|
platforms: linux/amd64,linux/arm64 # 构建平台
|
||||||
|
tags: ${{ steps.tags.outputs.tags }} # 镜像标签
|
||||||
# 构建并推送 AMD64 镜像
|
push: true # 推送镜像
|
||||||
- name: 构建并推送 AMD64
|
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maimbot-adapter:buildcache-${{ github.ref_name }} # 缓存来源
|
||||||
id: build
|
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maimbot-adapter:buildcache-${{ github.ref_name }},mode=max # 缓存目标
|
||||||
uses: docker/build-push-action@v5
|
labels: |
|
||||||
with:
|
org.opencontainers.image.created=${{ steps.tags.outputs.date_tag }} # 镜像创建时间
|
||||||
context: .
|
org.opencontainers.image.revision=${{ github.sha }} # 镜像修订版本
|
||||||
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,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 }}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user