Skip to content

refactor: simplify multi-arch Docker build workflow using direct buil… #66

refactor: simplify multi-arch Docker build workflow using direct buil…

refactor: simplify multi-arch Docker build workflow using direct buil… #66

Workflow file for this run

name: Build and Push Docker Image
on:
push:
branches: [ master, dev ]
tags: [ 'v*' ]
paths-ignore:
- 'README.md'
- 'docs/**'
- '*.md'
pull_request:
branches: [ master, dev ]
paths-ignore:
- 'README.md'
- 'docs/**'
- '*.md'
# 添加并发控制,避免重复构建
concurrency:
# 按分支分组,同分支的新构建会取消旧构建
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
env:
REGISTRY: docker.io
IMAGE_NAME: aethersailor/rule-bot
jobs:
# 构建并推送多架构镜像
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:v0.12.0
network=host
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=dev,enable=${{ github.ref == 'refs/heads/dev' || github.head_ref == 'dev' }}
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' || github.head_ref == 'master' }}
type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/') }}
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }}
labels: |
org.opencontainers.image.title=Rule Bot
org.opencontainers.image.description=Telegram bot for rule management
org.opencontainers.image.vendor=AetherSailor
- name: Build and push multi-arch image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BUILDKIT_INLINE_CACHE=1
BUILDKIT_STEP_LOG_MAX_SIZE=10485760
BUILDKIT_STEP_LOG_MAX_SPEED=10485760
provenance: false
- name: Verify multi-arch manifest
run: |
TAGS="${{ steps.meta.outputs.tags }}"
for tag in $TAGS; do
echo "Verifying manifest for $tag"
# 等待 manifest 创建完成
sleep 30
# 检查 manifest 是否包含所有架构
MANIFEST_OUTPUT=$(docker manifest inspect $tag 2>/dev/null || echo "{}")
echo "Manifest content: $MANIFEST_OUTPUT"
# 检查架构数量
ARCH_COUNT=$(echo "$MANIFEST_OUTPUT" | grep -o '"architecture"' | wc -l)
echo "Found $ARCH_COUNT architectures in manifest"
# 检查具体架构
echo "Checking specific architectures..."
if echo "$MANIFEST_OUTPUT" | grep -q '"architecture": "amd64"'; then
echo "✅ amd64 architecture found"
else
echo "❌ amd64 architecture missing"
fi
if echo "$MANIFEST_OUTPUT" | grep -q '"architecture": "arm64"'; then
echo "✅ arm64 architecture found"
else
echo "❌ arm64 architecture missing"
fi
if [ "$ARCH_COUNT" -lt 2 ]; then
echo "Warning: Not all architectures found in manifest"
echo "This might indicate a push or merge issue"
exit 1
else
echo "Success: All architectures found in manifest"
fi
done