Skip to content

Commit

Permalink
zombie_builder and zombie_tester updated
Browse files Browse the repository at this point in the history
  • Loading branch information
qdrvm-ci committed Jun 22, 2024
1 parent 765c3b5 commit 1abe5e4
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 112 deletions.
145 changes: 55 additions & 90 deletions .github/workflows/zombie-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,58 +19,12 @@ on:

env:
DOCKER_REGISTRY_PATH: ${{ secrets.GCP_REGISTRY }}/${{ secrets.GCP_PROJECT }}/kagome-dev/
FORCE_REBUILD: false
GITHUB_HUNTER_USERNAME: ${{ secrets.HUNTER_USERNAME }}
GITHUB_HUNTER_TOKEN: ${{ secrets.HUNTER_TOKEN }}


BUILD_DIR: build
KAGOME_IN_DOCKER: 1
CTEST_OUTPUT_ON_FAILURE: 1
# Change all container: values to this variable once this feature is available
# https://gh.neting.ccmunity/t/how-to-set-and-access-a-workflow-variable/17335/6
CACHE_VERSION: v001
CACHE_PATHS: ./zombienet/docker/cargo

jobs:
# get_polkadot_binary_image:
# runs-on: ubuntu-latest
# timeout-minutes: 120
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
#
# - id: 'auth'
# uses: 'google-github-actions/auth@v2'
# with:
# 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: |
# echo ${GOOGLE_APPLICATION_CREDENTIALS}
# gcloud auth configure-docker


# build_and_push_zombie_builder:
# runs-on: [ actions-runner-controller ]
# timeout-minutes: 120
# steps:
# - uses: actions/checkout@v4
# - name: build zombie-builder
# working-directory: ./zombienet/docker
# run: make builder_latest
# - uses: azure/docker-login@v2
# with:
# login-server: https://index.docker.io/v1/
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_TOKEN }}
# - name: Push zombie-builder docker image
# working-directory: ./zombienet/docker
# run: make builder_push

build_polkadot_builder:
runs-on: ubuntu-latest
timeout-minutes: 60
Expand Down Expand Up @@ -158,6 +112,10 @@ jobs:
- name: "Push Polkadot APT Package"
working-directory: ./zombienet/docker
run: |
SHORT_COMMIT_HASH=$$(grep 'short_commit_hash:' commit_hash.txt | cut -d ' ' -f 2); \
POLKADOT_RELEASE_GLOBAL_NUMERIC=$$(grep 'numeric_version:' polkadot-sdk-versions.txt | cut -d ' ' -f 2); \
POLKADOT_BINARY_PACKAGE_VERSION=$${POLKADOT_RELEASE_GLOBAL_NUMERIC}-$${SHORT_COMMIT_HASH}; \
echo "polkadot_binary_package_version=$POLKADOT_BINARY_PACKAGE_VERSION" >> GITHUB_OUTPUT
make upload_apt_package
# - name: Archive build outputs
Expand All @@ -167,47 +125,54 @@ jobs:
# path: ./zombienet/docker/polkadot_binary/


