From db7156c89bee69c526433ada99927f1c9f3bcfdc Mon Sep 17 00:00:00 2001 From: Filipe Azevedo Date: Mon, 12 Oct 2026 12:16:28 +0100 Subject: [PATCH 1/6] ci: Publish binaries and Docker images on release Releases attach x86_64 and aarch64 Linux binaries (publish.yml) and push the graph-node and graph-node-debug images (docker.yml), which also build nightly from master. Images go to ghcr.io/graphprotocol and, when DOCKERHUB_USERNAME and DOCKERHUB_TOKEN are set, to Docker Hub with the same tags. This replaces the Google Cloud Build setup (docker/cloudbuild.yaml, docker/tag.sh). --- .github/workflows/docker.yml | 130 +++++++++++++++++++++++++ .github/workflows/publish.yml | 178 ++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 30 +++++- docker/build.sh | 2 +- docker/cloudbuild.yaml | 53 ---------- docker/tag.sh | 31 ------ 6 files changed, 336 insertions(+), 88 deletions(-) create mode 100644 .github/workflows/docker.yml create mode 100644 .github/workflows/publish.yml delete mode 100644 docker/cloudbuild.yaml delete mode 100644 docker/tag.sh diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000000..1d9c701c737 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,130 @@ +name: Docker images + +on: + push: + branches: [master] + workflow_dispatch: + workflow_call: + inputs: + tag_name: + type: string + default: "" + secrets: + DOCKERHUB_USERNAME: + required: false + DOCKERHUB_TOKEN: + required: false + +permissions: + contents: read + +jobs: + docker: + name: Build and push images + # The Dockerfile compiles graph-node in release mode, which needs the + # cores and disk of a large runner. + runs-on: nscloud-ubuntu-22.04-amd64-16x32 + timeout-minutes: 60 + permissions: + contents: read + packages: write + steps: + - name: Checkout code + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 + with: + ref: ${{ inputs.tag_name }} + + # A release is told apart by tag_name, not the event: called from + # release.yml, the event is the caller's push to master. Same tags as the + # Cloud Build setup: the short SHA always, plus the release tag and + # `latest` for a release, or `nightly` for a master build. Docker Hub + # gets the same tags, and is skipped when its secrets are absent (forks). + - name: Compute build args and tags + id: meta + env: + TAG_NAME: ${{ inputs.tag_name }} + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + run: | + set -euo pipefail + registries=(ghcr.io/graphprotocol) + if [ -n "$DOCKERHUB_USERNAME" ] && [ -n "$DOCKERHUB_TOKEN" ]; then + registries+=(docker.io/graphprotocol) + echo "dockerhub=true" >> "$GITHUB_OUTPUT" + else + echo "::notice title=Docker Hub::Docker Hub push skipped, DOCKERHUB_USERNAME/DOCKERHUB_TOKEN not set" + echo "dockerhub=false" >> "$GITHUB_OUTPUT" + fi + tags=("$(git rev-parse --short=7 HEAD)") + branch="" + if [ -n "$TAG_NAME" ]; then + tags+=("$TAG_NAME" latest) + else + branch="$GITHUB_REF_NAME" + [ "$GITHUB_REF" = refs/heads/master ] && tags+=(nightly) + fi + { + echo "sha=$(git rev-parse HEAD)" + echo "branch=$branch" + for image in graph-node graph-node-debug; do + echo "${image}<> "$GITHUB_OUTPUT" + + - name: Log in to ghcr.io + uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Log in to Docker Hub + if: steps.meta.outputs.dockerhub == 'true' + uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + # Both images are built by one builder, so the graph-node-debug build + # reuses the graph-node-build stage from its cache. + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4 + + # context is set because the action's default is a git context of + # github.sha, which is not the checked-out release tag. linux/amd64 only, + # as Cloud Build built. + - name: Build and push graph-node + uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7 + with: + context: . + file: docker/Dockerfile + target: graph-node + platforms: linux/amd64 + push: true + tags: ${{ steps.meta.outputs.graph-node }} + labels: org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} + build-args: | + COMMIT_SHA=${{ steps.meta.outputs.sha }} + REPO_NAME=${{ github.event.repository.name }} + BRANCH_NAME=${{ steps.meta.outputs.branch }} + TAG_NAME=${{ inputs.tag_name }} + + - name: Build and push graph-node-debug + uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7 + with: + context: . + file: docker/Dockerfile + target: graph-node-debug + platforms: linux/amd64 + push: true + tags: ${{ steps.meta.outputs.graph-node-debug }} + labels: org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} + build-args: | + COMMIT_SHA=${{ steps.meta.outputs.sha }} + REPO_NAME=${{ github.event.repository.name }} + BRANCH_NAME=${{ steps.meta.outputs.branch }} + TAG_NAME=${{ inputs.tag_name }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000000..5a87e6a91b0 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,178 @@ +name: Publish + +on: + workflow_call: + inputs: + tag_name: + required: true + type: string + dry_run: + type: boolean + default: false + workflow_dispatch: + inputs: + tag_name: + description: "Tag to publish (e.g. v0.46.0); with dry_run, any ref" + required: true + type: string + dry_run: + description: "Build and upload workflow artifacts only; leave the release untouched" + type: boolean + default: false + +env: + CARGO_TERM_COLOR: always + +permissions: + contents: read + +jobs: + build: + name: Build ${{ matrix.asset_suffix }} + runs-on: nscloud-ubuntu-22.04-amd64-16x32 + timeout-minutes: 60 + strategy: + fail-fast: true + matrix: + # run_check marks the entries whose target is the runner's own architecture. + include: + - target: x86_64-unknown-linux-gnu + asset_suffix: linux-x86_64 + run_check: true + file_type: "^ELF 64-bit LSB .*x86-64" + - target: aarch64-unknown-linux-gnu + asset_suffix: linux-aarch64 + run_check: false + file_type: "^ELF 64-bit LSB .*ARM aarch64" + steps: + - name: Checkout code + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 + with: + ref: ${{ inputs.tag_name }} + + # rustflags is cleared because the action otherwise sets RUSTFLAGS to + # "-D warnings", which would let a new warning fail a release build. + - name: Setup rust toolchain + uses: actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48 # v1 + with: + target: ${{ matrix.target }} + cache: false + rustflags: "" + + # perl and make build the vendored OpenSSL; libprotobuf-dev carries the + # well-known protos the firehose build script imports. + - name: Install system packages + run: | + set -euo pipefail + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + file make perl pkg-config protobuf-compiler libprotobuf-dev + if [ "${{ matrix.target }}" = aarch64-unknown-linux-gnu ]; then + sudo apt-get install -y --no-install-recommends gcc-aarch64-linux-gnu libc6-dev-arm64-cross + echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> "$GITHUB_ENV" + fi + + # gnd is built alongside only for its pq-sys `bundled` feature, which + # links libpq statically into graph-node too, so the binary needs no + # libpq on the host. gnd itself is released by gnd-binary-build.yml. + - name: Build + run: cargo build --release --locked --target ${{ matrix.target }} --bin graph-node --bin gnd + + # A cross-built binary cannot run here, so its architecture is asserted instead. + - name: Stage binary + env: + FILE_TYPE: ${{ matrix.file_type }} + RUN_CHECK: ${{ matrix.run_check }} + run: | + set -euo pipefail + mkdir -p release + binary="release/graph-node-${{ matrix.asset_suffix }}" + cp "target/${{ matrix.target }}/release/graph-node" "$binary" + chmod +x "$binary" + kind=$(file -b "$binary") + echo "$kind" + grep -qE "$FILE_TYPE" <<<"$kind" || { echo "unexpected binary type: $kind" >&2; exit 1; } + if [ "$RUN_CHECK" = true ]; then + "$binary" --help > /dev/null + fi + gzip "$binary" + + - name: Upload artifact + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 + with: + name: binaries-${{ matrix.asset_suffix }} + path: release/*.gz + if-no-files-found: error + + publish: + name: Publish + needs: build + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + contents: write + concurrency: + group: publish + steps: + - name: Resolve tag + id: v + env: + TAG: ${{ inputs.tag_name }} + DRY_RUN: ${{ inputs.dry_run || false }} + run: | + set -euo pipefail + if [ "$DRY_RUN" != true ]; then + [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "tag_name must be vX.Y.Z, got: $TAG" >&2; exit 1; } + fi + echo "tag=$TAG" >> "$GITHUB_OUTPUT" + + - name: Download binaries + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8 + with: + path: dist + pattern: binaries-* + merge-multiple: true + + # graph-node for both Linux targets. + - name: Checksum binaries + working-directory: dist + run: | + set -euo pipefail + shopt -s nullglob + archives=(*.gz) + [ "${#archives[@]}" -eq 2 ] || { echo "expected 2 archives, found ${#archives[@]}" >&2; exit 1; } + sha256sum -- "${archives[@]}" > SHA256SUMS + cat SHA256SUMS + + - name: Upload release bundle + if: inputs.dry_run + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 + with: + name: release-bundle + path: dist/* + + - name: Attach to release + if: ${{ !inputs.dry_run }} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + set -euo pipefail + gh release upload "${{ steps.v.outputs.tag }}" --repo "$GITHUB_REPOSITORY" --clobber \ + dist/*.gz dist/SHA256SUMS + + - name: Summary + env: + DRY_RUN: ${{ inputs.dry_run || false }} + run: | + set -euo pipefail + { + if [ "$DRY_RUN" = true ]; then + echo "### Dry run for ${{ steps.v.outputs.tag }}: release left untouched" + else + echo "### graph-node ${{ steps.v.outputs.tag }}" + echo "https://github.com/${GITHUB_REPOSITORY}/releases/tag/${{ steps.v.outputs.tag }}" + fi + echo '```' + cat dist/SHA256SUMS + echo '```' + } >> "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7528cfb99e6..fe9adaeaeab 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,14 +8,16 @@ on: permissions: contents: read -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - jobs: release-please: name: Release Please runs-on: ubuntu-latest timeout-minutes: 5 + concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + outputs: + release_created: ${{ steps.release.outputs.release_created }} + tag_name: ${{ steps.release.outputs.tag_name }} steps: # A pull request opened with GITHUB_TOKEN does not trigger workflows, so # the release PR is opened as the app instead. @@ -47,3 +49,25 @@ jobs: else echo "Nothing to release" >> "$GITHUB_STEP_SUMMARY" fi + + publish: + name: Publish binaries + needs: release-please + if: needs.release-please.outputs.release_created == 'true' + permissions: + contents: write + uses: ./.github/workflows/publish.yml + with: + tag_name: ${{ needs.release-please.outputs.tag_name }} + + docker: + name: Docker images + needs: release-please + if: needs.release-please.outputs.release_created == 'true' + permissions: + contents: read + packages: write + uses: ./.github/workflows/docker.yml + secrets: inherit + with: + tag_name: ${{ needs.release-please.outputs.tag_name }} diff --git a/docker/build.sh b/docker/build.sh index 5dd67ea99d5..8ccf5f63770 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -1,7 +1,7 @@ #! /bin/bash # This file is only here to ease testing/development. Official images are -# built using the 'cloudbuild.yaml' file +# built by the .github/workflows/docker.yml workflow type -p podman > /dev/null && docker=podman || docker=docker diff --git a/docker/cloudbuild.yaml b/docker/cloudbuild.yaml deleted file mode 100644 index 0bf800cddad..00000000000 --- a/docker/cloudbuild.yaml +++ /dev/null @@ -1,53 +0,0 @@ -options: - machineType: "E2_HIGHCPU_32" -timeout: 1800s -steps: -- name: 'gcr.io/cloud-builders/docker' - args: ['build', '--target', 'graph-node-build', - '--build-arg', 'COMMIT_SHA=$COMMIT_SHA', - '--build-arg', 'REPO_NAME=$REPO_NAME', - '--build-arg', 'BRANCH_NAME=$BRANCH_NAME', - '--build-arg', 'TAG_NAME=$TAG_NAME', - '-t', 'gcr.io/$PROJECT_ID/graph-node-build:$SHORT_SHA', - '-f', 'docker/Dockerfile', '.'] -- name: 'gcr.io/cloud-builders/docker' - args: ['build', '--target', 'graph-node', - '--build-arg', 'COMMIT_SHA=$COMMIT_SHA', - '--build-arg', 'REPO_NAME=$REPO_NAME', - '--build-arg', 'BRANCH_NAME=$BRANCH_NAME', - '--build-arg', 'TAG_NAME=$TAG_NAME', - '-t', 'gcr.io/$PROJECT_ID/graph-node:$SHORT_SHA', - '-f', 'docker/Dockerfile', '.'] -- name: 'gcr.io/cloud-builders/docker' - args: ['build', '--target', 'graph-node-debug', - '--build-arg', 'COMMIT_SHA=$COMMIT_SHA', - '--build-arg', 'REPO_NAME=$REPO_NAME', - '--build-arg', 'BRANCH_NAME=$BRANCH_NAME', - '--build-arg', 'TAG_NAME=$TAG_NAME', - '-t', 'gcr.io/$PROJECT_ID/graph-node-debug:$SHORT_SHA', - '-f', 'docker/Dockerfile', '.'] -- name: 'gcr.io/cloud-builders/docker' - args: ['tag', - 'gcr.io/$PROJECT_ID/graph-node:$SHORT_SHA', - 'lutter/graph-node:$SHORT_SHA'] -- name: 'gcr.io/cloud-builders/docker' - entrypoint: 'bash' - args: ['docker/tag.sh'] - secretEnv: ['PASSWORD'] - env: - - 'SHORT_SHA=$SHORT_SHA' - - 'TAG_NAME=$TAG_NAME' - - 'PROJECT_ID=$PROJECT_ID' - - 'DOCKER_HUB_USER=$_DOCKER_HUB_USER' - - 'BRANCH_NAME=$BRANCH_NAME' -images: - - 'gcr.io/$PROJECT_ID/graph-node-build:$SHORT_SHA' - - 'gcr.io/$PROJECT_ID/graph-node:$SHORT_SHA' - - 'gcr.io/$PROJECT_ID/graph-node-debug:$SHORT_SHA' -substitutions: - # The owner of the access token whose encrypted value is in PASSWORD - _DOCKER_HUB_USER: "lutter" -secrets: - - kmsKeyName: projects/the-graph-staging/locations/global/keyRings/docker/cryptoKeys/docker-hub-push - secretEnv: - PASSWORD: 'CiQAdfFldbmUiHgGP1lPq6bAOfd+VQ/dFwyohB1IQwiwQg03ZE8STQDvWKpv6eJHVUN1YoFC5FcooJrH+Stvx9oMD7jBjgxEH5ngIiAysWP3E4Pgxt/73xnaanbM1EQ94eVFKCiY0GaEKFNu0BJx22vCYmU4' diff --git a/docker/tag.sh b/docker/tag.sh deleted file mode 100644 index 1abafa95afa..00000000000 --- a/docker/tag.sh +++ /dev/null @@ -1,31 +0,0 @@ -#! /bin/bash - -# This script is used by cloud build to push Docker images into Docker hub - -tag_and_push() { - tag=$1 - docker tag gcr.io/$PROJECT_ID/graph-node:$SHORT_SHA \ - graphprotocol/graph-node:$tag - docker push graphprotocol/graph-node:$tag - - docker tag gcr.io/$PROJECT_ID/graph-node-debug:$SHORT_SHA \ - graphprotocol/graph-node-debug:$tag - docker push graphprotocol/graph-node-debug:$tag -} - -echo "Logging into Docker Hub" -echo $PASSWORD | docker login --username="$DOCKER_HUB_USER" --password-stdin - -set -ex - -tag_and_push "$SHORT_SHA" - -# Builds of tags set the tag in Docker Hub, too -[ -n "$TAG_NAME" ] && tag_and_push "$TAG_NAME" -# Builds for tags vN.N.N become the 'latest' -[[ "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] && tag_and_push latest - -# If the build is from the master branch, tag it as 'nightly' -[ "$BRANCH_NAME" = "master" ] && tag_and_push nightly - -exit 0 From 941c88cdc1b90f84c2d7626bd6cd0e1de2dc9d5e Mon Sep 17 00:00:00 2001 From: Filipe Azevedo Date: Mon, 12 Oct 2026 12:53:51 +0100 Subject: [PATCH 2/6] ci: Tag images with metadata-action and skip Docker Hub login without a token --- .github/workflows/docker.yml | 91 ++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 52 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1d9c701c737..352def54080 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -28,52 +28,43 @@ jobs: permissions: contents: read packages: write + # Docker Hub is pushed to only when its token is set; `if:` can't read + # secrets directly. + env: + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} steps: - name: Checkout code uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 with: ref: ${{ inputs.tag_name }} - # A release is told apart by tag_name, not the event: called from - # release.yml, the event is the caller's push to master. Same tags as the - # Cloud Build setup: the short SHA always, plus the release tag and - # `latest` for a release, or `nightly` for a master build. Docker Hub - # gets the same tags, and is skipped when its secrets are absent (forks). - - name: Compute build args and tags + # The same tags as the Cloud Build setup: the short SHA always, plus + # `nightly` for master, or the release tag and `latest` for a release. A + # release is told apart by tag_name, not the event: called from + # release.yml, the event is the caller's push to master. + - name: Image metadata (graph-node) id: meta - env: - TAG_NAME: ${{ inputs.tag_name }} - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} - run: | - set -euo pipefail - registries=(ghcr.io/graphprotocol) - if [ -n "$DOCKERHUB_USERNAME" ] && [ -n "$DOCKERHUB_TOKEN" ]; then - registries+=(docker.io/graphprotocol) - echo "dockerhub=true" >> "$GITHUB_OUTPUT" - else - echo "::notice title=Docker Hub::Docker Hub push skipped, DOCKERHUB_USERNAME/DOCKERHUB_TOKEN not set" - echo "dockerhub=false" >> "$GITHUB_OUTPUT" - fi - tags=("$(git rev-parse --short=7 HEAD)") - branch="" - if [ -n "$TAG_NAME" ]; then - tags+=("$TAG_NAME" latest) - else - branch="$GITHUB_REF_NAME" - [ "$GITHUB_REF" = refs/heads/master ] && tags+=(nightly) - fi - { - echo "sha=$(git rev-parse HEAD)" - echo "branch=$branch" - for image in graph-node graph-node-debug; do - echo "${image}<> "$GITHUB_OUTPUT" + uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6 + with: + images: | + ghcr.io/graphprotocol/graph-node + name=docker.io/graphprotocol/graph-node,enable=${{ env.DOCKERHUB_TOKEN != '' }} + flavor: latest=false + tags: &tags | + type=sha,prefix= + type=raw,value=nightly,enable=${{ inputs.tag_name == '' && github.ref == 'refs/heads/master' }} + type=raw,value=${{ inputs.tag_name }},enable=${{ inputs.tag_name != '' }} + type=raw,value=latest,enable=${{ inputs.tag_name != '' }} + + - name: Image metadata (graph-node-debug) + id: meta-debug + uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6 + with: + images: | + ghcr.io/graphprotocol/graph-node-debug + name=docker.io/graphprotocol/graph-node-debug,enable=${{ env.DOCKERHUB_TOKEN != '' }} + flavor: latest=false + tags: *tags - name: Log in to ghcr.io uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4 @@ -83,7 +74,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Log in to Docker Hub - if: steps.meta.outputs.dockerhub == 'true' + if: env.DOCKERHUB_TOKEN != '' uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4 with: username: ${{ secrets.DOCKERHUB_USERNAME }} @@ -105,12 +96,12 @@ jobs: target: graph-node platforms: linux/amd64 push: true - tags: ${{ steps.meta.outputs.graph-node }} - labels: org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} - build-args: | - COMMIT_SHA=${{ steps.meta.outputs.sha }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: &build-args | + COMMIT_SHA=${{ github.sha }} REPO_NAME=${{ github.event.repository.name }} - BRANCH_NAME=${{ steps.meta.outputs.branch }} + BRANCH_NAME=${{ inputs.tag_name == '' && github.ref_name || '' }} TAG_NAME=${{ inputs.tag_name }} - name: Build and push graph-node-debug @@ -121,10 +112,6 @@ jobs: target: graph-node-debug platforms: linux/amd64 push: true - tags: ${{ steps.meta.outputs.graph-node-debug }} - labels: org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} - build-args: | - COMMIT_SHA=${{ steps.meta.outputs.sha }} - REPO_NAME=${{ github.event.repository.name }} - BRANCH_NAME=${{ steps.meta.outputs.branch }} - TAG_NAME=${{ inputs.tag_name }} + tags: ${{ steps.meta-debug.outputs.tags }} + labels: ${{ steps.meta-debug.outputs.labels }} + build-args: *build-args From eb4728a5fc9eec4d5f0700a3aed641dbac0e00ec Mon Sep 17 00:00:00 2001 From: Carlos Jorge Date: Wed, 18 Nov 2026 00:13:48 +0000 Subject: [PATCH 3/6] ci(docker): Push to Docker Hub always, and build canary and hotfix images Docker Hub is where users and deployments pull graph-node from, so a build that can't push there now fails instead of publishing to ghcr.io alone: it logs in with the organisation's access token (org secret DOCKERHUB_CI_TOKEN, user graphprotocol). Cover what the Cloud Build triggers built: `canary-*` tags get an image tagged with the tag's name, and hotfix/** branches the short SHA. Also: one build per ref at a time, a release in its own group so a nightly can't replace it; build provenance for both images; YAML anchors written out. CONTRIBUTING describes the tags and how to get a canary. --- .github/workflows/docker.yml | 127 +++++++++++++++++++++++++++-------- CONTRIBUTING.md | 16 +++++ 2 files changed, 116 insertions(+), 27 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 352def54080..8fcafcb30fe 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,23 +1,42 @@ name: Docker images +# Images go to Docker Hub (graphprotocol/graph-node, graphprotocol/graph-node-debug), +# where users and deployments pull them, and to ghcr.io under the same names. +# +# | Build | Tags | +# |-------------------------------------------|----------------------------| +# | every build | 7-char short SHA | +# | push to master | `nightly` | +# | push to hotfix/** | (short SHA only) | +# | push of a `canary-*` tag | the tag, e.g. `canary-fix` | +# | release (called from release.yml) | `vX.Y.Z`, `latest` | +# | run by hand (workflow_dispatch) | (short SHA only) | +# +# Canary images replace the Cloud Build tag trigger: to get an image of a +# commit that isn't on master, push a tag `canary-` pointing at it. on: push: - branches: [master] + branches: [master, "hotfix/**"] + tags: ["canary-*"] workflow_dispatch: workflow_call: inputs: tag_name: type: string default: "" + # release.yml passes it with `secrets: inherit`; the first step checks it. secrets: - DOCKERHUB_USERNAME: - required: false - DOCKERHUB_TOKEN: + DOCKERHUB_CI_TOKEN: required: false permissions: contents: read +env: + # The organisation's Docker Hub token (org secret DOCKERHUB_CI_TOKEN) is an + # organization access token, which logs in as the organisation. + DOCKERHUB_USERNAME: graphprotocol + jobs: docker: name: Build and push images @@ -28,31 +47,46 @@ jobs: permissions: contents: read packages: write - # Docker Hub is pushed to only when its token is set; `if:` can't read - # secrets directly. - env: - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + id-token: write + attestations: write + # One build per ref at a time, in order; a newer push replaces a waiting + # one. A release (tag_name set) has its own group, so a nightly can't + # replace it. + concurrency: + group: docker-${{ inputs.tag_name || github.ref }} + cancel-in-progress: false steps: + # Docker Hub is where images are pulled from, so a build that can't push + # there fails instead of quietly publishing to ghcr.io alone. + - name: Check Docker Hub credentials + env: + DOCKERHUB_CI_TOKEN: ${{ secrets.DOCKERHUB_CI_TOKEN }} + run: | + if [ -z "$DOCKERHUB_CI_TOKEN" ]; then + echo "::error::DOCKERHUB_CI_TOKEN is not available to this workflow" >&2 + exit 1 + fi + - name: Checkout code uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 with: ref: ${{ inputs.tag_name }} - # The same tags as the Cloud Build setup: the short SHA always, plus - # `nightly` for master, or the release tag and `latest` for a release. A - # release is told apart by tag_name, not the event: called from + # A release is told apart by tag_name, not the event: called from # release.yml, the event is the caller's push to master. - name: Image metadata (graph-node) id: meta uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6 with: images: | + docker.io/graphprotocol/graph-node ghcr.io/graphprotocol/graph-node - name=docker.io/graphprotocol/graph-node,enable=${{ env.DOCKERHUB_TOKEN != '' }} flavor: latest=false - tags: &tags | + # Keep the tags of the two images the same. + tags: | type=sha,prefix= type=raw,value=nightly,enable=${{ inputs.tag_name == '' && github.ref == 'refs/heads/master' }} + type=raw,value=${{ github.ref_name }},enable=${{ inputs.tag_name == '' && startsWith(github.ref, 'refs/tags/canary-') }} type=raw,value=${{ inputs.tag_name }},enable=${{ inputs.tag_name != '' }} type=raw,value=latest,enable=${{ inputs.tag_name != '' }} @@ -61,10 +95,21 @@ jobs: uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6 with: images: | + docker.io/graphprotocol/graph-node-debug ghcr.io/graphprotocol/graph-node-debug - name=docker.io/graphprotocol/graph-node-debug,enable=${{ env.DOCKERHUB_TOKEN != '' }} flavor: latest=false - tags: *tags + tags: | + type=sha,prefix= + type=raw,value=nightly,enable=${{ inputs.tag_name == '' && github.ref == 'refs/heads/master' }} + type=raw,value=${{ github.ref_name }},enable=${{ inputs.tag_name == '' && startsWith(github.ref, 'refs/tags/canary-') }} + type=raw,value=${{ inputs.tag_name }},enable=${{ inputs.tag_name != '' }} + type=raw,value=latest,enable=${{ inputs.tag_name != '' }} + + - name: Log in to Docker Hub + uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4 + with: + username: ${{ env.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_CI_TOKEN }} - name: Log in to ghcr.io uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4 @@ -73,13 +118,6 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Log in to Docker Hub - if: env.DOCKERHUB_TOKEN != '' - uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - # Both images are built by one builder, so the graph-node-debug build # reuses the graph-node-build stage from its cache. - name: Set up Docker Buildx @@ -87,8 +125,9 @@ jobs: # context is set because the action's default is a git context of # github.sha, which is not the checked-out release tag. linux/amd64 only, - # as Cloud Build built. + # as Cloud Build built. The build args only fill /etc/image-info. - name: Build and push graph-node + id: build uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7 with: context: . @@ -98,13 +137,14 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - build-args: &build-args | + build-args: | COMMIT_SHA=${{ github.sha }} REPO_NAME=${{ github.event.repository.name }} - BRANCH_NAME=${{ inputs.tag_name == '' && github.ref_name || '' }} - TAG_NAME=${{ inputs.tag_name }} + BRANCH_NAME=${{ inputs.tag_name == '' && github.ref_type == 'branch' && github.ref_name || '' }} + TAG_NAME=${{ inputs.tag_name || (github.ref_type == 'tag' && github.ref_name) || '' }} - name: Build and push graph-node-debug + id: build-debug uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7 with: context: . @@ -114,4 +154,37 @@ jobs: push: true tags: ${{ steps.meta-debug.outputs.tags }} labels: ${{ steps.meta-debug.outputs.labels }} - build-args: *build-args + build-args: | + COMMIT_SHA=${{ github.sha }} + REPO_NAME=${{ github.event.repository.name }} + BRANCH_NAME=${{ inputs.tag_name == '' && github.ref_type == 'branch' && github.ref_name || '' }} + TAG_NAME=${{ inputs.tag_name || (github.ref_type == 'tag' && github.ref_name) || '' }} + + # Build provenance, stored with GitHub and pushed next to the ghcr.io + # image. Both registries hold the same digest, so it verifies either: + # gh attestation verify oci://docker.io/graphprotocol/graph-node: -R graphprotocol/graph-node + - name: Attest graph-node + uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2 + with: + subject-name: ghcr.io/graphprotocol/graph-node + subject-digest: ${{ steps.build.outputs.digest }} + push-to-registry: true + + - name: Attest graph-node-debug + uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2 + with: + subject-name: ghcr.io/graphprotocol/graph-node-debug + subject-digest: ${{ steps.build-debug.outputs.digest }} + push-to-registry: true + + - name: Summary + env: + TAGS: ${{ steps.meta.outputs.tags }} + DIGEST: ${{ steps.build.outputs.digest }} + run: | + { + echo "### graph-node images (${DIGEST})" + echo '```' + echo "$TAGS" + echo '```' + } >> "$GITHUB_STEP_SUMMARY" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 84e7062df1b..f81b62467ac 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -104,3 +104,19 @@ the changes since the last release to `CHANGELOG.md`. To release: To release a version other than the one release-please proposes, put `Release-As: X.Y.Z` in the body of a commit on master (for example in the squash-merge description of a pull request). + +## Docker images + +`.github/workflows/docker.yml` publishes `graphprotocol/graph-node` and +`graphprotocol/graph-node-debug` to Docker Hub and to `ghcr.io`, with build +provenance: + +- every push to master: the short commit SHA (7 characters) and `nightly`; +- every push to a `hotfix/**` branch: the short SHA; +- a release: `vX.Y.Z` and `latest`. + +To get an image of a commit that isn't on master (a canary), push a tag +named `canary-` pointing at it, for example +`t=canary-$(git rev-parse --short HEAD); git tag "$t" && git push origin "$t"`. +The image is tagged with the tag's name and the short SHA; the tag can be +deleted once the image is published. From 32fe066571019f4a6dc52afc80b4892918a93870 Mon Sep 17 00:00:00 2001 From: Carlos Jorge Date: Wed, 18 Nov 2026 00:13:51 +0000 Subject: [PATCH 4/6] ci(publish): Check how release binaries link, and attest them Fail when graph-node needs libpq on the host: it is linked statically only because gnd's pq-sys `bundled` feature is unified into the build. Run the cross-built aarch64 binary under qemu-user instead of only checking its architecture. Attest the release archives' build provenance; release.yml grants id-token and attestations to the called workflows. --- .github/workflows/publish.yml | 27 ++++++++++++++++++++++++--- .github/workflows/release.yml | 6 ++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 5a87e6a91b0..4eb4806e618 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -66,9 +66,9 @@ jobs: set -euo pipefail sudo apt-get update sudo apt-get install -y --no-install-recommends \ - file make perl pkg-config protobuf-compiler libprotobuf-dev + binutils file make perl pkg-config protobuf-compiler libprotobuf-dev if [ "${{ matrix.target }}" = aarch64-unknown-linux-gnu ]; then - sudo apt-get install -y --no-install-recommends gcc-aarch64-linux-gnu libc6-dev-arm64-cross + sudo apt-get install -y --no-install-recommends gcc-aarch64-linux-gnu libc6-dev-arm64-cross qemu-user echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> "$GITHUB_ENV" fi @@ -78,7 +78,10 @@ jobs: - name: Build run: cargo build --release --locked --target ${{ matrix.target }} --bin graph-node --bin gnd - # A cross-built binary cannot run here, so its architecture is asserted instead. + # The architecture is asserted, and the binary must not need libpq on the + # host: it is linked statically only because gnd's pq-sys `bundled` + # feature is unified into this build. A cross-built binary runs under + # qemu-user against the cross libc. - name: Stage binary env: FILE_TYPE: ${{ matrix.file_type }} @@ -92,8 +95,16 @@ jobs: kind=$(file -b "$binary") echo "$kind" grep -qE "$FILE_TYPE" <<<"$kind" || { echo "unexpected binary type: $kind" >&2; exit 1; } + needed=$(readelf -d "$binary" | awk '/NEEDED/ {print $NF}') + echo "$needed" + if grep -q libpq <<<"$needed"; then + echo "graph-node links libpq dynamically; expected it statically linked" >&2 + exit 1 + fi if [ "$RUN_CHECK" = true ]; then "$binary" --help > /dev/null + else + qemu-aarch64 -L /usr/aarch64-linux-gnu "$binary" --help > /dev/null fi gzip "$binary" @@ -111,6 +122,8 @@ jobs: timeout-minutes: 10 permissions: contents: write + id-token: write + attestations: write concurrency: group: publish steps: @@ -151,6 +164,14 @@ jobs: name: release-bundle path: dist/* + # Build provenance for the release's archives, stored with GitHub: + # gh attestation verify graph-node-linux-x86_64.gz -R graphprotocol/graph-node + - name: Attest binaries + if: ${{ !inputs.dry_run }} + uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2 + with: + subject-path: dist/*.gz + - name: Attach to release if: ${{ !inputs.dry_run }} env: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4a9c9371615..62c2d6b83e1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -65,8 +65,12 @@ jobs: name: Publish binaries needs: release-please if: needs.release-please.outputs.release_created == 'true' + # A called workflow gets at most its caller's permissions; id-token and + # attestations are for the build provenance. permissions: contents: write + id-token: write + attestations: write uses: ./.github/workflows/publish.yml with: tag_name: ${{ needs.release-please.outputs.tag_name }} @@ -78,6 +82,8 @@ jobs: permissions: contents: read packages: write + id-token: write + attestations: write uses: ./.github/workflows/docker.yml secrets: inherit with: From f32e2b74069f5089d469b851bf215f82f89a5e40 Mon Sep 17 00:00:00 2001 From: Carlos Jorge Date: Wed, 18 Nov 2026 11:00:24 +0000 Subject: [PATCH 5/6] ci(docker): Build a release commit once, as the release release-please's release commit was built twice: by its push to master (nightly) and by the release. The two images differ, and the short-SHA tag went to whichever finished last, so it could name the nightly image instead of vX.Y.Z (seen in a rehearsal). Skip the push build for the release commit; nightly stays on the commit before it. --- .github/workflows/docker.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 8fcafcb30fe..f19d53efd00 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -6,7 +6,7 @@ name: Docker images # | Build | Tags | # |-------------------------------------------|----------------------------| # | every build | 7-char short SHA | -# | push to master | `nightly` | +# | push to master (except a release commit) | `nightly` | # | push to hotfix/** | (short SHA only) | # | push of a `canary-*` tag | the tag, e.g. `canary-fix` | # | release (called from release.yml) | `vX.Y.Z`, `latest` | @@ -40,6 +40,15 @@ env: jobs: docker: name: Build and push images + # release-please's release commit is built once, by the release + # (release.yml calls this workflow with tag_name), so its short-SHA tag is + # the release image; its own push to master builds nothing, and `nightly` + # stays on the commit before it. A called run sees the caller's push + # event, hence the tag_name test. + if: >- + inputs.tag_name != '' || + github.event_name != 'push' || + !startsWith(github.event.head_commit.message, 'chore(master): release ') # The Dockerfile compiles graph-node in release mode, which needs the # cores and disk of a large runner. runs-on: nscloud-ubuntu-22.04-amd64-16x32 From 7a077a97d97347b6c21a16f88192cc7362e17c1e Mon Sep 17 00:00:00 2001 From: Carlos Jorge Date: Thu, 26 Nov 2026 23:00:44 +0000 Subject: [PATCH 6/6] ci(docker): Describe the canary and platform choices as they are --- .github/workflows/docker.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index f19d53efd00..dd4a82afd42 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -12,8 +12,8 @@ name: Docker images # | release (called from release.yml) | `vX.Y.Z`, `latest` | # | run by hand (workflow_dispatch) | (short SHA only) | # -# Canary images replace the Cloud Build tag trigger: to get an image of a -# commit that isn't on master, push a tag `canary-` pointing at it. +# To get an image of a commit that isn't on master (a canary), push a tag +# `canary-` pointing at it. on: push: branches: [master, "hotfix/**"] @@ -133,8 +133,8 @@ jobs: uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4 # context is set because the action's default is a git context of - # github.sha, which is not the checked-out release tag. linux/amd64 only, - # as Cloud Build built. The build args only fill /etc/image-info. + # github.sha, which is not the checked-out release tag. linux/amd64 only. + # The build args only fill /etc/image-info. - name: Build and push graph-node id: build uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7