diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index b9dc138..e9701e9 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,8 +1,14 @@ -name: Docker +name: Build and Publish Docker Image on: push: - branches: [main] + branches: + - main + tags: + - "v*" + pull_request: + branches: + - main env: REGISTRY: ghcr.io @@ -10,17 +16,20 @@ env: jobs: build-and-push: - name: Build & Push Docker Image runs-on: ubuntu-latest permissions: contents: read packages: write steps: - - name: Checkout code + - name: Checkout repository uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Log in to Container Registry + if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} @@ -33,13 +42,18 @@ jobs: with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | - type=raw,value=latest + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} type=sha,prefix= - name: Build and push Docker image uses: docker/build-push-action@v6 with: context: . - push: true + 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