# building_binary:
# runs-on: [ actions-runner-controller ]
# timeout-minutes: 120
# container:
# image: ${{ needs.build.outputs.polkadot_builder_image }}
# steps:
## - run: rustup toolchain install stable --profile minimal
##
## - name: Configure sccache env var and set build profile to ephemeral build
## run: |
## echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
## echo “SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
##
## - name: Run sccache-cache
## uses: mozilla-actions/sccache-action@v0.0.2
#
# - name: Build target
# run: |
# cargo update \
# -p test-parachain-adder-collator \
# -p polkadot-test-malus \
# -p test-parachain-undying-collator && \
# cargo build --profile testnet \
# -p test-parachain-adder-collator \
# -p polkadot-test-malus \
# -p test-parachain-undying-collator
#
# - name: upload artifact
# uses: actions/upload-artifact@v4
# with:
# name: malus
# path: /tmp/polkadot_binary/malus
#
# - name: upload artifact
# uses: actions/upload-artifact@v4
# with:
# name: undying-collator
# path: /tmp/polkadot_binary/undying-collator
#
# - name: upload artifact
# uses: actions/upload-artifact@v4
# with:
# name: adder-collator
# path: /tmp/polkadot_binary/adder-collator
build_zombie_tester:
runs-on: ubuntu-latest
needs: [building_binaries]
timeout-minutes: 60
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name : "Authenticate with Google Cloud"
uses: 'google-github-actions/auth@v2'
with:
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: |
gcloud auth configure-docker --quiet
gcloud auth configure-docker ${{ secrets.GCP_REGISTRY }} --quiet
- name: "Get Polkadot and Zombienet versions"
working-directory: ./zombienet/docker
run: make get_versions

- name: "Check if image tag exists"
id: check-tag
working-directory: ./zombienet/docker
run: |
ZOMBIENET_RELEASE=$$(grep 'short_version:' zombienet-versions.txt | cut -d ' ' -f 2)
POLKADOT_SDK_RELEASE=$$(grep 'polkadot_format_version:' polkadot-sdk-versions.txt | cut -d ' ' -f 2)
ZOMBIE_TESTER_IMAGE=${DOCKER_REGISTRY_PATH}zombie_tester:$${POLKADOT_SDK_RELEASE}_$${ZOMBIENET_RELEASE}
TAG_EXISTS=$(docker manifest inspect ${ZOMBIE_TESTER_IMAGE} > /dev/null 2>&1 && echo "true" || echo "false")
echo "exists=$TAG_EXISTS" >> $GITHUB_ENV
echo "zombie_tester_image=$ZOMBIE_TESTER_IMAGE" >> GITHUB_OUTPUT
- name: "Build Polkadot Builder"
working-directory: ./zombienet/docker
if: env.exists == 'false' || github.event.inputs.zombie_tester_image == 'true'
run: make zombie_tester \
DOCKER_REGISTRY_PATH=${DOCKER_REGISTRY_PATH}
GOOGLE_APPLICATION_CREDENTIALS=${GOOGLE_APPLICATION_CREDENTIALS} \
PROJECT_ID=${{ secrets.GCP_PROJECT }}
POLKADOT_BINARY_PACKAGE_VERSION=${{ needs.building_binaries.outputs.polkadot_binary_package_version }}

- name: "Push Polkadot Builder"
working-directory: ./zombienet/docker
if: env.exists == 'false' || github.event.inputs.zombie_tester_image == 'true'
run: make zombie_tester_push \
DOCKER_REGISTRY_PATH=${DOCKER_REGISTRY_PATH} \

33 changes: 33 additions & 0 deletions zombienet/docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ REGION ?= europe-north1
#USE_GCP_SCCACHE ?= true
SCCACHE_GCS_BUCKET ?=
GOOGLE_APPLICATION_CREDENTIALS ?=
PROJECT_ID ?=

CARGO_PACKETS=-p test-parachain-adder-collator -p polkadot-test-malus -p test-parachain-undying-collator
RESULT_BINARIES=./target/testnet/malus ./target/testnet/undying-collator ./target/testnet/adder-collator
RESULT_BIN_NAMES=malus undying-collator adder-collator

POLKADOT_BINARY_PACKAGE_VERSION ?=

export DOCKER_BUILDKIT=1
# BUILDKIT_PROGRESS - auto, plain, tty, rawjson
export BUILDKIT_PROGRESS=auto
Expand Down Expand Up @@ -83,6 +86,36 @@ polkadot_builder_push:
echo "One or more files are missing."; \
fi

