diff --git a/.github/workflows/zombie-tests.yaml b/.github/workflows/zombie-tests.yaml index d17d291eed..22ca66a4eb 100644 --- a/.github/workflows/zombie-tests.yaml +++ b/.github/workflows/zombie-tests.yaml @@ -10,150 +10,201 @@ on: workflow_dispatch: env: + DOCKER_REGISTRY_PATH: ${{ secrets.GCP_REGISTRY }}/${{ secrets.GCP_PROJECT }}/kagome-dev/ BUILD_DIR: build KAGOME_IN_DOCKER: 1 CTEST_OUTPUT_ON_FAILURE: 1 - GITHUB_HUNTER_USERNAME: ${{ secrets.HUNTER_USERNAME }} - GITHUB_HUNTER_TOKEN: ${{ secrets.HUNTER_TOKEN }} - CACHE_VERSION: v07 - CACHE_PATHS: | - ~/Library/Caches/pip - ~/.cargo - ~/.ccache - ~/.hunter - ~/.rustup +# CACHE_VERSION: v07 +# CACHE_PATHS: | +# ~/Library/Caches/pip +# ~/.cargo +# ~/.ccache +# ~/.hunter +# ~/.rustup jobs: - Prepare-Kagome-Docker: - strategy: - fail-fast: false - matrix: - options: -# - name: "Self-hosted: Debug Docker image" -# build-type: "Debug" - - name: "Self-hosted: Release Docker image" - build-type: "Release" -# - name: "Self-hosted: RelWithDebInfo Docker image" -# build-type: "RelWithDebInfo" + building_binaries: runs-on: [ actions-runner-controller ] - timeout-minutes: 150 - container: qdrvm/kagome-dev:testing - steps: - - uses: actions/checkout@v4 - - uses: actions/cache@v4 - with: - path: ${{ env.CACHE_PATHS }} - key: ${{ github.job }}-${{ matrix.options.name }}-${{ env.CACHE_VERSION }} - - run: git config --global --add safe.directory /__w/kagome/kagome - - run: git fetch --prune --unshallow - - name: Build Kagome - env: - BUILD_TYPE: "${{ matrix.options.build-type }}" - KAGOME_ROOT: /__w/kagome/kagome - run: bash -c "cd $KAGOME_ROOT && source /venv/bin/activate && ./housekeeping/docker/kagome-dev/make.sh" - - name: Copy Kagome - env: - KAGOME_BUILD_DIR: /__w/kagome/kagome/build - run: bash -c "mkdir -p ${KAGOME_BUILD_DIR}/docker_context && cp -a ${KAGOME_BUILD_DIR}/node/kagome ${KAGOME_BUILD_DIR}/docker_context" - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Build Docker Image - uses: docker/build-push-action@v5 - with: - tags: kagome-dev:${{ github.run_number }} - file: ./housekeeping/docker/kagome/minideb-release.Dockerfile - context: /__w/kagome/kagome/build/docker_context - outputs: type=docker,dest=/tmp/kagome_dev.tar - - name: upload artifact - uses: actions/upload-artifact@v4 - with: - name: kagome-dev - path: /tmp/kagome_dev.tar + timeout-minutes: 120 - Prepare-Zombie-Tests-Docker: - runs-on: [ actions-runner-controller ] - timeout-minutes: 60 - needs: [Prepare-Kagome-Docker] steps: - - name: Download artifact - uses: actions/download-artifact@v4 + - name: Checkout repository + uses: actions/checkout@v4 + + - name: "Authenticate with Google Cloud" + uses: 'google-github-actions/auth@v2' with: - name: kagome-dev - path: /tmp - - name: Load image - run: | - docker load --input /tmp/kagome_dev.tar - docker image ls -a - - name: Set owner of working dir recursively - run: sudo chown -R $(whoami) . - - uses: actions/checkout@v4 - - name: Extract branch name - shell: bash + credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} + + - name: "Set up Cloud SDK" + uses: 'google-github-actions/setup-gcloud@v2' + + - name: "Configure Docker for GCR" run: | - branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} - echo "branch=${branch}" >> $GITHUB_OUTPUT - echo "Branch name: ${branch}" - id: extract_branch - - name: Build zombie-tester - working-directory: ./zombienet/docker - run: make tester BRANCH_NAME=${{ steps.extract_branch.outputs.branch }} KAGOME_IMAGE=kagome-dev:${{ github.run_number }} - - name: Archive zombie-tester - shell: bash - run: docker save -o /tmp/zombie-tester.tar zombie-tester:latest - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: zombie-tester - path: /tmp/zombie-tester.tar + gcloud auth configure-docker --quiet + gcloud auth configure-docker ${{ secrets.GCP_REGISTRY }} --quiet - Zombie-Tests: - runs-on: [ actions-runner-controller ] - timeout-minutes: 60 - needs: [Prepare-Zombie-Tests-Docker] - strategy: - fail-fast: false - matrix: - options: - - name: "PVF preparation & execution time" - test: "test-polkadot-functional-0001-parachains-pvf" - - name: "Disputes initiation, conclusion and lag" - test: "test-polkadot-functional-0002-parachains-disputes" - - name: "BEEFY voting and finality, test MMR proofs. Assumes Rococo sessions of 1 minute" - test: "test-polkadot-functional-0003-beefy-and-mmr" - - name: "Dispute finality lag when 1/3 of parachain validators always attempt to include an invalid block" - test: "test-polkadot-functional-0004-parachains-garbage-candidate" - - name: "Past-session dispute slashing" - test: "test-polkadot-functional-0005-parachains-disputes-past-session" - - name: "Test if parachains make progress with most of approvals being tranch0" - test: "test-polkadot-functional-0006-parachains-max-tranche0" - - name: "Test if disputes triggered on finalized blocks within scope always end as valid" - test: "test-polkadot-functional-0007-dispute-freshly-finalized" - - name: "Test if disputes triggered on finalized blocks out of scope never get to be confirmed and concluded" - test: "test-polkadot-functional-0008-dispute-old-finalized" - - name: "Approval voting coalescing does not lag finality" - test: "test-polkadot-functional-0009-approval-voting-coalescing" - - name: "Test validator disabling effects" - test: "test-polkadot-functional-0010-validator-disabling" - - name: "Test we are producing blocks at 6 seconds clip" - test: "test-polkadot-functional-0011-async-backing-6-seconds-rate" - steps: - - name: Download artifact - uses: actions/download-artifact@v4 - with: - name: zombie-tester - path: /tmp - - name: Load image + - name: "Get Polkadot and Zombienet versions" + working-directory: ./housekeeping/docker/kagome-dev + run: make get_versions + +# - name: "Setup package version if not rebuilding" +# working-directory: ./housekeeping/docker/kagome-dev +# run: | +# ARTIFACTS_REPO=$(grep '^ARTIFACTS_REPO ?=' Makefile | sed 's/ARTIFACTS_REPO ?= //') +# REGION=$(grep '^REGION ?=' Makefile | sed 's/REGION ?= //') +# gcloud config set artifacts/repository $ARTIFACTS_REPO +# gcloud config set artifacts/location $REGION +# POLKADOT_BINARY_PACKAGE_VERSION=$(gcloud artifacts versions list --package=kagome-dev --format=json | \ +# jq -r 'sort_by(.createTime) | .[-1] | {version: (.name | split("/") | last), createTime: .createTime} | .version') +# echo "POLKADOT_BINARY_PACKAGE_VERSION=${POLKADOT_BINARY_PACKAGE_VERSION}" | tee -a variables.env + + - name: "Build target" + #if: github.event.inputs.polkadot_binaries_rebuild == 'true' + working-directory: ./housekeeping/docker/kagome-dev + run: make kagome_dev_docker_build \ + DOCKER_REGISTRY_PATH=${DOCKER_REGISTRY_PATH} \ + GITHUB_HUNTER_USERNAME=${{ secrets.HUNTER_USERNAME }} \ + GITHUB_HUNTER_TOKEN=${{ secrets.HUNTER_TOKEN }} + + - name: "Push Polkadot APT Package" + #if: github.event.inputs.polkadot_binaries_rebuild == 'true' + working-directory: ./housekeeping/docker/kagome-dev run: | - docker load --input /tmp/zombie-tester.tar - docker image ls -a - - uses: actions/checkout@v4 - - name: Run test - working-directory: ./zombienet/docker - run: make ${{ matrix.options.test }} ZOMBIE_TESTER_IMAGE=zombie-tester:latest - - name: Upload test logs as artifact - if: always() - uses: actions/upload-artifact@v4 - with: - name: logs-${{ matrix.options.test }} - path: /tmp/test_logs + SHORT_COMMIT_HASH=$(grep 'short_commit_hash:' commit_hash.txt | cut -d ' ' -f 2) + make upload_apt_package + + +# Prepare-Kagome-Docker: +# strategy: +# fail-fast: false +# matrix: +# options: +## - name: "Self-hosted: Debug Docker image" +## build-type: "Debug" +# - name: "Self-hosted: Release Docker image" +# build-type: "Release" +## - name: "Self-hosted: RelWithDebInfo Docker image" +## build-type: "RelWithDebInfo" +# runs-on: [ actions-runner-controller ] +# timeout-minutes: 150 +# container: qdrvm/kagome-dev:testing +# steps: +# - uses: actions/checkout@v4 +# - uses: actions/cache@v4 +# with: +# path: ${{ env.CACHE_PATHS }} +# key: ${{ github.job }}-${{ matrix.options.name }}-${{ env.CACHE_VERSION }} +# - run: git config --global --add safe.directory /__w/kagome/kagome +# - run: git fetch --prune --unshallow +# - name: Build Kagome +# env: +# BUILD_TYPE: "${{ matrix.options.build-type }}" +# KAGOME_ROOT: /__w/kagome/kagome +# run: bash -c "cd $KAGOME_ROOT && source /venv/bin/activate && ./housekeeping/docker/kagome-dev/make.sh" +# - name: Copy Kagome +# env: +# KAGOME_BUILD_DIR: /__w/kagome/kagome/build +# run: bash -c "mkdir -p ${KAGOME_BUILD_DIR}/docker_context && cp -a ${KAGOME_BUILD_DIR}/node/kagome ${KAGOME_BUILD_DIR}/docker_context" +# - name: Set up Docker Buildx +# uses: docker/setup-buildx-action@v3 +# - name: Build Docker Image +# uses: docker/build-push-action@v5 +# with: +# tags: kagome-dev:${{ github.run_number }} +# file: ./housekeeping/docker/kagome/minideb-release.Dockerfile +# context: /__w/kagome/kagome/build/docker_context +# outputs: type=docker,dest=/tmp/kagome_dev.tar +# - name: upload artifact +# uses: actions/upload-artifact@v4 +# with: +# name: kagome-dev +# path: /tmp/kagome_dev.tar + +# Prepare-Zombie-Tests-Docker: +# runs-on: [ actions-runner-controller ] +# timeout-minutes: 60 +# needs: [Prepare-Kagome-Docker] +# steps: +# - name: Download artifact +# uses: actions/download-artifact@v4 +# with: +# name: kagome-dev +# path: /tmp +# - name: Load image +# run: | +# docker load --input /tmp/kagome_dev.tar +# docker image ls -a +# - name: Set owner of working dir recursively +# run: sudo chown -R $(whoami) . +# - uses: actions/checkout@v4 +# - name: Extract branch name +# shell: bash +# run: | +# branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} +# echo "branch=${branch}" >> $GITHUB_OUTPUT +# echo "Branch name: ${branch}" +# id: extract_branch +# - name: Build zombie-tester +# working-directory: ./zombienet/docker +# run: make tester BRANCH_NAME=${{ steps.extract_branch.outputs.branch }} KAGOME_IMAGE=kagome-dev:${{ github.run_number }} +# - name: Archive zombie-tester +# shell: bash +# run: docker save -o /tmp/zombie-tester.tar zombie-tester:latest +# - name: Upload artifact +# uses: actions/upload-artifact@v4 +# with: +# name: zombie-tester +# path: /tmp/zombie-tester.tar +# +# Zombie-Tests: +# runs-on: [ actions-runner-controller ] +# timeout-minutes: 60 +# needs: [Prepare-Zombie-Tests-Docker] +# strategy: +# fail-fast: false +# matrix: +# options: +# - name: "PVF preparation & execution time" +# test: "test-polkadot-functional-0001-parachains-pvf" +# - name: "Disputes initiation, conclusion and lag" +# test: "test-polkadot-functional-0002-parachains-disputes" +# - name: "BEEFY voting and finality, test MMR proofs. Assumes Rococo sessions of 1 minute" +# test: "test-polkadot-functional-0003-beefy-and-mmr" +# - name: "Dispute finality lag when 1/3 of parachain validators always attempt to include an invalid block" +# test: "test-polkadot-functional-0004-parachains-garbage-candidate" +# - name: "Past-session dispute slashing" +# test: "test-polkadot-functional-0005-parachains-disputes-past-session" +# - name: "Test if parachains make progress with most of approvals being tranch0" +# test: "test-polkadot-functional-0006-parachains-max-tranche0" +# - name: "Test if disputes triggered on finalized blocks within scope always end as valid" +# test: "test-polkadot-functional-0007-dispute-freshly-finalized" +# - name: "Test if disputes triggered on finalized blocks out of scope never get to be confirmed and concluded" +# test: "test-polkadot-functional-0008-dispute-old-finalized" +# - name: "Approval voting coalescing does not lag finality" +# test: "test-polkadot-functional-0009-approval-voting-coalescing" +# - name: "Test validator disabling effects" +# test: "test-polkadot-functional-0010-validator-disabling" +# - name: "Test we are producing blocks at 6 seconds clip" +# test: "test-polkadot-functional-0011-async-backing-6-seconds-rate" +# steps: +# - name: Download artifact +# uses: actions/download-artifact@v4 +# with: +# name: zombie-tester +# path: /tmp +# - name: Load image +# run: | +# docker load --input /tmp/zombie-tester.tar +# docker image ls -a +# - uses: actions/checkout@v4 +# - name: Run test +# working-directory: ./zombienet/docker +# run: make ${{ matrix.options.test }} ZOMBIE_TESTER_IMAGE=zombie-tester:latest +# - name: Upload test logs as artifact +# if: always() +# uses: actions/upload-artifact@v4 +# with: +# name: logs-${{ matrix.options.test }} +# path: /tmp/test_logs diff --git a/housekeeping/docker/kagome-dev/.gitignore b/housekeeping/docker/kagome-dev/.gitignore new file mode 100644 index 0000000000..cde438ac9c --- /dev/null +++ b/housekeeping/docker/kagome-dev/.gitignore @@ -0,0 +1,9 @@ +*-versions.txt +commit_hash.txt + +cumulus +polkadot + +cargo/ +pkg/ +polkadot_binary/ \ No newline at end of file diff --git a/housekeeping/docker/kagome-dev/Makefile b/housekeeping/docker/kagome-dev/Makefile index 7c5ad070c7..ea6db9511e 100644 --- a/housekeeping/docker/kagome-dev/Makefile +++ b/housekeeping/docker/kagome-dev/Makefile @@ -6,17 +6,32 @@ MINIDEB_IMAGE ?= bitnami/minideb@sha256:6cc3baf349947d587a9cd4971e81ff3ffc0d1738 PLATFORM ?= linux/amd64 ARCHITECTURE ?= x86_64 +PACKAGE_ARCHITECTURE ?= amd64 DOCKER_REGISTRY_PATH ?= +ARTIFACTS_REPO ?= kagome-apt +REGION ?= europe-north1 MINIDEB_HASH := $(subst bitnami/minideb@sha256:,,$(MINIDEB_IMAGE)) MINIDEB_SHORT_HASH := $(shell echo $(MINIDEB_HASH) | cut -c1-7) MINIDEB_TAG = $(MINIDEB_SHORT_HASH)_rust-$(RUST_VERSION) +GITHUB_HUNTER_USERNAME ?= +GITHUB_HUNTER_TOKEN ?= +CTEST_OUTPUT_ON_FAILURE ?= 1 + +# Debug, Release, RelWithDebInfo +BUILD_TYPE ?= Debug +BUILD_DIR ?= build + export DOCKER_BUILDKIT=1 # BUILDKIT_PROGRESS - auto, plain, tty, rawjson export BUILDKIT_PROGRESS=auto +get_versions: + echo "full_commit_hash: `git rev-parse HEAD`" > commit_hash.txt + echo "short_commit_hash: `git rev-parse HEAD | head -c 7`" >> commit_hash.txt + kagome_builder_deb: docker build --platform $(PLATFORM) \ -t $(DOCKER_REGISTRY_PATH)kagome_builder_deb:$(MINIDEB_TAG) \ @@ -28,4 +43,67 @@ kagome_builder_deb: kagome_builder_deb_push: docker push $(DOCKER_REGISTRY_PATH)kagome_builder_deb:$(MINIDEB_TAG) ; \ - docker push $(DOCKER_REGISTRY_PATH)kagome_builder_deb:latest ; \ + docker push $(DOCKER_REGISTRY_PATH)kagome_builder_deb:latest + +kagome_dev_docker_build: + CONTAINER_NAME=kagome_dev_build_$$(openssl rand -hex 6); \ + SHORT_COMMIT_HASH=$$(grep 'short_commit_hash:' commit_hash.txt | cut -d ' ' -f 2); \ + BUILD_THREADS=$$(nproc 2>/dev/null || sysctl -n hw.ncpu); \ + DOCKER_EXEC_RESULT=0 ; \ + if [ "$(BUILD_TYPE)" = "Debug" ]; then \ + echo "debug"; \ + docker run -d --name $$CONTAINER_NAME \ + --platform $(PLATFORM) \ + --entrypoint "/bin/bash" \ + -e SHORT_COMMIT_HASH=$$SHORT_COMMIT_HASH \ + -e BUILD_TYPE=$(BUILD_TYPE) \ + -e BUILD_THREADS=$$BUILD_THREADS \ + -e PACKAGE_ARCHITECTURE=$(PACKAGE_ARCHITECTURE) \ + -e GITHUB_HUNTER_USERNAME=$(GITHUB_HUNTER_USERNAME) \ + -e GITHUB_HUNTER_TOKEN=$(GITHUB_HUNTER_TOKEN) \ + -e CTEST_OUTPUT_ON_FAILURE=$(CTEST_OUTPUT_ON_FAILURE) \ + -v $$(pwd)/../../../../kagome:/opt/kagome \ + -v $(GOOGLE_APPLICATION_CREDENTIALS):/root/.gcp/google_creds.json \ + $(DOCKER_REGISTRY_PATH)kagome_builder_deb:$(MINIDEB_TAG) \ + -c "tail -f /dev/null"; \ + docker exec -t $$CONTAINER_NAME /bin/bash -c \ + "cd /opt/kagome && \ + git config --global --add safe.directory /opt/kagome && \ + source /venv/bin/activate && \ + git submodule update --init && \ + echo \"Building in $(pwd)\" && \ + cmake . -B\"$(BUILD_DIR)\" -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=\"${BUILD_TYPE}\" -DBACKWARD=OFF && \ + cmake --build \"$(BUILD_DIR)\" --target kagome -- -j${BUILD_THREADS} && \ + mkdir -p /tmp/kagome && \ + cp /opt/kagome/$(BUILD_DIR)/node/kagome /tmp/kagome/kagome && \ + cd /opt/kagome/housekeeping/docker/kagome-dev && \ + ./build_apt_package.sh \ + $$SHORT_COMMIT_HASH-$$BUILD_TYPE \ + $(PACKAGE_ARCHITECTURE) \ + kagome-dev \ + /tmp/kagome \ + 'Kagome Dev Debian Package' \ + 'libstdc++6, zlib1g, libgcc-s1, libc6' ; \ + " || DOCKER_EXEC_RESULT=$$? ; \ + elif [ "$(BUILD_TYPE)" = "Release" ]; then \ + echo "release"; \ + BUILD_THREADS=1 ; \ + elif [ "$(BUILD_TYPE)" = "RelWithDebInfo" ]; then \ + echo "relwithdebinfo"; \ + BUILD_THREADS=2 ; \ + else \ + echo "Invalid BUILD_TYPE"; \ + exit 1; \ + fi ; \ + if [ $$DOCKER_EXEC_RESULT -ne 0 ]; then \ + echo "Error: Docker exec failed with return code $$DOCKER_EXEC_RESULT"; \ + docker stop $$CONTAINER_NAME; \ + exit $$DOCKER_EXEC_RESULT; \ + fi; \ + docker stop $$CONTAINER_NAME + +upload_apt_package: + SHORT_COMMIT_HASH=$$(grep 'short_commit_hash:' commit_hash.txt | cut -d ' ' -f 2); \ + gcloud config set artifacts/repository $(ARTIFACTS_REPO); \ + gcloud config set artifacts/location $(REGION); \ + gcloud artifacts apt upload $(ARTIFACTS_REPO) --source=./pkg/kagome-dev_$$SHORT_COMMIT_HASH-$$BUILD_TYPE_$(PACKAGE_ARCHITECTURE).deb \ No newline at end of file diff --git a/housekeeping/docker/kagome-dev/build_apt_package.sh b/housekeeping/docker/kagome-dev/build_apt_package.sh new file mode 100644 index 0000000000..5c82325b2e --- /dev/null +++ b/housekeeping/docker/kagome-dev/build_apt_package.sh @@ -0,0 +1,93 @@ +#!/bin/bash + +set -euo pipefail + +# Function to display usage +usage() { + echo "Usage: $0 " + echo "Example: $0 1.0 amd64 mypackage /path/to/artifacts 'libc6, libssl1.1'" + exit 1 +} + +# Function to log messages +log() { + local MESSAGE=$1 + echo "[INFO] $MESSAGE" +} + +# Check for the correct number of arguments +if [ "$#" -ne 6 ]; then + usage +fi + +# Assign variables from arguments +VERSION=$1 +ARCHITECTURE=$2 +PACKAGE_NAME=$3 +ARTIFACTS_DIR=$4 +DESCRIPTION=$5 +DEPENDENCIES=$6 + +# Define maintainer and homepage variables +MAINTAINER="Zak Fein " +HOMEPAGE="https://qdrvm.io" +DIR_NAME=${PACKAGE_NAME}_${VERSION}_${ARCHITECTURE} + +# Validate parameters +log "Validating parameters..." + +if [ -z "$VERSION" ]; then + echo "Error: Version is required." >&2 + exit 1 +fi + +if [ -z "$ARCHITECTURE" ]; then + echo "Error: Architecture is required." >&2 + exit 1 +fi + +if [ -z "$PACKAGE_NAME" ]; then + echo "Error: Package name is required." >&2 + exit 1 +fi + +if [ -z "$ARTIFACTS_DIR" ] || [ ! -d "$ARTIFACTS_DIR" ]; then + echo "Error: A valid artifacts directory is required." >&2 + exit 1 +fi + +if [ -z "$DESCRIPTION" ]; then + echo "Error: Description is required." >&2 + exit 1 +fi + +if [ -z "$DEPENDENCIES" ]; then + echo "Error: Dependencies are required." >&2 + exit 1 +fi + +log "Creating package directory structure..." +mkdir -p ./pkg/${DIR_NAME}/DEBIAN +mkdir -p ./pkg/${DIR_NAME}/usr/local/bin + +log "Copying artifacts..." +mv -f ${ARTIFACTS_DIR}/* ./pkg/${DIR_NAME}/usr/local/bin/ + +log "Creating control file..." +cat < ./pkg/${DIR_NAME}/DEBIAN/control +Package: ${PACKAGE_NAME} +Version: ${VERSION} +Maintainer: ${MAINTAINER} +Depends: ${DEPENDENCIES} +Architecture: ${ARCHITECTURE} +Homepage: ${HOMEPAGE} +Description: ${DESCRIPTION} +EOF + +log "Building the package..." +dpkg --build ./pkg/${DIR_NAME} + +log "Displaying package info..." +dpkg-deb --info ./pkg/${DIR_NAME}.deb + +log "Package created successfully."