Skip to content

Workflow file for this run

name: Build Docker images and Polkadot binaries
on:
push:
branches:
paths:
- .github/workflows/polkadot.yml
- dockerfiles/Dockerfile.test
- dockerfiles/Dockerfile.amd64
- release-version.txt
pull_request:
paths:
- .github/workflows/polkadot.yml
- dockerfiles/Dockerfile.test
- dockerfiles/Dockerfile.amd64
- release-version.txt
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
RELEASE_REF: refs/heads/main
jobs:
build-docker-images:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
image-name: ${{ steps.env-vars.outputs.image-name }}
strategy:
fail-fast: false
matrix:
debian-versions: [bullseye, bookworm]
rust-versions: [1.78.0]
clang-versions: [17, 18]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set environmental variables
id: env-vars
run: |
echo "FULL_IMAGE_NAME=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:debian-${{ matrix.debian-versions }}-rust-${{ matrix.rust-versions }}-clang-${{ matrix.clang-versions }}" >> "$GITHUB_ENV"
echo "image-name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" >> "$GITHUB_OUTPUT"
echo "NODE_GIT_REF=$(cat release-version.txt | tr -d '\n')" >> "$GITHUB_ENV"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: dockerfiles
file: dockerfiles/Dockerfile.amd64
push: false
load: true
labels: ${{ steps.meta.outputs.labels }}
build-args: |
DEBIAN_VERSION=${{ matrix.debian-versions }}
RUST_STABLE_VERSION=${{ matrix.rust-versions }}
CLANG_VERSION=${{ matrix.clang-versions }}
tags: ${{ env.FULL_IMAGE_NAME }},image-to-test:latest
- name: Switch to default Docker builder
run: docker buildx use default
- name: Build node to test Docker image
uses: docker/build-push-action@v5
with:
context: dockerfiles
file: dockerfiles/Dockerfile.test
push: false
pull: false
build-args: |
IMAGE_VERSION=image-to-test:latest
GIT_REF=${{ env.NODE_GIT_REF }}
tags: test-build-image
- name: Push Docker image
if: ${{ github.ref == env.RELEASE_REF }}
run: docker push ${{ env.FULL_IMAGE_NAME }}
build-binaries:
runs-on: ubuntu-latest
needs: [build-docker-images]
permissions:
contents: write
container:
image: ${{ needs.build-docker-images.outputs.image-name }}:debian-${{ matrix.debian-versions }}-rust-${{ matrix.rust-versions }}-clang-${{ matrix.clang-versions }}
env:
RUSTFLAGS: "-C target-cpu=${{ matrix.rustc-targets }}"
GH_TOKEN: ${{ github.token }}
options: --user 0:0
strategy:
fail-fast: false
matrix:
debian-versions: [bullseye, bookworm]
rust-versions: [1.78.0]
clang-versions: [17, 18]
rustc-targets: ["x86-64-v2", "x86-64-v3", "x86-64-v4"]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set environmental variables
run: |
NODE_GIT_REF=$(cat release-version.txt | tr -d '\n')
echo "NODE_GIT_REF=${NODE_GIT_REF}" >> $GITHUB_ENV
ENV_VERSION="debian-${{ matrix.debian-versions }}-rust-${{ matrix.rust-versions }}-clang-${{ matrix.clang-versions }}-${{ matrix.rustc-targets }}"
echo "BINARY_FILE_NAME=${NODE_GIT_REF}-${ENV_VERSION}" >> $GITHUB_ENV
echo "EXECUTE_WORKER_BINARY_FILE_NAME=${NODE_GIT_REF}-execute-worker-${ENV_VERSION}" >> $GITHUB_ENV
echo "PREPARE_WORKER_BINARY_FILE_NAME=${NODE_GIT_REF}-prepare-worker-${ENV_VERSION}" >> $GITHUB_ENV
echo "WASM_BUILD_WORKSPACE_HINT=$(pwd)/polkadot-sdk" >> $GITHUB_ENV
git config --global --add safe.directory $(pwd)
- name: Checkout polkadot-sdk repository
uses: actions/checkout@v4
with:
repository: paritytech/polkadot-sdk
path: polkadot-sdk
ref: ${{ env.NODE_GIT_REF }}
- name: Build binaries
working-directory: ./polkadot-sdk
run: |
cargo build --profile production --locked --bin polkadot --bin polkadot-execute-worker --bin polkadot-prepare-worker --target x86_64-unknown-linux-gnu
ls /opt/cargo_target/x86_64-unknown-linux-gnu/production
- name: "Create release"
if: ${{ github.ref == env.RELEASE_REF }}
uses: "actions/github-script@v6"
with:
script: |
try {
const response = await github.rest.repos.createRelease({
draft: false,
generate_release_notes: true,
name: process.env.NODE_GIT_REF,
owner: context.repo.owner,
prerelease: false,
repo: context.repo.repo,
tag_name: process.env.NODE_GIT_REF,
});
} catch (error) {
core.notice(error.message);
}
- name: Upload binaries
if: ${{ github.ref == env.RELEASE_REF }}
run: |
BINARIES_DIR=${CARGO_TARGET_DIR}/x86_64-unknown-linux-gnu/production
mv ${BINARIES_DIR}/polkadot ${BINARIES_DIR}/${BINARY_FILE_NAME}
mv ${BINARIES_DIR}/polkadot-execute-worker ${BINARIES_DIR}/${EXECUTE_WORKER_BINARY_FILE_NAME}
mv ${BINARIES_DIR}/polkadot-prepare-worker ${BINARIES_DIR}/${PREPARE_WORKER_BINARY_FILE_NAME}
ls ${BINARIES_DIR}
gh release upload ${{ env.NODE_GIT_REF }} ${BINARIES_DIR}/${BINARY_FILE_NAME} --clobber
gh release upload ${{ env.NODE_GIT_REF }} ${BINARIES_DIR}/${EXECUTE_WORKER_BINARY_FILE_NAME} --clobber
gh release upload ${{ env.NODE_GIT_REF }} ${BINARIES_DIR}/${PREPARE_WORKER_BINARY_FILE_NAME} --clobber