zombie_tester_push:
if [ -f polkadot-sdk-versions.txt ]; then \
ZOMBIENET_RELEASE=$$(grep 'short_version:' zombienet-versions.txt | cut -d ' ' -f 2); \
POLKADOT_SDK_RELEASE=$$(grep 'polkadot_format_version:' polkadot-sdk-versions.txt | cut -d ' ' -f 2); \
docker push $(DOCKER_REGISTRY_PATH)zombie_tester:$${POLKADOT_SDK_RELEASE}_$${ZOMBIENET_RELEASE} ; \
docker push $(DOCKER_REGISTRY_PATH)zombie_tester:latest ; \
else \
echo "One or more files are missing."; \
fi

zombie_tester:
if [ -f polkadot-sdk-versions.txt ]; then \
ZOMBIENET_RELEASE=$$(grep 'short_version:' zombienet-versions.txt | cut -d ' ' -f 2); \
POLKADOT_SDK_RELEASE=$$(grep 'polkadot_format_version:' polkadot-sdk-versions.txt | cut -d ' ' -f 2); \
PROJECT_ID=$(PROJECT_ID) \
docker build \
--platform $(PLATFORM) \
--no-cache \
-t $(DOCKER_REGISTRY_PATH)zombie_tester:latest \
-t $(DOCKER_REGISTRY_PATH)zombie_tester:$${POLKADOT_SDK_RELEASE}_$${ZOMBIENET_RELEASE} \
--secret id=google_creds,src=$(GOOGLE_APPLICATION_CREDENTIALS) \
-f zombie_tester.Dockerfile \
--build-arg PROJECT_ID=$$PROJECT_ID \
--build-arg POLKADOT_BINARY_PACKAGE_VERSION="$(POLKADOT_BINARY_PACKAGE_VERSION)" \
--build-arg ZOMBIENET_RELEASE=$$ZOMBIENET_RELEASE \
--build-arg POLKADOT_SDK_RELEASE=$$POLKADOT_SDK_RELEASE . ; \
else \
echo "One or more files are missing."; \
fi

polkadot_binary:
if [ -f polkadot-sdk-versions.txt ]; then \
CONTAINER_NAME=polkadot_build_$$(openssl rand -hex 6); \
Expand Down
81 changes: 59 additions & 22 deletions zombienet/docker/zombie_tester.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
FROM ${MINIDEB_IMAGE} as zombienet-bin
ARG AUTHOR="k.azovtsev@qdrvm.io <Kirill Azovtsev>"

ARG BASE_IMAGE=bitnami/minideb@sha256:6cc3baf349947d587a9cd4971e81ff3ffc0d17382f2b5b6de63d6542bff10c16
ARG RUST_VERSION=1.79.0

ARG PROJECT_ID
ARG POLKADOT_BINARY_PACKAGE_VERSION
ARG POLKADOT_SDK_RELEASE
ARG ZOMBIENET_RELEASE

ARG REGION=europe-north1
ARG ARCHITECTURE=x86_64


FROM ${BASE_IMAGE} as zombie-tester

LABEL org.opencontainers.image.authors="${AUTHOR}"
LABEL org.opencontainers.image.description="Zombienet image"

ARG ZOMBIENET_RELEASE
ENV ZOMBIENET_RELEASE=$ZOMBIENET_RELEASE
ARG POLKADOT_SDK_RELEASE
ENV POLKADOT_SDK_RELEASE=$POLKADOT_SDK_RELEASE

RUN groupadd --gid 10000 nonroot && \
useradd --home-dir /home/nonroot \
Expand All @@ -20,7 +36,9 @@ RUN install_packages \
bash \
wget \
nano \
ca-certificates
ca-certificates \
gnupg2 \
curl

SHELL ["/bin/bash", "-c"]

Expand All @@ -30,10 +48,45 @@ WORKDIR /home/nonroot/bin

ENV PATH="/home/nonroot/bin:${PATH}"

