|
| 1 | +name: Build, push and release (if tag) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "*-v*" |
| 7 | + branches: |
| 8 | + - "firehose-fh3.0" |
| 9 | + - "release/*" |
| 10 | + |
| 11 | +env: |
| 12 | + REGISTRY: ghcr.io |
| 13 | + IMAGE_NAME: ${{ github.repository }} |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + strategy: |
| 18 | + matrix: |
| 19 | + include: |
| 20 | + - platform: linux/amd64 |
| 21 | + platform_suffix: amd64 |
| 22 | + runner: ubuntu-22.04 |
| 23 | + |
| 24 | + - platform: linux/arm64 |
| 25 | + platform_suffix: arm64 |
| 26 | + runner: ubuntu-22.04-arm |
| 27 | + |
| 28 | + runs-on: [ "${{ matrix.runner }}" ] |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Checkout repository |
| 32 | + uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Set up Docker Buildx |
| 35 | + uses: docker/setup-buildx-action@v3 |
| 36 | + |
| 37 | + - name: Log in to the Container registry |
| 38 | + uses: docker/login-action@v3 |
| 39 | + with: |
| 40 | + registry: ${{ env.REGISTRY }} |
| 41 | + username: ${{ github.actor }} |
| 42 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + |
| 44 | + - name: Extract version |
| 45 | + id: extract-version |
| 46 | + run: | |
| 47 | + version="edge" |
| 48 | + if [[ "${GITHUB_REF}" == refs/tags/* ]]; then |
| 49 | + version=${GITHUB_REF#refs/tags/} |
| 50 | + fi |
| 51 | +
|
| 52 | + echo "VERSION=${version}" >> "$GITHUB_OUTPUT" |
| 53 | +
|
| 54 | + - name: Generate docker tags/labels from github build context |
| 55 | + id: meta |
| 56 | + uses: docker/metadata-action@v5 |
| 57 | + with: |
| 58 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 59 | + # The second sha tag is defined to uniquely identify the image and the platform, |
| 60 | + # we append extract version, either edge or <tag>, this is necessary to avoid a |
| 61 | + # race condition when pushing a tag and its related branches. In this case, three |
| 62 | + # build are launched, but only one, the tag, will get it's version set to the tag. |
| 63 | + # |
| 64 | + # What happened is that non-tag Docker built image like `3b14725-amd64` was |
| 65 | + # overwriting the tag Docker image also labeled `3b14725-amd64`. The `push` action |
| 66 | + # was then merging an image that didn't have the version labels correctly set. |
| 67 | + # |
| 68 | + # Our image more looks like `3b14725-edge-amd64` or `3b14725-geth-v1.15.10-fh3.0-amd64` |
| 69 | + # which mean the `push` can now pick the correct image depending on the type of build. |
| 70 | + tags: | |
| 71 | + type=ref,event=tag,prefix= |
| 72 | + type=sha,prefix= |
| 73 | + type=sha,prefix=,suffix=-${{ steps.extract-version.outputs.VERSION }}-${{ matrix.platform_suffix }} |
| 74 | + type=edge,branch=firehose-fh3.0,priority=1 |
| 75 | + type=edge,branch=release/*,priority=1 |
| 76 | + flavor: | |
| 77 | + latest=${{ startsWith(github.ref, 'refs/tags/') && !contains(github.ref, 'beta') && !contains(github.ref, 'rc') }} |
| 78 | + prefix=geth-,onlatest=true |
| 79 | +
|
| 80 | + - name: Build and push Docker image (${{ matrix.platform }}) |
| 81 | + uses: docker/build-push-action@v6 |
| 82 | + with: |
| 83 | + context: . |
| 84 | + file: ./Dockerfile.sf |
| 85 | + platforms: ${{ matrix.platform }} |
| 86 | + push: true |
| 87 | + tags: ${{ steps.meta.outputs.tags }} |
| 88 | + labels: ${{ steps.meta.outputs.labels }} |
| 89 | + provenance: false |
| 90 | + # FIXME: Switch to Firehose Ethereum! |
| 91 | + build-args: | |
| 92 | + FIREHOSE_CORE=18bb86f |
| 93 | +
|
| 94 | + push: |
| 95 | + needs: build |
| 96 | + runs-on: ubuntu-22.04 |
| 97 | + |
| 98 | + permissions: |
| 99 | + contents: read |
| 100 | + packages: write |
| 101 | + |
| 102 | + steps: |
| 103 | + - name: Docker login |
| 104 | + uses: docker/login-action@v3 |
| 105 | + with: |
| 106 | + registry: ${{ env.REGISTRY }} |
| 107 | + username: ${{ github.actor }} |
| 108 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 109 | + |
| 110 | + - name: Generate docker tags/labels from github build context |
| 111 | + id: meta |
| 112 | + uses: docker/metadata-action@v5 |
| 113 | + with: |
| 114 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 115 | + tags: | |
| 116 | + type=ref,event=tag,prefix= |
| 117 | + type=sha,prefix= |
| 118 | + type=edge,branch=firehose-fh3.0,priority=1 |
| 119 | + type=edge,branch=release/*,priority=1 |
| 120 | + flavor: | |
| 121 | + latest=${{ startsWith(github.ref, 'refs/tags/') && !contains(github.ref, 'beta') && !contains(github.ref, 'rc') }} |
| 122 | + prefix=geth-,onlatest=true |
| 123 | + sep-tags: "," |
| 124 | + |
| 125 | + - name: Extract image |
| 126 | + id: image |
| 127 | + run: | |
| 128 | + version="edge" |
| 129 | + if [[ "${GITHUB_REF}" == refs/tags/* ]]; then |
| 130 | + version=${GITHUB_REF#refs/tags/} |
| 131 | + fi |
| 132 | +
|
| 133 | + echo "ID=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${GITHUB_SHA::7}-${version}" >> "$GITHUB_OUTPUT" |
| 134 | +
|
| 135 | + - name: Create and push manifest images |
| 136 | + uses: Noelware/docker-manifest-action@0.4.3 |
| 137 | + with: |
| 138 | + inputs: "${{ steps.meta.outputs.tags }}" |
| 139 | + images: "${{ steps.image.outputs.ID }}-amd64, ${{ steps.image.outputs.ID }}-arm64" |
| 140 | + push: true |
| 141 | + |
| 142 | + release: |
| 143 | + if: startsWith(github.ref, 'refs/tags/') |
| 144 | + needs: build |
| 145 | + runs-on: ubuntu-22.04 |
| 146 | + |
| 147 | + permissions: |
| 148 | + contents: write |
| 149 | + |
| 150 | + steps: |
| 151 | + - name: Extract image |
| 152 | + id: image |
| 153 | + run: | |
| 154 | + version="edge" |
| 155 | + if [[ "${GITHUB_REF}" == refs/tags/* ]]; then |
| 156 | + version=${GITHUB_REF#refs/tags/} |
| 157 | + fi |
| 158 | +
|
| 159 | + echo "ID=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${GITHUB_SHA::7}-${version}" >> "$GITHUB_OUTPUT" |
| 160 | +
|
| 161 | + - name: Extract assets |
| 162 | + if: startsWith(github.ref, 'refs/tags/') |
| 163 | + run: | |
| 164 | + # The --platform are not really needed here, but it removes the warning |
| 165 | + docker cp $(docker create --platform=linux/amd64 ${{ steps.image.outputs.ID }}-amd64):/usr/local/bin/geth ./geth_linux |
| 166 | + docker cp $(docker create --platform=linux/arm64 ${{ steps.image.outputs.ID }}-arm64):/usr/local/bin/geth ./geth_linux_arm64 |
| 167 | +
|
| 168 | + - name: Release |
| 169 | + uses: softprops/action-gh-release@v2 |
| 170 | + with: |
| 171 | + prerelease: ${{ contains(github.ref, 'beta') || contains(github.ref, 'rc') }} |
| 172 | + files: | |
| 173 | + ./geth_linux |
| 174 | + ./geth_linux_arm64 |
0 commit comments