name: Build and Publish Docker Image on: release: types: [published] pull_request: branches: [main] env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} DOCKERHUB_REGISTRY: docker.io DOCKERHUB_IMAGE_NAME: variantconst/openwebui-monitor jobs: build: runs-on: ubuntu-latest permissions: contents: read packages: write steps: # 检出代码 - name: Checkout repository uses: actions/checkout@v4 # 设置 QEMU(支持多平台) - name: Set up QEMU uses: docker/setup-qemu-action@v3 # 设置 Docker Buildx(支持多平台构建) - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 # 登录到 GitHub Container Registry (GHCR) - name: Log into GHCR if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} # 登录到 Docker Hub - name: Log into Docker Hub if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: registry: ${{ env.DOCKERHUB_REGISTRY }} username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} # 提取 Docker 元数据 - name: Extract Docker metadata id: meta uses: docker/metadata-action@v5 with: images: | ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} ${{ env.DOCKERHUB_REGISTRY }}/${{ env.DOCKERHUB_IMAGE_NAME }} tags: | type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=sha type=raw,value=latest,enable={{is_default_branch}} # 构建并推送到 GHCR 和 Docker Hub - name: Build and push Docker image uses: docker/build-push-action@v5 with: context: . platforms: linux/amd64,linux/arm64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max provenance: false