Skip to content

Commit

Permalink
feat: CI - Added GH action for basic operations on athens3 validator …
Browse files Browse the repository at this point in the history
…nodes (zeta-chain#705)

* Added action for basic operations on athens3 nodes

* Updated workflow name
  • Loading branch information
CharlieMc0 authored Jun 15, 2023
1 parent 33130b2 commit 486d150
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ inputs:
description: "Skip Docker Compose installation"
required: false
default: "false"
skip_go:
description: "Skip Go installation"
required: false
default: "false"

runs:
using: "composite"
steps:
- uses: actions/checkout@v3

- uses: actions/setup-go@v4
if: ${{ inputs.skip_go == 'false' }}
with:
go-version: '1.19.0'
cache: false
Expand All @@ -47,6 +52,7 @@ runs:

- name: Dependencies.
shell: bash
if: ${{ inputs.skip_docker_compose == 'false' }}
run: |
sudo apt-get update
sudo apt-get install wget jq -y
Expand Down
79 changes: 79 additions & 0 deletions .github/actions/node-operations/functions
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash

function set_regions() {
export regions=(
"us-east-1"
"us-west-2"
"eu-west-1"
"ap-southeast-1"
)
}

function stop_zetavisor() {
COMMAND_ID=$(aws ssm send-command \
--targets Key=tag:configured-by,Values=ansible \
--document-name "AWS-RunShellScript" \
--parameters 'commands=["systemctl stop zetavisor"]' \
--region "$1" | jq .Command.CommandId -r || exit 1)
echo "$COMMAND_ID"
}

function stop_zetaclient() {
COMMAND_ID=$(aws ssm send-command \
--targets Key=tag:Role,Values=validator \
--document-name "AWS-RunShellScript" \
--parameters 'commands=["systemctl stop zetaclientd"]' \
--region "$1" | jq .Command.CommandId -r || exit 1)
echo "$COMMAND_ID"
}

function restart_zetavisor() {
COMMAND_ID=$(aws ssm send-command \
--targets Key=tag:configured-by,Values=ansible \
--document-name "AWS-RunShellScript" \
--parameters 'commands=["systemctl restart zetavisor"]' \
--region "$1" | jq .Command.CommandId -r || exit 1)
echo "$COMMAND_ID"
}

function restart_zetaclient() {
COMMAND_ID=$(aws ssm send-command \
--targets Key=tag:Role,Values=validator \
--document-name "AWS-RunShellScript" \
--parameters 'commands=["systemctl restart zetaclientd"]' \
--region "$1" | jq .Command.CommandId -r || exit 1)
echo "$COMMAND_ID"
}

function delete_zetaclient_db() {
COMMAND_ID=$(aws ssm send-command \
--targets Key=tag:Role,Values=validator \
--document-name "AWS-RunShellScript" \
--parameters 'commands=["rm -rf /home/zetachain/.zetaclient/*"]' \
--region "$1" | jq .Command.CommandId -r || exit 1)
echo "$COMMAND_ID"
}

function unjail_validators() {
COMMAND_ID=$(aws ssm send-command \
--targets Key=tag:Role,Values=validator \
--document-name "AWS-RunShellScript" \
--parameters "commands=['export HOME=/home/zetachain && zetacored tx slashing unjail --chain-id athens_7001-1 --from operator -y']" \
--region "$1" | jq .Command.CommandId -r || exit 1)
echo "$COMMAND_ID"
}

check_cmd_status() {
COMMAND_ID=$1
echo "COMMAND_ID: $COMMAND_ID"
COMMAND_STATUS=$(aws ssm list-commands --command-id "$COMMAND_ID" | jq '.Commands[0].Status' -r)
until [[ "$COMMAND_STATUS" == "Success" || "$COMMAND_STATUS" == "Failed" ]]; do
echo "Waiting for Command to complete. ID: $COMMAND_ID | Status: $COMMAND_STATUS"
sleep 2
COMMAND_STATUS=$(aws ssm list-commands --command-id "$COMMAND_ID" | jq '.Commands[0].Status' -r)
done
echo "Complete. ID: $COMMAND_ID | Status: $COMMAND_STATUS"
if [ "$COMMAND_STATUS" == "Failed" ]; then
echo "Command ID $COMMAND_ID Failed" && exit 1
fi
}
99 changes: 99 additions & 0 deletions .github/workflows/node-operations-athens3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Node Operations - Athens 3
on:
workflow_dispatch:
inputs:
ZETACORED_STATUS:
description: "Do you want to stop, or restart zetacored?"
type: choice
options:
- "stop"
- "restart"
required: true
ZETACLIENTD_STATUS:
description: "Do you want to stop, or restart zetaclientd?"
type: choice
options:
- "stop"
- "restart"
required: true
DELETE_ZETACLIENT_DB:
description: "Which environment to update?"
type: environment
required: true
# ENVIRONMENT:
# description: "Which environment to update?"
# type: environment
# required: true

env:
AWS_REGION: "us-east-1"

jobs:
start-stop-processes:
runs-on: ubuntu-latest
# environment: ${{ github.event.inputs.ENVIRONMENT }}
environment: athens3-validators

steps:
- uses: actions/checkout@v3

- name: Install Pipeline Dependencies
uses: ./.github/actions/install-dependencies
with:
skip_python: "true"
skip_docker_compose: "true"
skip_go: "true"
# cpu_architecture: "arm64"

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Stop zetacored
if: ${{ github.event.inputs.ZETACORED_STATUS == 'stop' }}
run: |
source .github/actions/node-operations/functions
set_regions
for region in "${regions[@]}"; do
stop_zetavisor "$region"
done
- name: Restart zetacored
if: ${{ github.event.inputs.ZETACORED_STATUS == 'restart' }}
run: |
source .github/actions/node-operations/functions
set_regions
for region in "${regions[@]}"; do
restart_zetavisor "$region"
done
- name: Stop zetaclientd
if: ${{ github.event.inputs.ZETACORED_STATUS == 'stop' }}
run: |
source .github/actions/node-operations/functions
set_regions
for region in "${regions[@]}"; do
stop_zetaclient "$region"
done
- name: Delete zetaclientd db (/home/zetachain/.zetaclient/*)
if: ${{ github.event.inputs.DELETE_ZETACLIENT_DB == 'true' }}
run: |
source .github/actions/node-operations/functions
set_regions
for region in "${regions[@]}"; do
echo "Deleting zetaclient db in $region"
delete_zetaclient_db "$region"
done
- name: Restart zetaclientd
if: ${{ github.event.inputs.ZETACORED_STATUS == 'restart' }}
run: |
source .github/actions/node-operations/functions
set_regions
for region in "${regions[@]}"; do
restart_zetaclient "$region"
done

0 comments on commit 486d150

Please sign in to comment.