From d41f0c08a29a04ad66f71d71ce8217437dc51fea Mon Sep 17 00:00:00 2001 From: auricom <27022259+auricom@users.noreply.github.com> Date: Tue, 3 Dec 2024 10:29:45 +0100 Subject: [PATCH] feat: wasmd --- .github/scripts/prepare-matrices.py | 5 +- .github/workflows/build-applications.yaml | 12 +++-- apps/wasmd/Dockerfile | 47 ++++++++++++++++++ apps/wasmd/ci/build.sh | 20 ++++++++ apps/wasmd/ci/goss.yaml | 11 +++++ apps/wasmd/ci/test.sh | 58 +++++++++++++++++++++++ apps/wasmd/entrypoint.sh | 45 ++++++++++++++++++ apps/wasmd/metadata.yaml | 24 ++++++++++ metadata.rules.cue | 3 +- 9 files changed, 220 insertions(+), 5 deletions(-) create mode 100644 apps/wasmd/Dockerfile create mode 100755 apps/wasmd/ci/build.sh create mode 100644 apps/wasmd/ci/goss.yaml create mode 100755 apps/wasmd/ci/test.sh create mode 100755 apps/wasmd/entrypoint.sh create mode 100644 apps/wasmd/metadata.yaml diff --git a/.github/scripts/prepare-matrices.py b/.github/scripts/prepare-matrices.py index ce896fd..dabcc78 100644 --- a/.github/scripts/prepare-matrices.py +++ b/.github/scripts/prepare-matrices.py @@ -90,6 +90,9 @@ def get_app_metadata(subdir, meta, forRelease=False, channels=None): if meta.get("binary_name"): platformToBuild["binary_name"] = meta["binary_name"] + if meta.get("binary_build_output_path"): + platformToBuild["binary_build_output_path"] = meta["binary_build_output_path"] + platformToBuild["update_modules_enabled"] = channel["update_modules"]["enabled"] if channel["update_modules"]["enabled"]: platformToBuild["update_modules_branch"] = channel["update_modules"]["cosmossdk_branch"] @@ -142,4 +145,4 @@ def get_app_metadata(subdir, meta, forRelease=False, channels=None): if appToBuild is not None: appsToBuild["apps"].extend(appToBuild["apps"]) appsToBuild["appsPlatforms"].extend(appToBuild["appsPlatforms"]) - print(json.dumps(appsToBuild)) \ No newline at end of file + print(json.dumps(appsToBuild)) diff --git a/.github/workflows/build-applications.yaml b/.github/workflows/build-applications.yaml index 52bf322..4b1dab1 100644 --- a/.github/workflows/build-applications.yaml +++ b/.github/workflows/build-applications.yaml @@ -147,6 +147,7 @@ jobs: MATRIX_APP_PATH: ${{ matrix.app.path }} GOARCH: ${{ matrix.app.target_arch }} BINARY_NAME: ${{ matrix.app.binary_name }} + BINARY_BUILD_OUTPUT_PATH: ${{ matrix.app.repository }}/${{ matrix.app.binary_build_output_path }} run: ./nightly-stack/apps/${{ matrix.app.name }}/ci/test.sh - name: Export Build Result @@ -170,15 +171,20 @@ jobs: if: ${{ matrix.app.publish_artifacts }} env: BINARY_NAME: ${{ matrix.app.binary_name }} + BINARY_BUILD_OUTPUT_PATH: ${{ matrix.app.binary_build_output_path }} run: | set -oue pipefail set -x # Create archive - if [[ -z $BINARY_NAME ]]; then - BINARY_PATH=$(find $(go env GOPATH)/bin | tail -n 1) + if [[ ! -z $BINARY_BUILD_OUTPUT_PATH ]]; then + BINARY_PATH=${{ matrix.app.repository }}/$BINARY_BUILD_OUTPUT_PATH else - BINARY_PATH=$(find $(go env GOPATH)/bin | grep $BINARY_NAME | tail -n 1) + if [[ -z $BINARY_NAME ]]; then + BINARY_PATH=$(find $(go env GOPATH)/bin | tail -n 1) + else + BINARY_PATH=$(find $(go env GOPATH)/bin | grep $BINARY_NAME | tail -n 1) + fi fi chmod +x $BINARY_PATH mv $BINARY_PATH ${{ github.workspace }}/${{ matrix.app.name }}-${{ matrix.app.channel }}-${{ matrix.app.target_os }}-${{ matrix.app.target_arch }} diff --git a/apps/wasmd/Dockerfile b/apps/wasmd/Dockerfile new file mode 100644 index 0000000..4fb234a --- /dev/null +++ b/apps/wasmd/Dockerfile @@ -0,0 +1,47 @@ +FROM cgr.dev/chainguard/wolfi-base:latest@sha256:a9547b680d3d322b14c2e46963b04d7afe71d927a3fa701a839559041989debe + +ARG BINARY + +WORKDIR /app + +USER root + +COPY ./$BINARY /app/node + +# trunk-ignore(hadolint/DL3018) +RUN wget --output-document /lib/libwasmvm.x86_64.so https://github.com/CosmWasm/wasmvm/releases/download/v2.1.3/libwasmvm.x86_64.so && \ + wget --output-document /lib/libwasmvm.aarch64.so https://github.com/CosmWasm/wasmvm/releases/download/v2.1.3/libwasmvm.aarch64.so && \ + apk update && \ + apk add --no-cache \ + bash \ + libstdc++ \ + jq \ + tini \ + && \ + mkdir -p /config && \ + chown -R nonroot:nonroot /app /config && \ + chmod -R u=rwX,go=rX /app /config && \ + chmod +x /app/node + +USER nonroot + +COPY ./entrypoint.sh /entrypoint.sh + +# API Server +EXPOSE 1317 + +# Pprof Server +EXPOSE 6060 + +# gRPC Server +EXPOSE 9090 + +# CometBFT RPC interface +EXPOSE 26657 + +HEALTHCHECK --interval=1m --timeout=3s CMD /app/node query node status | grep validator_hash || exit 1 + +VOLUME ["/config"] + +ENTRYPOINT ["tini", "--"] +CMD ["/entrypoint.sh"] diff --git a/apps/wasmd/ci/build.sh b/apps/wasmd/ci/build.sh new file mode 100755 index 0000000..57e3292 --- /dev/null +++ b/apps/wasmd/ci/build.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail +set -x + +if [[ ${GOARCH} == "arm64" ]]; then + export CC=aarch64-linux-gnu-gcc + export CGO_ENABLED=1 + export GOOS=linux +fi + +# Install CORSS tools +sudo apt install gcc-aarch64-linux-gnu + +# Import go modules +cd "${MATRIX_APP_REPOSITORY}/${MATRIX_APP_PATH}" +go mod tidy + +# Build application +LEDGER_ENABLED=false make build diff --git a/apps/wasmd/ci/goss.yaml b/apps/wasmd/ci/goss.yaml new file mode 100644 index 0000000..b33a2f7 --- /dev/null +++ b/apps/wasmd/ci/goss.yaml @@ -0,0 +1,11 @@ +--- +# https://github.com/aelsabbahy/goss/blob/master/docs/manual.md#process +process: + node: + running: true + +# https://github.com/aelsabbahy/goss/blob/master/docs/manual.md#port +port: + # https://github.com/aelsabbahy/goss/issues/149 + tcp:26657: + listening: true \ No newline at end of file diff --git a/apps/wasmd/ci/test.sh b/apps/wasmd/ci/test.sh new file mode 100755 index 0000000..e5bb918 --- /dev/null +++ b/apps/wasmd/ci/test.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +set -oue pipefail +set -x + +BINARY_PATH="${BINARY_BUILD_OUTPUT_PATH}" + +sudo wget --output-document /lib/libwasmvm.x86_64.so https://github.com/CosmWasm/wasmvm/releases/download/v2.1.3/libwasmvm.x86_64.so +sudo wget --output-document /lib/libwasmvm.aarch64.so https://github.com/CosmWasm/wasmvm/releases/download/v2.1.3/libwasmvm.aarch64.so + +# Set the timeout to 60 seconds +TIMEOUT=60 +START_TIME=$(date +%s) + +echo "Launch init procedure..." +CONFIG_HOME=$(${BINARY_PATH} config home) +${BINARY_PATH} config set client chain-id testchain +${BINARY_PATH} config set client keyring-backend test +sed -i 's/minimum-gas-prices = ""/minimum-gas-prices = "0.002token1"/' "${CONFIG_HOME}/config/app.toml" +${BINARY_PATH} config set app api.enable true +${BINARY_PATH} keys add alice +${BINARY_PATH} keys add bob +${BINARY_PATH} init testchain-node --chain-id testchain +jq '.app_state.gov.params.voting_period = "600s"' "${CONFIG_HOME}/config/genesis.json" > temp.json && mv temp.json "${CONFIG_HOME}/config/genesis.json" +jq '.app_state.gov.params.expedited_voting_period = "300s"' "${CONFIG_HOME}/config/genesis.json" > temp.json && mv temp.json "${CONFIG_HOME}/config/genesis.json" +jq '.app_state.mint.minter.inflation = "0.300000000000000000"' "${CONFIG_HOME}/config/genesis.json" > temp.json && mv temp.json "${CONFIG_HOME}/config/genesis.json" # to change the inflation +${BINARY_PATH} genesis add-genesis-account alice 5000000000stake --keyring-backend test +${BINARY_PATH} genesis add-genesis-account bob 5000000000stake --keyring-backend test +${BINARY_PATH} genesis gentx alice 1000000stake --chain-id testchain +${BINARY_PATH} genesis collect-gentxs + +# trunk-ignore(shellcheck/SC2210) +${BINARY_PATH} start > ./output.log 2>1 & +APP_PID=$! + + +while true; do + CURRENT_TIME=$(date +%s) + ELAPSED_TIME=$((CURRENT_TIME - START_TIME)) + + if [[ "${ELAPSED_TIME}" -ge "${TIMEOUT}" ]]; then + echo "Timeout reached. Application did not produce the success pattern within 60 seconds." + kill "${APP_PID}" + cat ./output.log + exit 1 + fi + + # Check that 4th block is produced to validate the application + if ${BINARY_PATH} query block-results 4; then + echo "Block #4 has been committed. Application is working correctly." + kill "${APP_PID}" + exit 0 + else + echo "Block height is not greater than 4." + fi + + sleep 3 +done diff --git a/apps/wasmd/entrypoint.sh b/apps/wasmd/entrypoint.sh new file mode 100755 index 0000000..2d7a073 --- /dev/null +++ b/apps/wasmd/entrypoint.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail +set -x + +export HOME="${NODE_HOME:-/config}" +COSMOS_CHAIN_ID="${COSMOS_CHAIN_ID:-testchain}" +COSMOS_MONIKER="${COSMOS_MONIKER:-testchain-node}" +COSMOS_NODE_CMD=/app/node +GENESIS_FILE="${HOME}/config/genesis.json" + +if [[ ! -f "${HOME}/config/config.toml" ]]; then + echo "Launch init procedure..." + + # Configure client settings + /app/node config set client chain-id "${COSMOS_CHAIN_ID}" --home "${HOME}" + /app/node config set client keyring-backend test --home "${HOME}" + sed -i 's/minimum-gas-prices = ""/minimum-gas-prices = "0.002token1"/' "${HOME}/config/app.toml" + /app/node config set app api.enable true --home "${HOME}" + + # Add keys + for user in validator faucet alice bob; do + "${COSMOS_NODE_CMD}" keys add "${user}" --home "${HOME}" + done + + # Initialize node + "${COSMOS_NODE_CMD}" init "${COSMOS_MONIKER}" --chain-id "${COSMOS_CHAIN_ID}" --home "${HOME}" + + # Set governance and inflation parameters + jq '.app_state.gov.params.voting_period = "600s" | + .app_state.gov.params.expedited_voting_period = "300s" | + .app_state.mint.minter.inflation = "0.300000000000000000"' \ + "${GENESIS_FILE}" >temp.json && mv temp.json "${GENESIS_FILE}" + + # Add genesis accounts + for account in validator faucet alice bob; do + "${COSMOS_NODE_CMD}" genesis add-genesis-account "${account}" 5000000000stake --keyring-backend test --home "${HOME}" + done + "${COSMOS_NODE_CMD}" genesis gentx validator 1000000stake --chain-id "${COSMOS_CHAIN_ID}" --home "${HOME}" + "${COSMOS_NODE_CMD}" genesis collect-gentxs --home "${HOME}" +fi + +exec \ + "${COSMOS_NODE_CMD}" start --home "${HOME}" \ + "$@" diff --git a/apps/wasmd/metadata.yaml b/apps/wasmd/metadata.yaml new file mode 100644 index 0000000..deccace --- /dev/null +++ b/apps/wasmd/metadata.yaml @@ -0,0 +1,24 @@ +--- +app: wasmd +repository: CosmWasm/wasmd +path: ./ +fetch_full_history: true +publish_artifacts: true +binary_build_output_path: build/wasmd +channels: + - name: v0.52.x + branch: upgrade_sdk_0.52 + platforms: [linux/amd64,linux/arm64] + container_tag_name: "0.52" + update_modules: + enabled: false + cosmossdk_branch: refs/heads/release/v0.52.x + tests_enabled: true + - name: v0.52.x-mods + branch: upgrade_sdk_0.52 + platforms: [linux/amd64,linux/arm64] + container_tag_name: 0.52-mods + update_modules: + enabled: true + cosmossdk_branch: refs/heads/release/v0.52.x + tests_enabled: true diff --git a/metadata.rules.cue b/metadata.rules.cue index 5813c9b..1f412e1 100644 --- a/metadata.rules.cue +++ b/metadata.rules.cue @@ -6,6 +6,7 @@ fetch_full_history?: bool publish_artifacts: bool binary_name?: string + binary_build_output_path?: string channels: [...#Channels] } @@ -23,4 +24,4 @@ #AppName: string & !="" & =~"^[a-zA-Z0-9_-]+$" #ChannelName: string & !="" & =~"^[a-zA-Z0-9._-]+$" -#Platforms: "linux/amd64" | "linux/arm64" \ No newline at end of file +#Platforms: "linux/amd64" | "linux/arm64"