RUN wget https://github.com/paritytech/zombienet/releases/download/$ZOMBIENET_RELEASE/zombienet-linux-x64 && \
RUN wget -q https://github.com/paritytech/zombienet/releases/download/$ZOMBIENET_RELEASE/zombienet-linux-x64 && \
chmod +x zombienet-linux-x64 && \
ln -s /home/nonroot/bin/zombienet-linux-x64 /home/nonroot/bin/zombienet

# Setup enterprise repository

ARG REGION
ENV REGION=$REGION

RUN curl -fsSL https://${REGION}-apt.pkg.dev/doc/repo-signing-key.gpg | \
gpg --dearmor -o /usr/share/keyrings/${REGION}-apt-archive-keyring.gpg

RUN curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | \
gpg --dearmor -o /usr/share/keyrings/cloud-google-apt-archive-keyring.gpg

RUN echo "deb [signed-by=/usr/share/keyrings/${REGION}-apt-archive-keyring.gpg] \
http://packages.cloud.google.com/apt apt-transport-artifact-registry-stable main" | \
tee -a /etc/apt/sources.list.d/artifact-registry.list

RUN install_packages apt-transport-artifact-registry

ARG PROJECT_ID
ENV PROJECT_ID=$PROJECT_ID

RUN echo "deb [signed-by=/usr/share/keyrings/europe-north1-apt-archive-keyring.gpg] \
ar+https://${REGION}-apt.pkg.dev/projects/${PROJECT_ID} kagome-apt main" | \
tee -a /etc/apt/sources.list.d/kagome.list

RUN sed -i 's|^\(\s*\)# *Service-Account-JSON ".*";|\1Service-Account-JSON "/root/.gcp/google_creds.json";|' \
/etc/apt/apt.conf.d/90artifact-registry

ARG POLKADOT_BINARY_PACKAGE_VERSION
ENV POLKADOT_BINARY_PACKAGE_VERSION=$POLKADOT_BINARY_PACKAGE_VERSION

RUN mkdir -p /root/.gcp
RUN --mount=type=secret,id=google_creds cat /run/secrets/google_creds > /root/.gcp/google_creds.json && \
install_packages polkadot-binary=${POLKADOT_BINARY_PACKAGE_VERSION} && \
rm /root/.gcp/google_creds.json && sed -i '1s/^/#/' /etc/apt/sources.list.d/kagome.list

# WARNING: Setup always returns 2, even when successful
RUN zombienet setup -y polkadot polkadot-parachain; \
EXIT_CODE=$?; \
Expand All @@ -44,30 +97,14 @@ RUN zombienet setup -y polkadot polkadot-parachain; \
exit $EXIT_CODE; \
fi;

COPY --from=polkadot-sdk-builder /home/nonroot/polkadot-sdk/target/testnet/malus /home/nonroot/bin
COPY --from=polkadot-sdk-builder /home/nonroot/polkadot-sdk/target/testnet/adder-collator /home/nonroot/bin
COPY --from=polkadot-sdk-builder /home/nonroot/polkadot-sdk/target/testnet/undying-collator /home/nonroot/bin

RUN ./polkadot --version && \
./polkadot-parachain --version && \
./zombienet version && \
./polkadot-execute-worker --version && \
./polkadot-prepare-worker --version && \
./malus --version && \
./adder-collator --version && \
./undying-collator --version


FROM zombienet-bin as final

LABEL org.opencontainers.image.authors="${AUTHOR}"
LABEL org.opencontainers.image.description="Zombienet Builder image"

ENV PATH="/home/nonroot/bin:${PATH}"
ARG ZOMBIENET_RELEASE
ENV ZOMBIENET_RELEASE=$ZOMBIENET_RELEASE
ARG POLKADOT_SDK_RELEASE
ENV POLKADOT_SDK_RELEASE=$POLKADOT_SDK_RELEASE
malus --version && \
adder-collator --version && \
undying-collator --version

RUN install_packages \
curl \
Expand Down

0 comments on commit 1abe5e4

Please sign in to comment.