ghmark675

chore(workflow): build docker when push tag

  1 +name: Docker Image CI
  2 +
  3 +on:
  4 + push:
  5 + tags:
  6 + - 'v*'
  7 +
  8 +jobs:
  9 + build_and_publish:
  10 + runs-on: ubuntu-latest
  11 + permissions:
  12 + contents: read
  13 + packages: write
  14 +
  15 + steps:
  16 + - name: Checkout repository
  17 + uses: actions/checkout@v4
  18 +
  19 + - name: Log in to the Container registry
  20 + uses: docker/login-action@v3
  21 + with:
  22 + registry: ghcr.io
  23 + username: ${{ github.actor }}
  24 + password: ${{ secrets.GITHUB_TOKEN }}
  25 +
  26 + - name: Extract metadata (tags, labels) for Docker
  27 + id: meta
  28 + uses: docker/metadata-action@v5
  29 + with:
  30 + images: ghcr.io/${{ github.repository }}
  31 + tags: |
  32 + type=ref,event=tag
  33 + type=semver,pattern={{version}}
  34 + type=raw,value=latest
  35 +
  36 + - name: Set up Docker Buildx
  37 + uses: docker/setup-buildx-action@v3
  38 + with:
  39 + driver: docker-container
  40 +
  41 + - name: Build and push Docker image
  42 + uses: docker/build-push-action@v5
  43 + with:
  44 + context: .
  45 + push: true
  46 + tags: ${{ steps.meta.outputs.tags }}
  47 + labels: ${{ steps.meta.outputs.labels }}
  48 + cache-from: type=gha
  49 + cache-to: type=gha,mode=max