|
| 1 | +name: Build and Push Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - master |
| 8 | + tags: |
| 9 | + - 'v*' |
| 10 | + pull_request: |
| 11 | + branches: |
| 12 | + - main |
| 13 | + - master |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: read |
| 17 | + packages: write # Permission to write to GitHub Container Registry |
| 18 | + |
| 19 | +jobs: |
| 20 | + build-and-push: |
| 21 | + name: Build and Push Docker Image |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - name: Checkout |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Set up QEMU |
| 28 | + uses: docker/setup-qemu-action@v3 |
| 29 | + |
| 30 | + - name: Set up Docker Buildx |
| 31 | + uses: docker/setup-buildx-action@v3 |
| 32 | + |
| 33 | + - name: Docker metadata |
| 34 | + id: meta |
| 35 | + uses: docker/metadata-action@v5 |
| 36 | + with: |
| 37 | + images: | |
| 38 | + plexguide/huntarr |
| 39 | + ghcr.io/plexguide/huntarr |
| 40 | + tags: | |
| 41 | + type=ref,event=branch |
| 42 | + type=ref,event=pr |
| 43 | + type=semver,pattern={{version}} |
| 44 | + type=semver,pattern={{major}}.{{minor}} |
| 45 | + type=sha,format=short |
| 46 | + type=raw,value=latest,enable={{is_default_branch}} |
| 47 | +
|
| 48 | + # Login to DockerHub |
| 49 | + - name: Login to DockerHub |
| 50 | + if: github.event_name != 'pull_request' |
| 51 | + uses: docker/login-action@v3 |
| 52 | + with: |
| 53 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 54 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 55 | + |
| 56 | + # Login to GitHub Container Registry |
| 57 | + - name: Login to GitHub Container Registry |
| 58 | + if: github.event_name != 'pull_request' |
| 59 | + uses: docker/login-action@v3 |
| 60 | + with: |
| 61 | + registry: ghcr.io |
| 62 | + username: ${{ github.actor }} |
| 63 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 64 | + |
| 65 | + # Build and push to both Docker Hub and GitHub Container Registry |
| 66 | + - name: Build and Push |
| 67 | + uses: docker/build-push-action@v5 |
| 68 | + with: |
| 69 | + context: . |
| 70 | + platforms: linux/amd64,linux/arm64 |
| 71 | + push: ${{ github.event_name != 'pull_request' }} |
| 72 | + tags: ${{ steps.meta.outputs.tags }} |
| 73 | + labels: ${{ steps.meta.outputs.labels }} |
| 74 | + cache-from: type=gha |
| 75 | + cache-to: type=gha,mode=max |
0 commit comments