Skip to content

Commit ee1ecd6

Browse files
integrated srtool for deterministic runtime builds
1 parent ecaadf1 commit ee1ecd6

2 files changed

Lines changed: 53 additions & 2 deletions

File tree

.github/workflows/publish.yml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ jobs:
4848
type=semver,pattern={{major}}.{{minor}}
4949
type=sha,format=long
5050
51+
# ------------------------------------------------------------
52+
# Build the runtime deterministically with srtool and capture
53+
# its SHA-256 so we can inject it as an OCI label.
54+
# ------------------------------------------------------------
55+
- name: Build runtime with srtool & extract Wasm hash
56+
id: wasm
57+
run: |
58+
set -euo pipefail
59+
echo "🛠️ Running srtool to build compact runtime…"
60+
HASH=$(docker run --rm \
61+
-v "${PWD}":/build \
62+
--workdir /build \
63+
paritytech/srtool:1.84.1 \
64+
bash -c "/srtool/build >/dev/null 2>&1 && sha256sum runtime/fennel/target/srtool/release/wbuild/fennel-node-runtime/fennel_node_runtime.compact.wasm | awk '{print \"0x\"\$1}'")
65+
echo "WASM_HASH=$HASH" >> $GITHUB_ENV
66+
echo "hash=$HASH" >> $GITHUB_OUTPUT
67+
echo "✅ Deterministic Wasm hash: $HASH"
68+
5169
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
5270
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
5371
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
@@ -58,6 +76,8 @@ jobs:
5876
push: true
5977
tags: ${{ steps.meta.outputs.tags }}
6078
labels: ${{ steps.meta.outputs.labels }}
79+
build-args: |
80+
WASM_HASH=${{ env.WASM_HASH }}
6181
cache-from: type=gha
6282
cache-to: type=gha,mode=max
6383

@@ -66,8 +86,10 @@ jobs:
6686
run: |
6787
mkdir -p ./artifacts
6888
echo "Image name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" > ./artifacts/image-info.txt
69-
echo "Tags: ${{ steps.meta.outputs.tags }}" >> ./artifacts/image-info.txt
70-
echo "Created: $(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> ./artifacts/image-info.txt
89+
echo "Tags: ${{ steps.meta.outputs.tags }}" >> ./artifacts/image-info.txt
90+
echo "Wasm hash: ${{ env.WASM_HASH }}" >> ./artifacts/image-info.txt
91+
echo "Digest: ${{ steps.build-and-push-image.outputs.digest }}" >> ./artifacts/image-info.txt
92+
echo "Created: $(date -u +\"%Y-%m-%dT%H:%M:%SZ\")" >> ./artifacts/image-info.txt
7193
7294
- name: Upload Docker image info artifact
7395
uses: actions/upload-artifact@v4

Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,27 @@ FROM base AS tester
1515
COPY . .
1616
RUN cargo test --features=runtime-benchmarks
1717

18+
# --- New stage: deterministic WASM runtime build using srtool -----------------
19+
FROM docker.io/paritytech/srtool:1.84.1 AS srtool
20+
21+
# The srtool image expects the sources to live in /build
22+
WORKDIR /build
23+
24+
# Copy the full workspace so that frame pallets & dependencies are available
25+
COPY --chown=builder:builder . .
26+
27+
# Tell srtool which crate contains the runtime. Adjust these paths/names if you
28+
# ever rename the runtime crate or move it to another folder.
29+
ENV RUNTIME_DIR=runtime/fennel
30+
ENV PACKAGE=fennel-node-runtime
31+
32+
# Build the runtime in deterministic mode. The build script lives inside the
33+
# image under /scripts/build
34+
RUN /srtool/build
35+
36+
# The compact deterministic wasm will be available below.
37+
ENV DETERMINISTIC_WASM_PATH=target/srtool/release/wbuild/fennel-node-runtime/fennel_node_runtime.compact.wasm
38+
1839
# Builder stage - build with cached dependencies
1940
FROM base AS builder
2041
COPY --from=planner /fennel/recipe.json recipe.json
@@ -28,6 +49,14 @@ FROM docker.io/parity/base-bin:latest
2849
# Copy the node binary
2950
COPY --from=builder /fennel/target/release/fennel-node /usr/local/bin/fennel-node
3051

52+
# Copy the deterministic wasm compiled with srtool (optional but convenient for
53+
# governance upgrades & CI verification)
54+
COPY --from=srtool /build/runtime/fennel/target/srtool/release/wbuild/fennel-node-runtime/fennel_node_runtime.compact.wasm /usr/local/bin/fennel_node_runtime.compact.wasm
55+
RUN test -f /usr/local/bin/fennel_node_runtime.compact.wasm
56+
57+
ARG WASM_HASH=unknown
58+
LABEL io.parity.srtool.wasm-hash=${WASM_HASH}
59+
3160
USER root
3261
RUN useradd -m -u 1001 -U -s /bin/sh -d /fennel fennel && \
3362
mkdir -p /data /fennel/.local/share && \

0 commit comments

Comments
 (0)