|
1 | | -name: Upload Docker images to ghcr.io |
| 1 | +name: Upload Docker images to GitHub Container Registry (ghcr.io) |
| 2 | + |
2 | 3 | on: |
3 | 4 | release: |
4 | 5 | types: [published] |
5 | | - workflow_dispatch: |
6 | | - inputs: |
7 | | - ref: |
8 | | - description: 'Git tag to push the image' |
9 | | - required: true |
10 | | - type: string |
| 6 | + push: |
| 7 | + branches: [ master, main ] |
| 8 | + tags: [ 'v*' ] |
| 9 | + pull_request: |
| 10 | + branches: [ master, main ] |
| 11 | + |
11 | 12 | jobs: |
12 | 13 | docker: |
13 | | - name: Build image |
| 14 | + name: Build images |
14 | 15 | runs-on: ubuntu-latest |
15 | 16 | steps: |
16 | 17 | - name: Check out code |
17 | 18 | uses: actions/checkout@v4 |
| 19 | + - name: Set up QEMU |
| 20 | + if: github.event_name != 'pull_request' |
| 21 | + uses: docker/setup-qemu-action@v3 |
18 | 22 | with: |
19 | | - ref: ${{ inputs.ref }} |
| 23 | + platforms: arm,arm64 |
| 24 | + cache-image: false |
| 25 | + - name: Set up Docker Buildx |
| 26 | + uses: docker/setup-buildx-action@v3 |
20 | 27 | - name: Docker meta |
21 | 28 | id: meta |
22 | 29 | uses: docker/metadata-action@v5 |
23 | 30 | with: |
24 | | - context: ${{ inputs.ref && 'git' || 'workflow' }} |
25 | 31 | images: ghcr.io/${{ github.repository }} |
26 | 32 | # create latest tag for branch events |
27 | 33 | flavor: | |
28 | | - latest=${{ inputs.ref && 'false' || 'auto' }} |
| 34 | + latest=${{ github.event_name == 'push' && github.ref_type == 'branch' }} |
29 | 35 | tags: | |
30 | | - type=semver,pattern={{version}},value=${{inputs.ref}} |
31 | | - type=semver,pattern={{major}}.{{minor}},value=${{inputs.ref}} |
32 | | - type=semver,pattern={{major}}.{{minor}}.{{patch}},value=${{inputs.ref}} |
33 | | - - name: Login to ghcr.io |
| 36 | + type=ref,event=branch |
| 37 | + type=ref,event=pr |
| 38 | + type=semver,pattern={{version}} |
| 39 | + type=semver,pattern={{major}}.{{minor}} |
| 40 | + type=semver,pattern={{major}}.{{minor}}.{{patch}} |
| 41 | + env: |
| 42 | + DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index |
| 43 | + - name: Login to GitHub Container Registry |
| 44 | + if: github.event_name != 'pull_request' |
34 | 45 | uses: docker/login-action@v3 |
35 | 46 | with: |
36 | 47 | registry: ghcr.io |
37 | 48 | username: ${{ github.actor }} |
38 | 49 | password: ${{ secrets.GITHUB_TOKEN }} |
| 50 | + - name: Build |
| 51 | + if: github.event_name == 'pull_request' |
| 52 | + uses: docker/build-push-action@v6 |
| 53 | + with: |
| 54 | + context: . |
| 55 | + platforms: linux/amd64 |
| 56 | + push: false |
| 57 | + tags: ${{ steps.meta.outputs.tags }} |
| 58 | + labels: ${{ steps.meta.outputs.labels }} |
| 59 | + annotations: ${{ steps.meta.outputs.annotations }} |
39 | 60 | - name: Build and push |
40 | | - id: docker_build |
41 | | - uses: docker/build-push-action@v5 |
| 61 | + if: github.event_name != 'pull_request' |
| 62 | + uses: docker/build-push-action@v6 |
42 | 63 | with: |
43 | | - # push for non-pr events |
44 | | - push: ${{ github.event_name != 'pull_request' }} |
45 | 64 | context: . |
| 65 | + platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 |
| 66 | + push: true |
46 | 67 | tags: ${{ steps.meta.outputs.tags }} |
47 | 68 | labels: ${{ steps.meta.outputs.labels }} |
| 69 | + annotations: ${{ steps.meta.outputs.annotations }} |
| 70 | + cache-from: type=gha |
| 71 | + cache-to: type=gha,mode=max |
0 commit comments