|
| 1 | +name: Build and Push Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +env: |
| 10 | + CARGO_TERM_COLOR: always |
| 11 | + IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/rgb-lightning-node |
| 12 | + |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + include: |
| 19 | + - runner: ubuntu-latest |
| 20 | + platform: linux/amd64 |
| 21 | + arch: amd64 |
| 22 | + - runner: ubuntu-24.04-arm |
| 23 | + platform: linux/arm64 |
| 24 | + arch: arm64 |
| 25 | + runs-on: ${{ matrix.runner }} |
| 26 | + timeout-minutes: 60 |
| 27 | + steps: |
| 28 | + - name: Checkout code |
| 29 | + uses: actions/checkout@v4 |
| 30 | + with: |
| 31 | + submodules: recursive |
| 32 | + |
| 33 | + - name: Set up Docker Buildx |
| 34 | + uses: docker/setup-buildx-action@v3 |
| 35 | + |
| 36 | + - name: Login to Docker Hub |
| 37 | + uses: docker/login-action@v3 |
| 38 | + with: |
| 39 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 40 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 41 | + |
| 42 | + - name: Extract Docker metadata |
| 43 | + id: meta |
| 44 | + uses: docker/metadata-action@v5 |
| 45 | + with: |
| 46 | + images: ${{ env.IMAGE_NAME }} |
| 47 | + |
| 48 | + - name: Build and push by digest |
| 49 | + id: build |
| 50 | + uses: docker/build-push-action@v6 |
| 51 | + with: |
| 52 | + context: . |
| 53 | + platforms: ${{ matrix.platform }} |
| 54 | + labels: ${{ steps.meta.outputs.labels }} |
| 55 | + outputs: type=image,"name=${{ env.IMAGE_NAME }}",push-by-digest=true,name-canonical=true,push=true |
| 56 | + cache-from: type=gha,scope=${{ matrix.arch }} |
| 57 | + cache-to: type=gha,scope=${{ matrix.arch }},mode=max |
| 58 | + |
| 59 | + - name: Export digest |
| 60 | + run: | |
| 61 | + mkdir -p ${{ runner.temp }}/digests |
| 62 | + digest="${{ steps.build.outputs.digest }}" |
| 63 | + touch "${{ runner.temp }}/digests/${digest#sha256:}" |
| 64 | +
|
| 65 | + - name: Upload digest |
| 66 | + uses: actions/upload-artifact@v4 |
| 67 | + with: |
| 68 | + name: digest-${{ matrix.arch }} |
| 69 | + path: ${{ runner.temp }}/digests/* |
| 70 | + if-no-files-found: error |
| 71 | + retention-days: 1 |
| 72 | + |
| 73 | + merge: |
| 74 | + runs-on: ubuntu-latest |
| 75 | + needs: build |
| 76 | + timeout-minutes: 10 |
| 77 | + steps: |
| 78 | + - name: Download digests |
| 79 | + uses: actions/download-artifact@v4 |
| 80 | + with: |
| 81 | + path: ${{ runner.temp }}/digests |
| 82 | + pattern: digest-* |
| 83 | + merge-multiple: true |
| 84 | + |
| 85 | + - name: Login to Docker Hub |
| 86 | + uses: docker/login-action@v3 |
| 87 | + with: |
| 88 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 89 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 90 | + |
| 91 | + - name: Set up Docker Buildx |
| 92 | + uses: docker/setup-buildx-action@v3 |
| 93 | + |
| 94 | + - name: Extract Docker metadata |
| 95 | + id: meta |
| 96 | + uses: docker/metadata-action@v5 |
| 97 | + with: |
| 98 | + images: ${{ env.IMAGE_NAME }} |
| 99 | + tags: | |
| 100 | + type=raw,value=latest,enable={{is_default_branch}} |
| 101 | + type=semver,pattern={{version}} |
| 102 | +
|
| 103 | + - name: Create manifest list and push |
| 104 | + working-directory: ${{ runner.temp }}/digests |
| 105 | + run: | |
| 106 | + docker buildx imagetools create \ |
| 107 | + $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 108 | + $(printf '${{ env.IMAGE_NAME }}@sha256:%s ' *) |
| 109 | +
|
| 110 | + - name: Inspect image |
| 111 | + run: | |
| 112 | + docker buildx imagetools inspect "${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}" |
0 commit comments