|
1 |
| -name: Docker Release |
| 1 | +name: Docker |
2 | 2 |
|
3 | 3 | on:
|
4 | 4 | push:
|
5 | 5 | tags:
|
6 |
| - - '*' |
7 |
| - branches: |
8 |
| - - master |
| 6 | + - "*" |
| 7 | + workflow_dispatch: |
9 | 8 |
|
10 |
| -permissions: |
11 |
| - contents: read |
| 9 | +env: |
| 10 | + REGISTRY_IMAGE: mergeability/mergeable |
12 | 11 |
|
13 | 12 | jobs:
|
14 |
| - init: |
15 |
| - permissions: |
16 |
| - contents: none |
17 |
| - runs-on: ubuntu-latest |
18 |
| - outputs: |
19 |
| - do_docker: ${{ steps.vars.outputs.IS_DOCKERHUB_PUSH }} |
20 |
| - steps: |
21 |
| - - name: Initialize workflow variables |
22 |
| - shell: bash |
23 |
| - run: | |
24 |
| - # work-around for inaccessible 'secrets' object for 'if'; see <https://github.community/t5/GitHub-Actions/jobs-lt-job-id-gt-if-does-not-work-with-env-secrets/m-p/38549>) |
25 |
| - unset IS_DOCKERHUB_PUSH |
26 |
| - if [ -z "$DOCKERHUB_PUSH" ]; then IS_DOCKERHUB_PUSH='false'; else IS_DOCKERHUB_PUSH='true' ; fi |
27 |
| - echo set-output name=IS_DOCKERHUB_PUSH::${IS_DOCKERHUB_PUSH} |
28 |
| - echo ::set-output name=IS_DOCKERHUB_PUSH::${IS_DOCKERHUB_PUSH} |
29 |
| - env: |
30 |
| - DOCKERHUB_PUSH: ${{ secrets.DOCKERHUB_PUSH }} |
31 | 13 | build:
|
32 |
| - name: Build and push Docker image |
33 | 14 | runs-on: ubuntu-latest
|
34 |
| - needs: [init] |
35 |
| - if: ${{ needs.init.outputs.do_docker == 'true' }} |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + platform: |
| 19 | + - linux/amd64 |
| 20 | + # Failing to build |
| 21 | + # - linux/arm/v6 |
| 22 | + - linux/arm/v7 |
| 23 | + - linux/arm64 |
36 | 24 | steps:
|
| 25 | + - name: Prepare |
| 26 | + run: | |
| 27 | + platform=${{ matrix.platform }} |
| 28 | + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV |
| 29 | + |
37 | 30 | - name: Checkout
|
38 |
| - uses: actions/checkout@v2 |
39 |
| - |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Docker meta |
| 34 | + id: meta |
| 35 | + uses: docker/metadata-action@v5 |
| 36 | + with: |
| 37 | + images: ${{ env.REGISTRY_IMAGE }} |
| 38 | + |
40 | 39 | - name: Set up Docker Buildx
|
41 |
| - uses: docker/setup-buildx-action@v1 |
42 |
| - |
43 |
| - - name: Login to DockerHub |
44 |
| - uses: docker/login-action@v1 |
| 40 | + uses: docker/setup-buildx-action@v3 |
| 41 | + |
| 42 | + - name: Login to Docker Hub |
| 43 | + uses: docker/login-action@v3 |
45 | 44 | with:
|
46 | 45 | username: ${{ secrets.DOCKERHUB_USERNAME }}
|
47 |
| - password: ${{ secrets.DOCKERHUB_PASSWORD }} |
48 |
| - |
49 |
| - - name: Build and push latest |
50 |
| - uses: docker/build-push-action@v2 |
51 |
| - if: github.ref == 'refs/heads/master' |
| 46 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 47 | + |
| 48 | + - name: Build and push by digest |
| 49 | + id: build |
| 50 | + uses: docker/build-push-action@v5 |
52 | 51 | with:
|
53 |
| - push: true |
54 |
| - tags: ${{ secrets.DOCKERHUB_REPO }}:latest |
55 |
| - |
56 |
| - - name: Set version variable |
57 |
| - id: version |
58 |
| - if: startsWith(github.ref, 'refs/tags/') |
59 |
| - run: echo ::set-output name=TAG::${GITHUB_REF#refs/tags/} |
| 52 | + context: . |
| 53 | + platforms: ${{ matrix.platform }} |
| 54 | + labels: ${{ steps.meta.outputs.labels }} |
| 55 | + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true |
| 56 | + cache-from: type=gha,scope=build-${{ matrix.platform }} |
| 57 | + cache-to: type=gha,mode=max,scope=build-${{ matrix.platform }} |
| 58 | + |
| 59 | + - name: Export digest |
| 60 | + run: | |
| 61 | + mkdir -p /tmp/digests |
| 62 | + digest="${{ steps.build.outputs.digest }}" |
| 63 | + touch "/tmp/digests/${digest#sha256:}" |
| 64 | + |
| 65 | + - name: Upload digest |
| 66 | + uses: actions/upload-artifact@v4 |
| 67 | + with: |
| 68 | + name: digests-${{ env.PLATFORM_PAIR }} |
| 69 | + path: /tmp/digests/* |
| 70 | + if-no-files-found: error |
| 71 | + retention-days: 1 |
60 | 72 |
|
61 |
| - - name: Build and push tag |
62 |
| - uses: docker/build-push-action@v2 |
63 |
| - if: startsWith(github.ref, 'refs/tags/') |
| 73 | + merge: |
| 74 | + runs-on: ubuntu-latest |
| 75 | + needs: |
| 76 | + - build |
| 77 | + steps: |
| 78 | + - name: Download digests |
| 79 | + uses: actions/download-artifact@v4 |
| 80 | + with: |
| 81 | + path: /tmp/digests |
| 82 | + pattern: digests-* |
| 83 | + merge-multiple: true |
| 84 | + |
| 85 | + - name: Set up Docker Buildx |
| 86 | + uses: docker/setup-buildx-action@v3 |
| 87 | + |
| 88 | + - name: Docker meta |
| 89 | + id: meta |
| 90 | + uses: docker/metadata-action@v5 |
64 | 91 | with:
|
65 |
| - push: true |
66 |
| - tags: ${{ secrets.DOCKERHUB_REPO }}:${{ steps.version.outputs.TAG }} |
| 92 | + images: ${{ env.REGISTRY_IMAGE }} |
| 93 | + tags: | |
| 94 | + # minimal |
| 95 | + type=semver,pattern={{version}} |
| 96 | + # set latest tag for default branch |
| 97 | + type=raw,value=latest,enable={{is_default_branch}} |
| 98 | + |
| 99 | + - name: Login to Docker Hub |
| 100 | + uses: docker/login-action@v3 |
| 101 | + with: |
| 102 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 103 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 104 | + |
| 105 | + - name: Create manifest list and push |
| 106 | + working-directory: /tmp/digests |
| 107 | + run: | |
| 108 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 109 | + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) |
| 110 | + |
| 111 | + - name: Inspect image |
| 112 | + run: | |
| 113 | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} |
0 commit comments