From 40775cacc48f166cc501ad214ea24764a259bd4f Mon Sep 17 00:00:00 2001 From: Mikolaj Gasior Date: Fri, 26 Jan 2024 21:59:26 +0100 Subject: [PATCH] Extract updating featurenet to separate action and workflow --- .github/workflows/_featurenet-create.yml | 12 +-- .github/workflows/_featurenet-update.yml | 101 ++++++++++++++++++ create-featurenet/action.yml | 9 +- update-featurenet/action.yml | 126 +++++++++++++++++++++++ 4 files changed, 231 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/_featurenet-update.yml create mode 100644 update-featurenet/action.yml diff --git a/.github/workflows/_featurenet-create.yml b/.github/workflows/_featurenet-create.yml index 9d9866c..d09910d 100644 --- a/.github/workflows/_featurenet-create.yml +++ b/.github/workflows/_featurenet-create.yml @@ -45,13 +45,6 @@ on: type: string required: false default: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY' - update: - description: | - Perform update instead of create, and do not change values of validators, expiration, - internal and sudo-account-id - required: false - type: boolean - default: false outputs: ws-hostname: description: Hostname of the WS endpoint @@ -122,8 +115,8 @@ jobs: override: true debug: true - - name: Upsert featurenet with image tag - uses: Cardinal-Cryptography/github-actions/create-featurenet@v6 + - name: Create featurenet with image tag + uses: Cardinal-Cryptography/github-actions/create-featurenet@A0-3761-tweak-naming-for-more-clarity id: create-featurenet with: gh-ci-user: ${{ secrets.CI_GH_USER }} @@ -140,7 +133,6 @@ jobs: git-commit-email: ${{ secrets.AUTOCOMMIT_EMAIL }} wait-for-finalized-heads: "true" sudo-account-id: ${{ inputs.sudo-account-id }} - update: ${{ inputs.update && 'true' || 'false' }} - name: Finish featurenet Deployment uses: bobheadxi/deployments@v1 diff --git a/.github/workflows/_featurenet-update.yml b/.github/workflows/_featurenet-update.yml new file mode 100644 index 0000000..e34c151 --- /dev/null +++ b/.github/workflows/_featurenet-update.yml @@ -0,0 +1,101 @@ +--- +name: FE - Create + +on: + workflow_call: + inputs: + featurenet-name: + description: 'Name of the featurenet' + required: true + type: string + aleph-node-image: + description: "FQDN of aleph-node image" + required: true + type: string + rolling-update-partition: + description: | + Number from 0 to N-1, where N is size of am existing featurenet. + All aleph-node-validator-N with an ordinal N that is great than or equal to the partition + will be updated. If not specified, all nodes will be updated. + required: false + default: '0' + type: string + outputs: + ws-hostname: + description: Hostname of the WS endpoint + value: ${{ jobs.create-featurenet.outputs.ws-hostname }} + +jobs: + validate-inputs: + name: Validate inputs + runs-on: ubuntu-20.04 + steps: + - name: Validate inputs + shell: bash + # yamllint disable rule:line-length + run: | + if [[ ! '${{ inputs.featurenet-name }}' =~ ^[a-z0-9][a-z0-9\-]{4,48}$ ]] + then + echo '!!! Invalid featurenet name' + exit 1 + fi + if [[ ! '${{ inputs.aleph-node-image }}' =~ ^[a-z0-9][a-z0-9\._:/\-]{1,52}$ ]]; then + echo "!!! Invalid aleph-node image" + exit 1 + fi + # yamllint enable rule:line-length + + check-vars-and-secrets: + needs: [validate-inputs] + name: Check vars and secrets + uses: ./.github/workflows/_check-vars-and-secrets.yml + secrets: inherit + + create-featurenet: + needs: [check-vars-and-secrets] + name: Create featurenet + runs-on: [self-hosted, Linux, X64, small] + outputs: + deployment-id: ${{ steps.deployment.outputs.deployment_id }} + ws-hostname: ${{ steps.create-featurenet.outputs.ws-hostname }} + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Start featurenet Deployment + uses: bobheadxi/deployments@v1.1.0 + id: deployment + with: + step: start + token: ${{ secrets.CI_GH_TOKEN }} + env: ${{ inputs.featurenet-name }} + override: true + debug: true + + - name: Update featurenet with image tag + uses: Cardinal-Cryptography/github-actions/update-featurenet@A0-3761-tweak-naming-for-more-clarity + id: create-featurenet + with: + gh-ci-user: ${{ secrets.CI_GH_USER }} + gh-ci-token: ${{ secrets.CI_GH_TOKEN }} + argo-sync-user-token: ${{ secrets.ARGO_SYNC_USER_TOKEN }} + repo-featurenet-template-name: ${{ secrets.REPO_FEATURENET_TEMPLATE_NAME }} + featurenet-name: ${{ inputs.featurenet-name }} + featurenet-aleph-node-image: ${{ inputs.aleph-node-image }} + rolling-update-partition: ${{ inputs.rolling-update-partition }} + git-commit-author: ${{ secrets.AUTOCOMMIT_AUTHOR }} + git-commit-email: ${{ secrets.AUTOCOMMIT_EMAIL }} + wait-for-finalized-heads: "true" + + - name: Finish featurenet Deployment + uses: bobheadxi/deployments@v1 + if: always() + with: + step: finish + token: ${{ secrets.CI_GH_TOKEN }} + status: ${{ job.status }} + env: ${{ inputs.featurenet-name }} + deployment_id: ${{ steps.deployment.outputs.deployment_id }} + # yamllint disable-line rule:line-length + env_url: https://dev.azero.dev/?rpc=wss%3A%2F%2F${{ steps.create-featurenet.outputs.ws-hostname }}#/explorer + debug: true diff --git a/create-featurenet/action.yml b/create-featurenet/action.yml index ce1cf52..1104951 100644 --- a/create-featurenet/action.yml +++ b/create-featurenet/action.yml @@ -59,10 +59,6 @@ inputs: description: 'Sudo account ID' required: false default: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY' - update: - description: 'Perform update instead of create, and do not change values of validators, expiration, internal and sudo-account-id' - required: false - default: "false" outputs: ws-hostname: description: Hostname of the WS endpoint @@ -124,7 +120,7 @@ runs: repository: Cardinal-Cryptography/${{ inputs.repo-featurenet-template-name }} token: ${{ inputs.gh-ci-token }} path: "${{ inputs.repo-featurenet-template-name }}" - ref: main + ref: A0-3761-tweak-naming-for-more-clarity - name: Start featurenet id: start-featurenet @@ -138,7 +134,7 @@ runs: run: | cd '${{ inputs.repo-featurenet-template-name }}' - ./create-featurenet.sh \ + ./upsert-featurenet.sh \ '${{ inputs.featurenet-name }}' \ '${{ inputs.featurenet-aleph-node-image }}' \ '${{ inputs.validators }}' \ @@ -146,7 +142,6 @@ runs: '${{ inputs.expiration }}' \ '${{ inputs.sudo-account-id }}' \ ${{ inputs.internal == 'true' && '-i' || '' }} \ - ${{ inputs.update == 'true' && '-u' || '' }} \ -c -g | tee -a tmp-opssh-createfeaturenet-output.txt ws_hostname=$(cat tmp-opssh-createfeaturenet-output.txt | grep '^__output:ws-hostname:' | cut -d: -f3) diff --git a/update-featurenet/action.yml b/update-featurenet/action.yml new file mode 100644 index 0000000..b55d10f --- /dev/null +++ b/update-featurenet/action.yml @@ -0,0 +1,126 @@ +--- +name: Create featurenet +description: | + This action is used in several dev flows to + * spawn new featurenet from any aleph node git ref, + * update binary in the existing featurenet, + * update rolling partition in the existing featurenet, +inputs: + gh-ci-user: + description: 'GH user to be used in the action' + required: true + gh-ci-token: + description: 'GH token to be used in the action' + required: true + repo-featurenet-template-name: + description: 'Name of the repository containing featurenet template' + required: true + argo-sync-user-token: + description: 'ArgoCD user token to be used in the action' + required: true + featurenet-name: + description: 'Name of featurenet' + required: true + git-commit-author: + description: 'Git commit author when pushing to featurenets repository' + required: true + git-commit-email: + description: 'Git commit email when pushing to featurenets repository' + required: true + featurenet-aleph-node-image: + description: 'aleph-node docker image tag' + required: true + default: '' + rolling-update-partition: + description: | + Number from 0 to N-1, where N is size of am existing featurenet. + All aleph-node-validator-N with an ordinal N that is great than or equal to the partition + will be updated. If not specified, all nodes will be updated. + required: false + default: "0" + wait-for-finalized-heads: + description: 'Wait for heads finalization' + required: false + default: "false" +outputs: + ws-hostname: + description: Hostname of the WS endpoint + value: ${{ steps.start-featurenet.outputs.ws-hostname }} + +runs: + using: "composite" + steps: + - name: Validate inputs + shell: bash + run: | + if [[ + ! '${{ inputs.featurenet-name }}' =~ ^[a-z0-9][a-z0-9\-]{4,48}$ + ]] + then + echo "!!! Invalid featurenet name" + exit 1 + fi + if [[ + ! '${{ inputs.featurenet-aleph-node-image }}' =~ ^[a-z0-9][a-z0-9\._/:\-]{1,52}$ + ]] + then + echo "!!! Invalid featurenet node image tag" + exit 1 + fi + if [[ + '${{ inputs.rolling-update-partition }}' != "" && \ + ! '${{ inputs.rolling-update-partition }}' =~ ^[0-9]$ + ]] + then + echo "!!! Expected rolling update partition to be a cardinal value from 0 to 9" + exit 1 + fi + + - name: Checkout featurenet template repo + uses: actions/checkout@v3 + with: + repository: Cardinal-Cryptography/${{ inputs.repo-featurenet-template-name }} + token: ${{ inputs.gh-ci-token }} + path: "${{ inputs.repo-featurenet-template-name }}" + ref: A0-3761-tweak-naming-for-more-clarity + + - name: Start featurenet + id: start-featurenet + shell: bash + env: + GITHUB_USERNAME: ${{ inputs.gh-ci-user }} + GITHUB_TOKEN: ${{ inputs.gh-ci-token }} + GIT_COMMIT_USER_NAME: ${{ inputs.git-commit-author }} + GIT_COMMIT_USER_EMAIL: ${{ inputs.git-commit-email }} + # yamllint disable rule:line-length + run: | + cd '${{ inputs.repo-featurenet-template-name }}' + + ./upsert-featurenet.sh \ + '${{ inputs.featurenet-name }}' \ + '${{ inputs.featurenet-aleph-node-image }}' \ + 'not-used-because-update' \ + '${{ inputs.rolling-update-partition }}' \ + 'not-used-because-update' \ + 'not-used-because-update' \ + -u \ + -c -g | tee -a tmp-opssh-updatefeaturenet-output.txt + + ws_hostname=$(cat tmp-opssh-updatefeaturenet-output.txt | grep '^__output:ws-hostname:' | cut -d: -f3) + echo "ws-hostname=${ws_hostname}" >> $GITHUB_OUTPUT + # yamllint enable rule:line-length + + - name: Refresh Argo and wait for the creation to be finished + shell: bash + run: | + cd '${{ inputs.repo-featurenet-template-name }}' + + ./refresh-featurenets.sh '${{ inputs.argo-sync-user-token }}' '${{ inputs.featurenet-name }}' + + - name: Wait for the unique consecutive finalized heads + if: inputs.wait-for-finalized-heads == 'true' + shell: bash + run: | + cd '${{ inputs.repo-featurenet-template-name }}' + + ./wait-for-featurenet-finalized-heads.sh '${{ inputs.featurenet-name }}'