|
| 1 | +# Copyright the Hyperledger Fabric contributors. All rights reserved. |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +name: Release |
| 6 | + |
| 7 | +on: |
| 8 | + push: |
| 9 | + tags: [v2.*] |
| 10 | + |
| 11 | +env: |
| 12 | + UBUNTU_VER: 22.04 |
| 13 | + FABRIC_VER: ${{ github.ref_name }} |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: read |
| 17 | + |
| 18 | +jobs: |
| 19 | + build-binaries: |
| 20 | + name: Build Fabric Binaries |
| 21 | + strategy: |
| 22 | + matrix: |
| 23 | + include: |
| 24 | + - image: ubuntu-22.04 |
| 25 | + target: linux |
| 26 | + arch: amd64 |
| 27 | + - image: ubuntu-22.04 |
| 28 | + target: linux |
| 29 | + arch: arm64 |
| 30 | + - image: macos-11 |
| 31 | + target: darwin |
| 32 | + arch: amd64 |
| 33 | + - image: macos-11 |
| 34 | + target: darwin |
| 35 | + arch: arm64 |
| 36 | + - image: windows-2022 |
| 37 | + target: windows |
| 38 | + arch: amd64 |
| 39 | + runs-on: ubuntu-22.04 |
| 40 | + steps: |
| 41 | + - name: Checkout Fabric Code |
| 42 | + uses: actions/checkout@v4 |
| 43 | + - name: Install Go |
| 44 | + uses: actions/setup-go@v5 |
| 45 | + with: |
| 46 | + go-version-file: go.mod |
| 47 | + - name: Compile Binary and Create Tarball |
| 48 | + run: ./ci/scripts/create_binary_package.sh |
| 49 | + env: |
| 50 | + TARGET: ${{ matrix.target }}-${{ matrix.arch }} |
| 51 | + RELEASE: ${{ env.FABRIC_VER }} |
| 52 | + |
| 53 | + - name: Publish Release Artifact |
| 54 | + uses: actions/upload-artifact@v4 |
| 55 | + with: |
| 56 | + # <name> of the artifact must not collide between platform/arch builds |
| 57 | + name: release-${{ matrix.target }}-${{ matrix.arch }} |
| 58 | + # <path> of the artifact may include multiple files. |
| 59 | + path: release/${{ matrix.target }}-${{ matrix.arch }}/*.tar.gz |
| 60 | + |
| 61 | + # build native images using a different runner for each architecture (faster and more reliable than using qemu to build multi-architecture images on ubuntu-22.04) |
| 62 | + build-and-push-native-docker-images: |
| 63 | + name: Build and Push native images |
| 64 | + runs-on: ${{ matrix.runner }} |
| 65 | + |
| 66 | + permissions: |
| 67 | + contents: read |
| 68 | + packages: write |
| 69 | + |
| 70 | + strategy: |
| 71 | + fail-fast: false |
| 72 | + matrix: |
| 73 | + runner: |
| 74 | + - ubuntu-22.04 # creates linux-amd64 images |
| 75 | + - ubuntu-22.04-arm # creates linux-arm64 images |
| 76 | + |
| 77 | + component: |
| 78 | + - name: baseos |
| 79 | + context: images/baseos |
| 80 | + - name: ccenv |
| 81 | + context: images/ccenv |
| 82 | + - name: peer |
| 83 | + context: . |
| 84 | + - name: orderer |
| 85 | + context: . |
| 86 | + - name: tools |
| 87 | + context: . |
| 88 | + |
| 89 | + steps: |
| 90 | + - name: Checkout |
| 91 | + uses: actions/checkout@v4 |
| 92 | + |
| 93 | + - name: Set GO_VER environment variable from go.mod |
| 94 | + run: | |
| 95 | + awk '/^go[ /t]/ { gsub(/^go[ \t]+|[ \t]+^/, ""); print "GO_VER="$0; exit }' < go.mod >> "${GITHUB_ENV}" |
| 96 | +
|
| 97 | + - name: Login to the docker.io Container Registry |
| 98 | + uses: docker/login-action@v3 |
| 99 | + with: |
| 100 | + registry: "docker.io" |
| 101 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 102 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 103 | + |
| 104 | + - name: Set up Docker Buildx |
| 105 | + uses: docker/setup-buildx-action@v3 |
| 106 | + |
| 107 | + - name: Docker meta |
| 108 | + id: meta |
| 109 | + uses: docker/metadata-action@v5 |
| 110 | + with: |
| 111 | + images: docker.io/${{ github.repository_owner }}/fabric-${{ matrix.component.name }} |
| 112 | + |
| 113 | + - name: Build and push ${{ matrix.component.name }} Image |
| 114 | + id: build-and-push |
| 115 | + uses: docker/build-push-action@v6 |
| 116 | + with: |
| 117 | + context: ${{ matrix.component.context }} |
| 118 | + file: images/${{ matrix.component.name }}/Dockerfile |
| 119 | + labels: ${{ steps.meta.outputs.labels }} |
| 120 | + build-args: | |
| 121 | + FABRIC_VER=${{ env.FABRIC_VER }} |
| 122 | + UBUNTU_VER=${{ env.UBUNTU_VER }} |
| 123 | + GO_VER=${{ env.GO_VER }} |
| 124 | + GO_TAGS= |
| 125 | + outputs: type=image,"name=docker.io/${{ github.repository_owner }}/fabric-${{ matrix.component.name }}",push-by-digest=true,name-canonical=true,push=true |
| 126 | + |
| 127 | + - name: Export digest |
| 128 | + run: | |
| 129 | + mkdir -p ${{ runner.temp }}/digests/docker.io/${{ matrix.component.name }} |
| 130 | + digest="${{ steps.build-and-push.outputs.digest }}" |
| 131 | + touch "${{ runner.temp }}/digests/docker.io/${{ matrix.component.name }}/${digest#sha256:}" |
| 132 | +
|
| 133 | + - name: Upload digest |
| 134 | + uses: actions/upload-artifact@v4 |
| 135 | + with: |
| 136 | + name: digests-docker.io-${{ matrix.component.name }}-${{ matrix.runner }} |
| 137 | + path: ${{ runner.temp }}/digests/docker.io/${{ matrix.component.name }}/* |
| 138 | + if-no-files-found: error |
| 139 | + retention-days: 1 |
| 140 | + |
| 141 | + # This job merges the architecture-specific digests for the images created above |
| 142 | + # and creates a multi-architecture image manifest with user-friendly tags |
| 143 | + merge-and-push-multi-arch-image: |
| 144 | + name: Merge and Push multi-arch image |
| 145 | + runs-on: ubuntu-22.04 |
| 146 | + needs: |
| 147 | + - build-and-push-native-docker-images |
| 148 | + |
| 149 | + permissions: |
| 150 | + contents: read |
| 151 | + packages: write |
| 152 | + |
| 153 | + strategy: |
| 154 | + fail-fast: false |
| 155 | + matrix: |
| 156 | + component: |
| 157 | + - name: baseos |
| 158 | + context: images/baseos |
| 159 | + - name: ccenv |
| 160 | + context: images/ccenv |
| 161 | + - name: peer |
| 162 | + context: . |
| 163 | + - name: orderer |
| 164 | + context: . |
| 165 | + - name: tools |
| 166 | + context: . |
| 167 | + |
| 168 | + steps: |
| 169 | + - name: Download digests |
| 170 | + uses: actions/download-artifact@v4 |
| 171 | + with: |
| 172 | + path: ${{ runner.temp }}/digests/docker.io/${{ matrix.component.name }} |
| 173 | + pattern: digests-docker.io-${{ matrix.component.name }}-* |
| 174 | + merge-multiple: true |
| 175 | + |
| 176 | + - name: Login to the docker.io Container Registry |
| 177 | + uses: docker/login-action@v3 |
| 178 | + with: |
| 179 | + registry: docker.io |
| 180 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 181 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 182 | + |
| 183 | + - name: Set up Docker Buildx |
| 184 | + uses: docker/setup-buildx-action@v3 |
| 185 | + |
| 186 | + - name: Docker meta |
| 187 | + id: meta |
| 188 | + uses: docker/metadata-action@v5 |
| 189 | + with: |
| 190 | + images: docker.io/${{ github.repository_owner }}/fabric-${{ matrix.component.name }} |
| 191 | + tags: | |
| 192 | + type=semver,pattern={{version}} |
| 193 | + type=semver,pattern={{major}}.{{minor}} |
| 194 | + type=semver,pattern={{major}}.{{minor}}.{{patch}} |
| 195 | +
|
| 196 | + - name: Create manifest list and push # combines the downloaded amd64 and arm64 digests and pushes multi-architecture manifest with the tags specified above |
| 197 | + working-directory: ${{ runner.temp }}/digests/docker.io/${{ matrix.component.name }} |
| 198 | + run: | |
| 199 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 200 | + $(printf 'docker.io/${{ github.repository_owner }}/fabric-${{ matrix.component.name }}@sha256:%s ' *) |
| 201 | +
|
| 202 | + - name: Inspect image |
| 203 | + run: | |
| 204 | + docker buildx imagetools inspect docker.io/${{ github.repository_owner }}/fabric-${{ matrix.component.name }}:${{ steps.meta.outputs.version }} |
| 205 | +
|
| 206 | + create-release: |
| 207 | + name: Create GitHub Release |
| 208 | + needs: |
| 209 | + - build-binaries |
| 210 | + - merge-and-push-multi-arch-image |
| 211 | + runs-on: ubuntu-22.04 |
| 212 | + permissions: |
| 213 | + contents: write |
| 214 | + steps: |
| 215 | + - name: Checkout Fabric Code |
| 216 | + uses: actions/checkout@v4 |
| 217 | + |
| 218 | + - name: Download Artifacts |
| 219 | + id: download |
| 220 | + uses: actions/download-artifact@v4 |
| 221 | + with: |
| 222 | + pattern: "release-*" |
| 223 | + |
| 224 | + - name: Release Fabric Version |
| 225 | + uses: ncipollo/release-action@v1 |
| 226 | + with: |
| 227 | + allowUpdates: "true" |
| 228 | + artifacts: "release-*-*/*.tar.gz" |
| 229 | + bodyFile: release_notes/${{ env.FABRIC_VER }}.md |
| 230 | + tag: ${{ env.FABRIC_VER }} |
| 231 | + token: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments