From d4521cc5fde704a42751fa153e11217e6e25437a Mon Sep 17 00:00:00 2001 From: Michael Buntarman Date: Wed, 25 Nov 2026 11:09:15 +0700 Subject: [PATCH] build(release): show operators the TN release their node runs --- .github/workflows/publish-node-image.yaml | 35 +++++++++++++++++++++++ .github/workflows/release.yaml | 33 +++++++++++++++++---- cmd/version/utils.go | 11 +++++++ deployments/Dockerfile | 13 +++++++-- docs/node-operator-guide.md | 4 ++- docs/node-upgrade-guide.md | 17 +++++++++++ 6 files changed, 104 insertions(+), 9 deletions(-) diff --git a/.github/workflows/publish-node-image.yaml b/.github/workflows/publish-node-image.yaml index 5f5e15a6b..52bf84f57 100644 --- a/.github/workflows/publish-node-image.yaml +++ b/.github/workflows/publish-node-image.yaml @@ -50,6 +50,37 @@ jobs: type=ref,event=tag type=semver,pattern={{version}} + - name: Read the commit time + id: commit + run: echo "time=$(git log -1 --format=%cI)" >> "$GITHUB_OUTPUT" + + # Build and load the image first, so a binary that reports the wrong version is never + # pushed. The push step below reuses this build's cache. + - name: Build image for the version check (linux/amd64) + uses: docker/build-push-action@v5 + with: + context: . + file: deployments/Dockerfile + load: true + platforms: linux/amd64 + tags: tn-node:version-check + build-args: | + TN_VERSION=${{ steps.meta.outputs.version }} + TN_COMMIT=${{ github.sha }} + TN_BUILD_TIME=${{ steps.commit.outputs.time }} + cache-from: type=gha + + - name: Check that kwild reports the image version + env: + EXPECTED: ${{ steps.meta.outputs.version }} + run: | + got=$(docker run --rm --entrypoint /app/kwild tn-node:version-check version --output json | jq -r '.result.version') + if [ "$got" != "$EXPECTED" ]; then + echo "::error::kwild version prints '$got', but the image version is '$EXPECTED'" + exit 1 + fi + echo "kwild reports $EXPECTED" + - name: Build and push image (linux/amd64) uses: docker/build-push-action@v5 with: @@ -59,6 +90,10 @@ jobs: platforms: linux/amd64 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + build-args: | + TN_VERSION=${{ steps.meta.outputs.version }} + TN_COMMIT=${{ github.sha }} + TN_BUILD_TIME=${{ steps.commit.outputs.time }} cache-from: type=gha cache-to: type=gha,mode=max diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 8ca8cbab6..f1ecee7c0 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -32,34 +32,55 @@ jobs: VERSION=${GITHUB_REF#refs/tags/} VERSION=${VERSION#v} echo "VERSION=$VERSION" >> $GITHUB_ENV + # stamp the release, its commit and the commit time into kwild, as task build does + PKG=github.com/trufnetwork/node/cmd/version + BUILD_TIME=$(git log -1 --format=%cI) + echo "LDFLAGS=-X $PKG.TNVersion=$VERSION -X $PKG.TNCommit=$GITHUB_SHA -X $PKG.TNBuildTime=$BUILD_TIME" >> $GITHUB_ENV - name: Setup Go uses: actions/setup-go@v5 with: - go-version: '1.22.x' - check-latest: true + go-version-file: go.mod - name: Build for Darwin AMD64 run: | - GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -o ./.build/kwild ./cmd/kwild/main.go + GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "$LDFLAGS" -o ./.build/kwild ./cmd/kwild/main.go tar -czvf ./.build/tn_${{ env.VERSION }}_darwin_amd64.tar.gz -C ./.build kwild rm -rf ./.build/kwild - name: Build for Darwin ARM64 run: | - GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -o ./.build/kwild ./cmd/kwild/main.go + GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -ldflags "$LDFLAGS" -o ./.build/kwild ./cmd/kwild/main.go tar -czvf ./.build/tn_${{ env.VERSION }}_darwin_arm64.tar.gz -C ./.build kwild rm -rf ./.build/kwild - name: Build for Linux AMD64 run: | - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o ./.build/kwild ./cmd/kwild/main.go + GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "$LDFLAGS" -o ./.build/kwild ./cmd/kwild/main.go + + # The runner can run only this binary; the other three take the same LDFLAGS. + - name: Check that kwild reports the release version + run: | + got=$(./.build/kwild version --output json | jq -r '.result.version') + if [ "$got" != "$VERSION" ]; then + echo "::error::kwild version prints '$got', but the release is '$VERSION'" + exit 1 + fi + got=$(./.build/kwild --version) + if [ "$got" != "kwild version $VERSION" ]; then + echo "::error::kwild --version prints '$got', but the release is '$VERSION'" + exit 1 + fi + echo "kwild reports $VERSION" + + - name: Package Linux AMD64 + run: | tar -czvf ./.build/tn_${{ env.VERSION }}_linux_amd64.tar.gz -C ./.build kwild rm -rf ./.build/kwild - name: Build for Linux ARM64 run: | - GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -o ./.build/kwild ./cmd/kwild/main.go + GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags "$LDFLAGS" -o ./.build/kwild ./cmd/kwild/main.go tar -czvf ./.build/tn_${{ env.VERSION }}_linux_arm64.tar.gz -C ./.build kwild rm -rf ./.build/kwild diff --git a/cmd/version/utils.go b/cmd/version/utils.go index cdcac290e..b4f65ae0a 100644 --- a/cmd/version/utils.go +++ b/cmd/version/utils.go @@ -14,6 +14,17 @@ var ( TNBuildTime string // -X github.com/trufnetwork/node/cmd/version.TNBuildTime=... ) +// kwild --version, the "Starting kwild version" log line and kwil_ver in the +// RPC version methods (user.version and the others) read kwil-db's +// KwilVersion. When a build sets TNVersion, KwilVersion takes the same value, +// so they all report the TN release. The health endpoints keep their API +// versions. +func init() { + if TNVersion != "" { + kwilVersion.KwilVersion = TNVersion + } +} + // getVersion returns the TN version if set, otherwise falls back to kwil-db version func getVersion() string { if TNVersion != "" { diff --git a/deployments/Dockerfile b/deployments/Dockerfile index b68e66515..6dcbdf49e 100644 --- a/deployments/Dockerfile +++ b/deployments/Dockerfile @@ -18,12 +18,21 @@ COPY internal/ ./internal/ COPY extensions/ ./extensions/ COPY deployments/tn-entrypoint.sh ./deployments/tn-entrypoint.sh -# todo: incorporate task build process, otherwise images will lack information about the build +# The TN release, commit and commit time that kwild version, kwild --version, the +# startup log and user.version report. The image workflow passes them; a local +# build without them reports 0.0.0-dev. +ARG TN_VERSION=0.0.0-dev +ARG TN_COMMIT=unknown +ARG TN_BUILD_TIME= + # Use build cache mounts for faster rebuilds RUN --mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/root/.cache/go-build \ + pkg=github.com/trufnetwork/node/cmd/version && \ CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ - go build -o /app/.build/kwild /app/cmd/kwild/main.go + go build \ + -ldflags "-X ${pkg}.TNVersion=${TN_VERSION} -X ${pkg}.TNCommit=${TN_COMMIT} -X ${pkg}.TNBuildTime=${TN_BUILD_TIME}" \ + -o /app/.build/kwild /app/cmd/kwild/main.go # Pin to alpine3.21 to match the final runtime stage below: the floating # `postgres:16-alpine` tag has moved to Alpine 3.24, which dropped the clang19/llvm19 diff --git a/docs/node-operator-guide.md b/docs/node-operator-guide.md index 301d1c07b..e438a6c43 100644 --- a/docs/node-operator-guide.md +++ b/docs/node-operator-guide.md @@ -958,10 +958,12 @@ Sometimes you may need to reset your node to sync from a specific point or recov sudo mv .build/kwild /usr/local/bin/kwild sudo chmod +x /usr/local/bin/kwild - # Verify version + # Verify version: "Version:" shows the TN release, for example 2.6.9 kwild version ``` + A binary that prints `Version: 0.10.1` (kwil-db's version) was built before TN releases carried their own version. See [Check the version](node-upgrade-guide.md#3-install-the-latest-kwild-binary) in the upgrade guide for what the output shows and how to read the release of a node that runs in Docker. + 6. **Restore node identity and custom configuration** *(optional)*: > **Note**: Skip this step if you want to start with a completely fresh node identity and default configuration. Only restore if you need to preserve your existing validator status or custom settings. diff --git a/docs/node-upgrade-guide.md b/docs/node-upgrade-guide.md index 51526f787..fa641107d 100644 --- a/docs/node-upgrade-guide.md +++ b/docs/node-upgrade-guide.md @@ -67,6 +67,23 @@ If you manage `kwild` with another init system or inside Docker Compose, use the ```bash kwild version ``` + `Version` is the TN release the binary was built from, and `Git commit` is the first 9 characters of its commit. A `v2.6.9` release binary prints, for example: + ```text + Version: 2.6.9 + Git commit: + Built: (commit time) + Go version: go1.25.3 + OS/Arch: linux/amd64 + ``` + `kwild --version` prints the same release (`kwild version 2.6.9`), and `kwild version --output json | jq -r .result.version` prints only `2.6.9`. A binary built with `task build` prints the `git describe` version of your clone instead, such as `2.6.8-4-g9e008683` for a clone 4 commits past `v2.6.8`. + + A binary that prints `0.10.1` (kwil-db's version) was built before TN releases carried their own version, as the v2.6.8 release was. Read its release from the release page or tarball you downloaded it from. + + If your node runs in Docker, read the release from the image label of the running container: + ```bash + docker inspect --format '{{ index .Config.Labels "org.opencontainers.image.version" }}' + ``` + For an image that carries the TN version, `docker exec /app/kwild version` prints the same release; an older image prints `0.10.1` there. ---