Build and Push Multi-Arch Docker Image #114
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Push Multi-Arch Docker Image | |
on: | |
workflow_dispatch: | |
release: | |
types: [published] | |
pull_request: | |
branches: | |
- master | |
types: [closed] | |
paths: | |
- '**.py' | |
- 'requirements.txt' | |
- '!./web/**' | |
jobs: | |
build_and_push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
with: | |
platforms: all | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Extract Git Tag | |
id: extract_tag | |
run: | | |
GIT_TAG=$(git describe --tags --exact-match ${{ github.sha }} 2>/dev/null || echo "") | |
echo "GIT_TAG=$GIT_TAG" >> $GITHUB_ENV | |
- name: Build and Push Docker Image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
platforms: linux/amd64,linux/arm64 | |
file: ./Dockerfile | |
# 定义多架构标签 | |
tags: | | |
${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_REPOSITORY_NAME }}:latest | |
${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_REPOSITORY_NAME }}:${{ env.GIT_TAG }} | |
# 可选:缓存加速 | |
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_REPOSITORY_NAME }}:cache | |
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_REPOSITORY_NAME }}:cache,mode=max | |
- name: Verify Manifest | |
run: | | |
docker manifest inspect ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_REPOSITORY_NAME }}:latest | |
if [ -n "${{ env.GIT_TAG }}" ]; then | |
docker manifest inspect ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_REPOSITORY_NAME }}:${{ env.GIT_TAG }} | |
fi |