ci docker

pull/55/head
野原小牛 2025-03-05 09:51:39 +08:00
parent 8e48e72019
commit a8df542146
1 changed files with 23 additions and 12 deletions

View File

@ -3,10 +3,11 @@ name: Docker Build and Push
on: on:
push: push:
branches: branches:
- main # 推送到main分支时触发 - main
- debug # 新增 debug 分支触发
tags: tags:
- 'v*' # 推送v开头的tag时触发例如v1.0.0 - 'v*'
workflow_dispatch: # 允许手动触发 workflow_dispatch:
jobs: jobs:
build-and-push: build-and-push:
@ -24,15 +25,25 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }} username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }} password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Determine Image Tags
id: tags
run: |
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
echo "::set-output name=tags::${DOCKERHUB_USERNAME}/maimbot:${{ github.ref_name }},${DOCKERHUB_USERNAME}/maimbot:latest"
elif [ "${{ github.ref }}" == "refs/heads/main" ]; then
echo "::set-output name=tags::${DOCKERHUB_USERNAME}/maimbot:main,${DOCKERHUB_USERNAME}/maimbot:latest"
elif [ "${{ github.ref }}" == "refs/heads/debug" ]; then
echo "::set-output name=tags::${DOCKERHUB_USERNAME}/maimbot:debug"
fi
DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}
- name: Build and Push Docker Image - name: Build and Push Docker Image
uses: docker/build-push-action@v5 uses: docker/build-push-action@v5
with: with:
context: . # Docker构建上下文路径 context: .
file: ./Dockerfile # Dockerfile路径 file: ./Dockerfile
platforms: linux/amd64,linux/arm64 # 支持arm架构 platforms: linux/amd64,linux/arm64
tags: | tags: ${{ steps.tags.outputs.tags }}
${{ secrets.DOCKERHUB_USERNAME }}/maimbot:${{ github.ref_name }} push: true
${{ secrets.DOCKERHUB_USERNAME }}/maimbot:latest cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maimbot:buildcache
push: true cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maimbot:buildcache,mode=max
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/maimbot:latest
cache-to: type=inline