|
| 1 | +name: docker publish |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: [ 'build' ] |
| 6 | + types: [ completed ] |
| 7 | + branches: [ 'master' ] |
| 8 | + tags: [ 'v*' ] |
| 9 | + |
| 10 | +env: |
| 11 | + PLATFORMS: linux/amd64,linux/arm64,linux/arm/v7 |
| 12 | + # github.repository as <account>/<repo> |
| 13 | + IMAGE_NAME: ${{ github.repository }} |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 19 | + steps: |
| 20 | + - name: Checkout repository |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Set up QEMU |
| 24 | + uses: docker/setup-qemu-action@v3 |
| 25 | + |
| 26 | + - name: Set up Docker Buildx |
| 27 | + uses: docker/setup-buildx-action@v3 |
| 28 | + |
| 29 | + - name: Login to Docker Hub |
| 30 | + if: github.event_name != 'pull_request' |
| 31 | + uses: docker/login-action@v3 |
| 32 | + with: |
| 33 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 34 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 35 | + |
| 36 | + # Extract metadata (tags, labels) for Docker |
| 37 | + # https://github.com/docker/metadata-action |
| 38 | + - name: Extract Docker metadata |
| 39 | + id: meta |
| 40 | + uses: docker/metadata-action@v5 |
| 41 | + with: |
| 42 | + images: ${{ env.IMAGE_NAME }} |
| 43 | + tags: | |
| 44 | + type=ref,event=branch |
| 45 | + type=ref,event=pr |
| 46 | + type=semver,pattern={{version}} |
| 47 | + type=semver,pattern={{major}}.{{minor}} |
| 48 | + type=sha |
| 49 | +
|
| 50 | + # Build and push Docker image with Buildx (don't push on PR) |
| 51 | + # https://github.com/docker/build-push-action |
| 52 | + - name: Build and push Docker image |
| 53 | + id: build-and-push |
| 54 | + uses: docker/build-push-action@v5 |
| 55 | + with: |
| 56 | + context: . |
| 57 | + platforms: ${{ env.PLATFORMS }} |
| 58 | + push: ${{ github.event_name != 'pull_request' }} |
| 59 | + tags: ${{ steps.meta.outputs.tags }} |
| 60 | + labels: ${{ steps.meta.outputs.labels }} |
| 61 | + cache-from: type=gha,scope=${{ env.IMAGE_NAME }} |
| 62 | + cache-to: type=gha,mode=max,scope=${{ env.IMAGE_NAME }} |
0 commit comments