From 4b01a3f8921b93251ff4505a2f31e947653db70a Mon Sep 17 00:00:00 2001 From: Choco Date: Sat, 23 Aug 2025 10:53:59 +0800 Subject: [PATCH] Update docker-image.yml --- .github/workflows/docker-image.yml | 68 ++++++++++++++++-------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 3ffbf59..77ad3ed 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -16,38 +16,42 @@ permissions: jobs: build: runs-on: ubuntu-latest - steps: - uses: actions/checkout@v4 - - - name: Determine Image Tag - id: image_tag - run: | - if [ "${{ github.ref_type }}" == "tag" ]; then - IMAGE_NAME="ghcr.io/chocomeow/vocard:${{ github.ref_name }}" - elif [ "${{ github.ref }}" == "refs/heads/beta" ]; then - IMAGE_NAME="ghcr.io/chocomeow/vocard:beta" - elif [ "${{ github.ref }}" == "refs/heads/main" ]; then - IMAGE_NAME="ghcr.io/chocomeow/vocard:latest" - else - echo "Error: Triggered on an unexpected ref: ${{ github.ref }}" - exit 1 - fi - echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV - echo "Set image name to: ${IMAGE_NAME}" - - - name: Build the Docker image - run: | - echo "Building image: ${{ env.IMAGE_NAME }}" - docker build . --file Dockerfile --tag ${{ env.IMAGE_NAME }} - + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Log in to GitHub Docker Registry - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin - - - name: Push the Docker image - run: | - echo "Pushing image: ${{ env.IMAGE_NAME }}" - docker push ${{ env.IMAGE_NAME }} - echo "Successfully pushed ${{ env.IMAGE_NAME }}" \ No newline at end of file + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/chocomeow/vocard + tags: | + # For version tags (v1.2.3) + type=ref,event=tag + # For main branch + type=raw,value=latest,enable={{is_default_branch}} + # For beta branch + type=raw,value=beta,enable=${{ github.ref == 'refs/heads/beta' }} + flavor: | + latest=false + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64 + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file