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