diff --git a/.github/workflows/flow-pull-request-checks.yaml b/.github/workflows/flow-pull-request-checks.yaml index 2b703ca39..670595d52 100644 --- a/.github/workflows/flow-pull-request-checks.yaml +++ b/.github/workflows/flow-pull-request-checks.yaml @@ -44,20 +44,23 @@ jobs: enable-spotless-check: true unit-tests: - name: Unit Tests + name: FST Java Unit Tests uses: ./.github/workflows/zxc-compile-code.yaml with: custom-job-label: Standard enable-unit-tests: true - nodejs-tests: - name: NodeJS CLI Tests - uses: ./.github/workflows/zxc-compile-code.yaml + chart-tests: + name: FS Helm Chart Tests + uses: ./.github/workflows/zxc-helm-chart-tests.yaml + with: + custom-job-label: Standard + + fsnetman-tests: + name: FS Network Manager Tests + uses: ./.github/workflows/zxc-fsnetman-tests.yaml with: custom-job-label: Standard - enable-unit-tests: false - enable-nodejs-tests: true - node-version: 18 codecov: name: CodeCov diff --git a/.github/workflows/zxc-compile-code.yaml b/.github/workflows/zxc-compile-code.yaml index 1918bfd56..0ac861620 100644 --- a/.github/workflows/zxc-compile-code.yaml +++ b/.github/workflows/zxc-compile-code.yaml @@ -28,11 +28,6 @@ on: type: boolean required: false default: false - enable-nodejs-tests: - description: "NodeJS Testing Enabled" - type: boolean - required: false - default: false enable-spotless-check: description: "Spotless Check Enabled" type: boolean @@ -114,7 +109,7 @@ jobs: - name: Setup Kind uses: helm/kind-action@dda0770415bac9fc20092cacbc54aa298604d140 # v1.8.0 - if: ${{ (inputs.enable-unit-tests || inputs.enable-nodejs-tests) && !cancelled() && !failure() }} + if: ${{ inputs.enable-unit-tests && !cancelled() && !failure() }} with: config: dev/dev-cluster.yaml version: v0.19.0 @@ -123,13 +118,13 @@ jobs: - name: Setup Helm uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 # v3.5 - if: ${{ (inputs.enable-unit-tests || inputs.enable-nodejs-tests) && !cancelled() && !failure() }} + if: ${{ inputs.enable-unit-tests && !cancelled() && !failure() }} with: version: "v3.12.3" # helm version # Technically, this step is not required for the unit tests to run, but it is useful for debugging setup issues. - name: Kubernetes Cluster Info - if: ${{ (inputs.enable-unit-tests || inputs.enable-nodejs-tests) && !cancelled() && !failure() }} + if: ${{ inputs.enable-unit-tests && !cancelled() && !failure() }} run: | kubectl config get-contexts kubectl get crd @@ -140,7 +135,7 @@ jobs: - name: Authenticate to Google Cloud id: google-auth uses: google-github-actions/auth@35b0e87d162680511bf346c299f71c9c5c379033 # v1.1.1 - if: ${{ (inputs.enable-unit-tests || inputs.enable-nodejs-tests) && !cancelled() && !failure() }} + if: ${{ inputs.enable-unit-tests && !cancelled() && !failure() }} with: token_format: 'access_token' workload_identity_provider: "projects/101730247931/locations/global/workloadIdentityPools/hedera-registry-pool/providers/hedera-registry-gh-actions" @@ -152,40 +147,6 @@ jobs: if: ${{ inputs.enable-unit-tests && !cancelled() }} uses: google-github-actions/setup-gcloud@e30db14379863a8c79331b04a9969f4c1e225e0b # v1.1.1 - - name: NodeJS CLI Unit Tests - id: nodejs-test - working-directory: fullstack-network-manager - if: ${{ inputs.enable-nodejs-tests && !cancelled() && !failure() }} - run: | - npm i - npm test - - - name: NodeJS CLI E2E Tests - id: nodejs-test-e2e - working-directory: fullstack-network-manager - if: ${{ inputs.enable-nodejs-tests && !cancelled() && !failure() }} - run: | - export DEV_MODE=true - npm i - npm link - fsnetman init -d ../charts - fsnetman cluster create - fsnetman cluster setup - fsnetman chart install - npm run test-e2e - - # This step tests the Helm chart direct mode of operation which uses the ubi8-init-java17 image. - - name: Helm Chart Test (Direct Install) - working-directory: dev - if: ${{ inputs.enable-unit-tests && !cancelled() && !failure() }} - run: make ci-test SCRIPT_NAME=direct-install.sh - - # This step tests the Helm chart NMT mode of operation which uses the ubi8-init-dind image. - - name: Helm Chart Test (NMT Install) - working-directory: dev - if: ${{ inputs.enable-unit-tests && !cancelled() && !failure() }} - run: make ci-test SCRIPT_NAME=nmt-install.sh - - name: Compile id: gradle-build uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a # v2.9.0 @@ -237,7 +198,7 @@ jobs: # This step is to cache the helm charts before we start unit tests - name: Setup Helm Charts - if: ${{ (inputs.enable-unit-tests || inputs.enable-nodejs-tests) && !cancelled() && !failure() }} + if: ${{ inputs.enable-unit-tests && !cancelled() && !failure() }} run: | helm repo add haproxytech https://haproxytech.github.io/helm-charts helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx diff --git a/.github/workflows/zxc-fsnetman-tests.yaml b/.github/workflows/zxc-fsnetman-tests.yaml new file mode 100644 index 000000000..3ec1e2ff6 --- /dev/null +++ b/.github/workflows/zxc-fsnetman-tests.yaml @@ -0,0 +1,135 @@ +## +# Copyright (C) 2023 Hedera Hashgraph, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +## + +name: "ZXC: FS Network Manager Tests" +# The purpose of this reusable workflow is to compile the code and run the unit tests on every PR and commit. +# This reusable component is called by the following workflows: +# - .github/workflows/flow-pull-request-checks.yaml + +on: + workflow_call: + inputs: + custom-job-label: + description: "Custom Job Label:" + type: string + required: false + default: "fsnetman Test" + node-version: + description: "NodeJS Version:" + type: string + required: false + default: "18" + +defaults: + run: + shell: bash + +permissions: + id-token: write + contents: read + actions: read + pull-requests: write + checks: write + statuses: write + +jobs: + test: + name: ${{ inputs.custom-job-label || 'fsnetman Test' }} + runs-on: [self-hosted, Linux, medium, ephemeral] + steps: + - name: Get related changed files + id: changed-files + uses: tj-actions/changed-files@25ef3926d147cd02fc7e931c1ef50772bbb0d25d #v40.1.1 + with: + files: | + fullstack-network-manager/** + + - name: List all related changed files + id: check-changed-files + run: | + echo "Modified files" + echo "-------------------------------------------------------------------" + for file in ${{ steps.changed-files.outputs.all_changed_files }}; do + echo " - ${file} was changed" + done + echo "" + if [ "${{ steps.changed-files.outputs.any_changed }}" ]; then + echo "run-tests=true" >> "${GITHUB_OUTPUT}" + echo "Executing fsnetman tests...." + else + echo ">> No relevant files are changed. No need to run fsnetman tests" + fi + + - name: Checkout Code + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + if: ${{ steps.check-changed-files.outputs.run-tests && !cancelled() && !failure() }} + with: + # the fetch depth defaults to only the commit that triggered the workflow unless the spotless check was enabled + fetch-depth: ${{ inputs.enable-spotless-check && '0' || '' }} + + - name: Setup Node + uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0 + if: ${{ steps.check-changed-files.outputs.run-tests && !cancelled() && !failure() }} + with: + node-version: ${{ inputs.node-version }} + + - name: Setup Kind + uses: helm/kind-action@dda0770415bac9fc20092cacbc54aa298604d140 # v1.8.0 + if: ${{ steps.check-changed-files.outputs.run-tests && !cancelled() && !failure() }} + with: + config: dev/dev-cluster.yaml + version: v0.19.0 + verbosity: 3 + wait: 120s + + - name: Setup Helm + uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 # v3.5 + if: ${{ steps.check-changed-files.outputs.run-tests && !cancelled() && !failure() }} + with: + version: "v3.12.3" # helm version + + # Technically, this step is not required for the unit tests to run, but it is useful for debugging setup issues. + - name: Kubernetes Cluster Info + if: ${{ steps.check-changed-files.outputs.run-tests && !cancelled() && !failure() }} + run: | + kubectl config get-contexts + kubectl get crd + kubectl get node --show-labels + + - name: NodeJS CLI Unit Tests + id: nodejs-test + working-directory: fullstack-network-manager + if: ${{ steps.check-changed-files.outputs.run-tests && !cancelled() && !failure() }} + run: | + which npm + which bash + npm -v + npm i + npm test + + - name: NodeJS CLI E2E Tests + id: nodejs-test-e2e + working-directory: fullstack-network-manager + if: ${{ steps.check-changed-files.outputs.run-tests && !cancelled() && !failure() }} + run: | + export DEV_MODE=true + npm i + npm link + fsnetman init -d ../charts + fsnetman cluster create + fsnetman cluster setup + fsnetman chart install + npm run test-e2e diff --git a/.github/workflows/zxc-helm-chart-tests.yaml b/.github/workflows/zxc-helm-chart-tests.yaml new file mode 100644 index 000000000..fa87f2089 --- /dev/null +++ b/.github/workflows/zxc-helm-chart-tests.yaml @@ -0,0 +1,127 @@ +## +# Copyright (C) 2023 Hedera Hashgraph, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +## + +name: "ZXC: FS Helm Chart Tests" +# The purpose of this reusable workflow is to compile the code and run the unit tests on every PR and commit. +# This reusable component is called by the following workflows: +# - .github/workflows/flow-pull-request-checks.yaml + +on: + workflow_call: + inputs: + custom-job-label: + description: "Custom Job Label:" + type: string + required: false + default: "Helm Chart Test" + +defaults: + run: + shell: bash + +permissions: + id-token: write + contents: read + actions: read + pull-requests: write + checks: write + statuses: write + +jobs: + test: + name: ${{ inputs.custom-job-label || 'Helm Chart Test' }} (${{ matrix.scriptName }}) + runs-on: [self-hosted, Linux, medium, ephemeral] + strategy: + fail-fast: false + matrix: + # direct-install.sh uses ubi8-init-java17 image + # nmt-install.sh uses ubi8-init-dind image + scriptName: [ direct-install.sh, nmt-install.sh ] + steps: + - name: Get changed files related to charts + id: changed-files + uses: tj-actions/changed-files@25ef3926d147cd02fc7e931c1ef50772bbb0d25d #v40.1.1 + with: + files: | + chart: + - charts/** + scripts: + - dev/** + + - name: List all changed files related to charts + id: check-changed-files + run: | + echo "Modified charts files" + echo "-------------------------------------------------------------------" + for file in ${{ steps.changed-files.outputs.chart_all_changed_files }}; do + echo " - ${file} was changed" + done + echo "" + echo "Modified script files" + echo "-------------------------------------------------------------------" + for file in ${{ steps.changed-files.outputs.script_all_changed_files }}; do + echo " - ${file} was changed" + done + echo "" + if [ "${{ steps.changed-files.outputs.scripts_any_changed }}" ] || [ "${{ steps.changed-files.outputs.scripts_any_changed }}" ]; then + echo "run-tests=true" >> "${GITHUB_OUTPUT}" + echo "Executing helm chart tests...." + else + echo ">> No relevant files are changed. No need to run helm chart tests" + fi + + - name: Initialize Job Variables + id: vars + if: ${{ steps.check-changed-files.outputs.run-tests && !cancelled() && !failure() }} + run: | + echo "script_name=${{ matrix.scriptName }}" >> "${GITHUB_OUTPUT}" + + - name: Checkout Code + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + if: ${{ steps.check-changed-files.outputs.run-tests && !cancelled() && !failure() }} + with: + # the fetch depth defaults to only the commit that triggered the workflow unless the spotless check was enabled + fetch-depth: ${{ inputs.enable-spotless-check && '0' || '' }} + + - name: Setup Kind + uses: helm/kind-action@dda0770415bac9fc20092cacbc54aa298604d140 # v1.8.0 + if: ${{ steps.check-changed-files.outputs.run-tests && !cancelled() && !failure() }} + with: + config: dev/dev-cluster.yaml + version: v0.19.0 + verbosity: 3 + wait: 120s + + - name: Setup Helm + uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 # v3.5 + if: ${{ steps.check-changed-files.outputs.run-tests && !cancelled() && !failure() }} + with: + version: "v3.12.3" # helm version + + # Technically, this step is not required for the unit tests to run, but it is useful for debugging setup issues. + - name: Kubernetes Cluster Info + if: ${{ steps.check-changed-files.outputs.run-tests && !cancelled() && !failure() }} + run: | + kubectl config get-contexts + kubectl get crd + kubectl get node --show-labels + + - name: Helm Chart Test + working-directory: dev + if: ${{ steps.check-changed-files.outputs.run-tests && !cancelled() && !failure() }} + run: | + echo "Running test with SCRIPT_NAME=${{ steps.vars.outputs.script_name}}" + make ci-test SCRIPT_NAME="${{ steps.vars.outputs.script_name}}" diff --git a/.gitignore b/.gitignore index b8bbc7d98..4a91b2ba8 100644 --- a/.gitignore +++ b/.gitignore @@ -515,3 +515,4 @@ dev/temp/.env charts/deleteme.yaml node_modules fullstack-network-manager/coverage +dev/resources/nmt/version.properties diff --git a/dev/scripts/env.sh b/dev/scripts/env.sh index c0a883295..2e0637b4c 100644 --- a/dev/scripts/env.sh +++ b/dev/scripts/env.sh @@ -74,9 +74,32 @@ function setup() { load_env_file } +function parse_minor_version() { + local platform_version="$1" + IFS=. read -a VERSION_PARTS <<< "$platform_version" + local minor_version=${VERSION_PARTS[1]} + echo "${minor_version}" +} + +function parse_release_dir() { + local platform_version="$1" + IFS=. read -a VERSION_PARTS <<< "$platform_version" + local release_dir="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}" + echo "${release_dir}" +} + +function prepare_platform_software_URL() { + local platform_version="$1" + local release_dir=$(parse_release_dir "${platform_version}") + + # https://builds.hedera.com/node/software/v0.40/build-v0.40.0.zip + local platform_url="https://builds.hedera.com/node/software/${release_dir}/build-${platform_version}.zip" + echo "${platform_url}" +} + + # ----------------------------- Setup ENV Variables ------------------------------------------------------------- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" -readonly SCRIPT_DIR readonly TMP_DIR="${SCRIPT_DIR}/../temp" readonly CLUSTER_SETUP_VALUES_FILE="${TMP_DIR}/cluster-values.yaml" load_env_file diff --git a/dev/scripts/helper.sh b/dev/scripts/helper.sh index 1478bf194..dcd1dcfed 100755 --- a/dev/scripts/helper.sh +++ b/dev/scripts/helper.sh @@ -2,11 +2,6 @@ CUR_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" source "${CUR_DIR}/env.sh" -start_time=$(date +%s) -TMP_DIR="${SCRIPT_DIR}/../temp" - -readonly start_time TMP_DIR - # load .env file set -a # shellcheck source=./../temp/.env @@ -33,9 +28,11 @@ readonly NMT_INSTALLER_PATH="${NMT_INSTALLER_DIR}/${NMT_INSTALLER}" readonly NMT_PROFILE="jrs" # we only allow jrs profile readonly PLATFORM_VERSION="${PLATFORM_VERSION:-v0.39.1}" +readonly MINOR_VERSION=$(parse_minor_version "${PLATFORM_VERSION}") readonly PLATFORM_INSTALLER="build-${PLATFORM_VERSION}.zip" readonly PLATFORM_INSTALLER_DIR="${SCRIPT_DIR}/../resources/platform" readonly PLATFORM_INSTALLER_PATH="${PLATFORM_INSTALLER_DIR}/${PLATFORM_INSTALLER}" +readonly PLATFORM_INSTALLER_URL=$(prepare_platform_software_URL "${PLATFORM_VERSION}") readonly OPENJDK_VERSION="${OPENJDK_VERSION:-17.0.2}" @@ -63,28 +60,30 @@ function fetch_nmt() { return "${EX_OK}" fi - # echo "NMT Release URL: ${NMT_RELEASE_URL}" - # NMT_DOWNLOAD_URL=$(curl -sL \ - # -H "Accept: application/vnd.github+json" \ - # -H "Authorization: Bearer ${GITHUB_TOKEN}"\ - # -H "X-GitHub-Api-Version: 2022-11-28" \ - # "${NMT_RELEASE_URL}" | jq ".assets[0] | .url" | sed 's/\"//g') - # echo "NMT Download URL: ${NMT_DOWNLOAD_URL}" - # echo "Downloading NMT..." - # curl -L \ - # -H 'Accept: application/octet-stream' \ - # -H "Authorization: Bearer ${GITHUB_TOKEN}"\ - # -H "X-GitHub-Api-Version: 2022-11-28" \ - # "${NMT_DOWNLOAD_URL}" -o "${NMT_INSTALLER_PATH}" || return "${EX_ERR}" - - gsutil cp "gs://fst-resources/nmt/${NMT_INSTALLER}" "${NMT_INSTALLER_PATH}" || return "${EX_ERR}" + mkdir -p "${NMT_INSTALLER_DIR}" + + # fetch nmt version.properties file to find the actual release file name + local release_dir=$(parse_release_dir "${NMT_VERSION}") + local nmt_version_url="https://builds.hedera.com/node/mgmt-tools/${release_dir}/version.properties" + echo "NMT version.properties URL: ${nmt_version_url}" + curl -L "${nmt_version_url}" -o "${NMT_INSTALLER_DIR}/version.properties" || return "${EX_ERR}" + cat "${NMT_INSTALLER_DIR}/version.properties" + + # parse version.properties file to determine the actual URL + local nmt_release_file=$(grep "^${NMT_VERSION}" "${NMT_INSTALLER_DIR}/version.properties"|cut -d'=' -f2) + local nmt_release_url="https://builds.hedera.com/node/mgmt-tools/${release_dir}/${nmt_release_file}" + echo "NMT release URL: ${nmt_release_url}" + curl -L "${nmt_release_url}" -o "${NMT_INSTALLER_PATH}" || return "${EX_ERR}" + ls -la "${NMT_INSTALLER_DIR}" + return "${EX_OK}" } # Fetch platform build.zip file function fetch_platform_build() { echo "" - echo "Fetching Platform ${PLATFORM_VERSION}" + echo "Fetching Platform ${PLATFORM_VERSION}: ${PLATFORM_INSTALLER_URL}" + echo "Local path: ${PLATFORM_INSTALLER_PATH}" echo "-----------------------------------------------------------------------------------------------------" if [[ -f "${PLATFORM_INSTALLER_PATH}" ]]; then @@ -92,7 +91,8 @@ function fetch_platform_build() { return "${EX_OK}" fi - gsutil cp "gs://fst-resources/platform/${PLATFORM_INSTALLER}" "${PLATFORM_INSTALLER_PATH}" || return "${EX_ERR}" + mkdir -p "${PLATFORM_INSTALLER_DIR}" + curl -L "${PLATFORM_INSTALLER_URL}" -o "${PLATFORM_INSTALLER_PATH}" || return "${EX_ERR}" return "${EX_OK}" } @@ -285,16 +285,12 @@ function copy_node_keys() { # prepare address book using all nodes pod IP and store as config.txt function prep_address_book() { - IFS=. read -a VERSION_PARTS <<< "$PLATFORM_VERSION" - local MINOR_VERSION=${VERSION_PARTS[1]} - echo "" echo "Preparing address book" - echo "PLATFORM_VERSION [ MAJOR: ${VERSION_PARTS[0]}, MINOR=${VERSION_PARTS[1]}, PATCH=${VERSION_PARTS[2]} ]" + echo "Platform version: ${PLATFORM_VERSION}" + echo "Minor version: ${MINOR_VERSION}" echo "-----------------------------------------------------------------------------------------------------" - - local config_file="${TMP_DIR}/config.txt" local node_IP="" local node_seq="${NODE_SEQ:-0}" # this also used as the account ID suffix @@ -434,6 +430,12 @@ function copy_config_files() { copy_files "${pod}" "${srcDir}" "${file}" "${dstDir}" || return "${EX_ERR}" done + # create gc.log file since otherwise node doesn't start when using older NMT releases (e.g. v1.2.2) + "${KCTL}" exec "${pod}" -c root-container -- touch "${HAPI_PATH}/gc.log" || return "${EX_ERR}" + set_permission "${pod}" "${HAPI_PATH}/gc.log" + + + return "${EX_OK}" } diff --git a/dev/scripts/template.env b/dev/scripts/template.env index 2918787ed..c78e9e3b5 100644 --- a/dev/scripts/template.env +++ b/dev/scripts/template.env @@ -2,8 +2,8 @@ USER="${USER:-changeme}" CLUSTER_NAME="${CLUSTER_NAME:-fst}" NAMESPACE="${NAMESPACE:-fst-${USER}}" RELEASE_NAME="${RELEASE_NAME:-fst}" -NMT_VERSION=v2.0.0-alpha.0 -PLATFORM_VERSION=v0.39.1 +NMT_VERSION=v1.2.2 +PLATFORM_VERSION=v0.42.5 POD_MONITOR_ROLE="${POD_MONITOR_ROLE:-pod-monitor-role}" GATEWAY_CLASS_NAME="${GATEWAY_CLASS_NAME:-fst-gateway-class}" diff --git a/fullstack-network-manager/README.md b/fullstack-network-manager/README.md index 074283a4f..e96bfbf7c 100644 --- a/fullstack-network-manager/README.md +++ b/fullstack-network-manager/README.md @@ -1,6 +1,6 @@ -# fullstack-network-manager CLI +# Full Stack Network Manager CLI -fullstack-network-manager is a CLI tool to manage and deploy a Hedera Network using Helm chart for local testing. +Full Stack Network Manager (fsnetman) is a CLI tool to manage and deploy a Hedera Network using the FS Helm Chart. ## Install