Compare commits
67 Commits
main
...
8394a032d5
Author | SHA1 | Date | |
---|---|---|---|
8394a032d5 | |||
63e27f31ac | |||
64d57407e0 | |||
e40e14dea5 | |||
b988582553 | |||
22ce6c07c3 | |||
834ddb4438 | |||
7e8587660d | |||
6b431823f5 | |||
82e6047e86 | |||
15f277057e | |||
04d44aeadf | |||
b006ea31b0 | |||
04efc25a48 | |||
cccbc07db1 | |||
7d5889553d | |||
34776214d6 | |||
0cc12c5446 | |||
57c8b81c13 | |||
382a910856 | |||
a0d2e74115 | |||
c1f23386b5 | |||
e5a0eef020 | |||
c95fce1b69 | |||
cd119be631 | |||
a5a27829de | |||
246e073092 | |||
43dbcd0a17 | |||
c062ad8e66 | |||
da56ef57f0 | |||
b89e6c20ce | |||
b93e5f890a | |||
625a8f71ae | |||
8acb4768e3 | |||
b9d966ff90 | |||
1e38b5aca6 | |||
3abc4e0a81 | |||
49c13d9e42 | |||
4e50ee554b | |||
f5706ac887 | |||
da787935df | |||
77a5f1a071 | |||
8425114abf | |||
92f6cdcd40 | |||
f2cce2f592 | |||
5d8a2cfdd6 | |||
4c0268823b | |||
bbd1de0020 | |||
3a2847295a | |||
671c7a4507 | |||
e0913ece08 | |||
1a775c6b87 | |||
26323e9c41 | |||
a79bdc94d0 | |||
272ee7522b | |||
e85f0b987e | |||
7eab098a99 | |||
c0502193b2 | |||
9be7df6bcf | |||
8183934d09 | |||
1558f60810 | |||
138fcfc321 | |||
153ccfd4db | |||
eaceb3ecfa | |||
c0fd0330af | |||
fc49f06d75 | |||
17702b1396 |
214
checker.py
Normal file
214
checker.py
Normal file
@ -0,0 +1,214 @@
|
||||
# flake8: noqa
|
||||
# pylint: disable=broad-exception-raised, raise-missing-from, too-many-arguments, redefined-outer-name
|
||||
# pylance: disable=reportMissingImports, reportMissingModuleSource, reportGeneralTypeIssues
|
||||
# type: ignore
|
||||
|
||||
import warnings
|
||||
warnings.filterwarnings("ignore", category=Warning)
|
||||
|
||||
import re
|
||||
from datetime import datetime, timedelta, timezone
|
||||
import subprocess
|
||||
import os
|
||||
import time
|
||||
import random
|
||||
import sys
|
||||
import pkg_resources
|
||||
import requests
|
||||
import json
|
||||
from collections import deque
|
||||
|
||||
required_packages = {
|
||||
'grist-api': 'latest',
|
||||
'colorama': 'latest',
|
||||
'requests': '2.31.0',
|
||||
'urllib3': '2.0.7',
|
||||
'charset-normalizer': '3.3.2'
|
||||
}
|
||||
|
||||
installed_packages = {pkg.key: pkg.version for pkg in pkg_resources.working_set}
|
||||
|
||||
for package, version in required_packages.items():
|
||||
if package not in installed_packages or (version != 'latest' and installed_packages[package] != version):
|
||||
if version == 'latest':
|
||||
subprocess.check_call([sys.executable, '-m', 'pip', 'install', package, '--break-system-packages'])
|
||||
else:
|
||||
subprocess.check_call([sys.executable, '-m', 'pip', 'install', f"{package}=={version}", '--break-system-packages'])
|
||||
|
||||
from grist_api import GristDocAPI
|
||||
import colorama
|
||||
|
||||
import logging
|
||||
import socket
|
||||
|
||||
def self_update(logger):
|
||||
logger.info("Checking for updates..")
|
||||
script_path = os.path.abspath(__file__)
|
||||
update_url = "https://gitea.vvzvlad.xyz/vvzvlad/ritual/raw/branch/main-22aug/checker.py"
|
||||
try:
|
||||
response = requests.get(update_url, timeout=10)
|
||||
if response.status_code == 200:
|
||||
current_content = ""
|
||||
with open(script_path, 'r', encoding='utf-8') as f:
|
||||
current_content = f.read()
|
||||
|
||||
if current_content != response.text:
|
||||
with open(script_path, 'w', encoding='utf-8') as f:
|
||||
f.write(response.text)
|
||||
logger.info("Script updated successfully, restarting")
|
||||
os.execv(sys.executable, ['python3'] + sys.argv)
|
||||
else:
|
||||
logger.info("Script is up to date")
|
||||
else:
|
||||
logger.error(f"Failed to download update, status code: {response.status_code}")
|
||||
except Exception as e:
|
||||
logger.error(f"Update error: {str(e)}")
|
||||
|
||||
class GRIST:
|
||||
def __init__(self, server, doc_id, api_key, logger):
|
||||
self.server = server
|
||||
self.doc_id = doc_id
|
||||
self.api_key = api_key
|
||||
self.logger = logger
|
||||
self.grist = GristDocAPI(doc_id, server=server, api_key=api_key)
|
||||
|
||||
def table_name_convert(self, table_name):
|
||||
return table_name.replace(" ", "_")
|
||||
|
||||
def to_timestamp(self, dtime: datetime) -> int:
|
||||
if dtime.tzinfo is None:
|
||||
dtime = dtime.replace(tzinfo=timezone(timedelta(hours=3)))
|
||||
return int(dtime.timestamp())
|
||||
|
||||
def insert_row(self, data, table):
|
||||
data = {key.replace(" ", "_"): value for key, value in data.items()}
|
||||
row_id = self.grist.add_records(self.table_name_convert(table), [data])
|
||||
return row_id
|
||||
|
||||
def update_column(self, row_id, column_name, value, table):
|
||||
if isinstance(value, datetime):
|
||||
value = self.to_timestamp(value)
|
||||
column_name = column_name.replace(" ", "_")
|
||||
self.grist.update_records(self.table_name_convert(table), [{ "id": row_id, column_name: value }])
|
||||
|
||||
def delete_row(self, row_id, table):
|
||||
self.grist.delete_records(self.table_name_convert(table), [row_id])
|
||||
|
||||
def update(self, row_id, updates, table):
|
||||
for column_name, value in updates.items():
|
||||
if isinstance(value, datetime):
|
||||
updates[column_name] = self.to_timestamp(value)
|
||||
updates = {column_name.replace(" ", "_"): value for column_name, value in updates.items()}
|
||||
self.grist.update_records(self.table_name_convert(table), [{"id": row_id, **updates}])
|
||||
|
||||
def fetch_table(self, table):
|
||||
return self.grist.fetch_table(self.table_name_convert(table))
|
||||
|
||||
def find_record(self, id=None, state=None, name=None, table=None):
|
||||
if table is None:
|
||||
raise ValueError("Table is not specified")
|
||||
table_data = self.grist.fetch_table(self.table_name_convert(table))
|
||||
if id is not None:
|
||||
record = [row for row in table_data if row.id == id]
|
||||
return record
|
||||
if state is not None and name is not None:
|
||||
record = [row for row in table_data if row.State == state and row.name == name]
|
||||
return record
|
||||
if state is not None:
|
||||
record = [row for row in table_data if row.State == state]
|
||||
return record
|
||||
if name is not None:
|
||||
record = [row for row in table_data if row.Name == name]
|
||||
return record
|
||||
|
||||
def find_settings(self, key, table):
|
||||
table = self.fetch_table(self.table_name_convert(table))
|
||||
for record in table:
|
||||
if record.Setting == key:
|
||||
if record.Value is None or record.Value == "":
|
||||
raise ValueError(f"Setting {key} blank")
|
||||
return record.Value
|
||||
raise ValueError(f"Setting {key} not found")
|
||||
|
||||
def clean_ansi(text):
|
||||
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
|
||||
return ansi_escape.sub('', text)
|
||||
|
||||
def format_number(number_str):
|
||||
number = int(number_str)
|
||||
if number >= 1000:
|
||||
return f"{number//1000}k"
|
||||
return str(number)
|
||||
|
||||
def check_logs(logger):
|
||||
try:
|
||||
logs = subprocess.run(['docker', 'logs', '--since', '10m', 'infernet-node'], capture_output=True, text=True, check=True)
|
||||
log_content = clean_ansi(logs.stdout)
|
||||
|
||||
last_subscription_id = None
|
||||
head_sub_id = None
|
||||
|
||||
for line in log_content.splitlines():
|
||||
if "Ignored subscription creation" in line and "id=" in line:
|
||||
id_match = re.search(r'id=(\d+)', line)
|
||||
if id_match:
|
||||
last_subscription_id = id_match.group(1)
|
||||
|
||||
if "head sub id is:" in line:
|
||||
id_match = re.search(r'head sub id is:\s*(\d+)', line)
|
||||
if id_match:
|
||||
head_sub_id = id_match.group(1)
|
||||
|
||||
if last_subscription_id:
|
||||
logger.info(f"Subscription: {last_subscription_id}")
|
||||
return {"status": f"Sync: {format_number(last_subscription_id)}"}
|
||||
|
||||
if head_sub_id:
|
||||
logger.info(f"Head sub id: {head_sub_id}")
|
||||
return {"status": f"OK: {head_sub_id}"}
|
||||
|
||||
|
||||
logger.info("Not found subscription")
|
||||
return {"status": "Idle"}
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
raise RuntimeError(f"Error running docker logs: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
colorama.init(autoreset=True)
|
||||
logger = logging.getLogger("Checker")
|
||||
logger.setLevel(logging.INFO)
|
||||
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
||||
ch = logging.StreamHandler()
|
||||
ch.setFormatter(formatter)
|
||||
logger.addHandler(ch)
|
||||
|
||||
logger.info("Checker started")
|
||||
self_update(logger)
|
||||
#random_sleep = random.randint(1, 60)
|
||||
#logger.info(f"Sleeping for {random_sleep} seconds")
|
||||
#time.sleep(random_sleep)
|
||||
|
||||
grist_data = {}
|
||||
with open('/root/node/grist.json', 'r', encoding='utf-8') as f:
|
||||
grist_data = json.loads(f.read())
|
||||
|
||||
GRIST_ROW_NAME = socket.gethostname()
|
||||
NODES_TABLE = "Nodes"
|
||||
grist = GRIST(grist_data.get('grist_server'), grist_data.get('grist_doc_id'), grist_data.get('grist_api_key'), logger)
|
||||
current_vm = grist.find_record(name=GRIST_ROW_NAME, table=NODES_TABLE)[0]
|
||||
def grist_callback(msg): grist.update(current_vm.id, msg, NODES_TABLE)
|
||||
|
||||
for attempt in range(3):
|
||||
try:
|
||||
result = check_logs(logger)
|
||||
grist_callback({ "Health": result["status"] })
|
||||
logger.info(f"Status: {result['status']}")
|
||||
break
|
||||
except Exception as e:
|
||||
logger.error(f"Error on attempt {attempt+1}/3: {e}")
|
||||
if attempt == 2:
|
||||
grist_callback({ "Health": f"Error: {e}" })
|
||||
if attempt < 2:
|
||||
time.sleep(5)
|
@ -1,8 +1,6 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
node:
|
||||
image: ritualnetwork/infernet-node:1.2.0
|
||||
image: ritualnetwork/infernet-node:1.4.0
|
||||
ports:
|
||||
- "0.0.0.0:4000:4000"
|
||||
volumes:
|
||||
@ -21,6 +19,11 @@ services:
|
||||
- "host.docker.internal:host-gateway"
|
||||
stop_grace_period: 1m
|
||||
container_name: infernet-node
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-file: 5
|
||||
max-size: 10m
|
||||
|
||||
redis:
|
||||
image: redis:latest
|
||||
@ -33,6 +36,11 @@ services:
|
||||
- redis-data:/data
|
||||
restart:
|
||||
unless-stopped
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-file: 5
|
||||
max-size: 10m
|
||||
|
||||
fluentbit:
|
||||
image: fluent/fluent-bit:latest
|
||||
@ -47,6 +55,11 @@ services:
|
||||
- network
|
||||
restart:
|
||||
unless-stopped
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-file: 5
|
||||
max-size: 10m
|
||||
|
||||
infernet-anvil:
|
||||
image: ritualnetwork/infernet-anvil:1.0.0
|
||||
@ -58,6 +71,11 @@ services:
|
||||
container_name: infernet-anvil
|
||||
restart:
|
||||
unless-stopped
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-file: 5
|
||||
max-size: 10m
|
||||
|
||||
networks:
|
||||
network:
|
||||
|
5
grist.json
Normal file
5
grist.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"grist_server": "###GRIST_SERVER###",
|
||||
"grist_doc_id": "###GRIST_DOC_ID###",
|
||||
"grist_api_key": "###GRIST_API_KEY###"
|
||||
}
|
278
playbook.yml
278
playbook.yml
@ -1,16 +1,48 @@
|
||||
---
|
||||
- name: System Setup and Configuration
|
||||
hosts: all
|
||||
become: yes
|
||||
|
||||
|
||||
become: true
|
||||
|
||||
tasks:
|
||||
- name: Set locale to C.UTF-8
|
||||
command: localectl set-locale LANG=C.UTF-8
|
||||
|
||||
- name: Create APT configuration file to assume yes
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/apt/apt.conf.d/90forceyes
|
||||
content: |
|
||||
APT::Get::Assume-Yes "true";
|
||||
mode: '0644'
|
||||
|
||||
- name: Append command to .bash_history
|
||||
ansible.builtin.blockinfile:
|
||||
path: "~/.bash_history"
|
||||
create: true
|
||||
block: |
|
||||
cd ~/node; bash rebuild.sh
|
||||
nano ~/node/projects/hello-world/container/config.json
|
||||
docker logs infernet-node -f
|
||||
docker logs --since 10m infernet-node -f
|
||||
journalctl -u node-checker.service
|
||||
journalctl -u grpcbalancer.service
|
||||
nano ~/node/deploy/config.json
|
||||
docker compose -f deploy/docker-compose.yaml down; docker compose -f deploy/docker-compose.yaml up -d
|
||||
marker: ""
|
||||
mode: '0644'
|
||||
|
||||
|
||||
- name: Append command to .bash_rc
|
||||
ansible.builtin.blockinfile:
|
||||
path: "~/.bashrc"
|
||||
create: true
|
||||
insertafter: EOF
|
||||
block: |
|
||||
cd /root/node
|
||||
marker: ""
|
||||
mode: '0644'
|
||||
|
||||
- name: Update /etc/bash.bashrc
|
||||
blockinfile:
|
||||
ansible.builtin.blockinfile:
|
||||
path: /etc/bash.bashrc
|
||||
block: |
|
||||
export HISTTIMEFORMAT='%F, %T '
|
||||
@ -23,27 +55,23 @@
|
||||
export LC_ALL=C.UTF-8
|
||||
alias ls='ls --color=auto'
|
||||
shopt -s cmdhist
|
||||
create: true
|
||||
marker: ""
|
||||
mode: '0644'
|
||||
|
||||
- name: Ensure ~/.inputrc exists
|
||||
file:
|
||||
path: /root/.inputrc
|
||||
state: touch
|
||||
|
||||
- name: Update ~/.inputrc
|
||||
blockinfile:
|
||||
path: ~/.inputrc
|
||||
- name: Update .inputrc for the current user
|
||||
ansible.builtin.blockinfile:
|
||||
path: "{{ ansible_env.HOME }}/.inputrc"
|
||||
block: |
|
||||
"\e[A": history-search-backward
|
||||
"\e[B": history-search-forward
|
||||
|
||||
- name: Ensure ~/.nanorc exists
|
||||
file:
|
||||
path: /root/.nanorc
|
||||
state: touch
|
||||
create: true
|
||||
marker: ""
|
||||
mode: '0644'
|
||||
|
||||
- name: Update ~/.nanorc
|
||||
blockinfile:
|
||||
path: ~/.nanorc
|
||||
ansible.builtin.blockinfile:
|
||||
path: "{{ ansible_env.HOME }}/.nanorc"
|
||||
block: |
|
||||
set nohelp
|
||||
set tabsize 4
|
||||
@ -54,24 +82,31 @@
|
||||
set backupdir /tmp/
|
||||
set locking
|
||||
include /usr/share/nano/*.nanorc
|
||||
create: true
|
||||
marker: ""
|
||||
mode: '0644'
|
||||
|
||||
- name: Set hostname
|
||||
shell: |
|
||||
hostnamectl set-hostname {{ serverid }}
|
||||
echo "127.0.1.1 {{ serverid }}" >> /etc/hosts
|
||||
ansible.builtin.hostname:
|
||||
name: "{{ serverid }}"
|
||||
|
||||
- name: Update and upgrade apt
|
||||
apt:
|
||||
update_cache: yes
|
||||
upgrade: dist
|
||||
force_apt_get: yes
|
||||
register: apt_update_result
|
||||
retries: 50
|
||||
delay: 50
|
||||
until: apt_update_result is succeeded
|
||||
- name: Ensure hostname is in /etc/hosts
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/hosts
|
||||
regexp: '^127\.0\.1\.1\s+'
|
||||
line: "127.0.1.1 {{ serverid }}"
|
||||
state: present
|
||||
|
||||
#- name: Update and upgrade apt
|
||||
# ansible.builtin.apt:
|
||||
# update_cache: true
|
||||
# upgrade: dist
|
||||
# force_apt_get: true
|
||||
# register: apt_update_result
|
||||
# until: apt_update_result is success
|
||||
|
||||
- name: Install necessary packages
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name:
|
||||
- apt-transport-https
|
||||
- ca-certificates
|
||||
@ -83,132 +118,151 @@
|
||||
state: present
|
||||
|
||||
- name: Install pip package web3
|
||||
pip:
|
||||
ansible.builtin.pip:
|
||||
name: web3
|
||||
extra_args: --break-system-packages
|
||||
|
||||
- name: Install Docker
|
||||
shell: curl -sL https://get.docker.com | sudo sh -
|
||||
|
||||
- name: Ensure /etc/docker/daemon.json exists
|
||||
file:
|
||||
path: /etc/docker/daemon.json
|
||||
state: touch
|
||||
|
||||
# - name: Install Docker
|
||||
# ansible.builtin.shell: curl -sL https://get.docker.com | sudo sh -
|
||||
#
|
||||
- name: Update Docker daemon configuration for journald logging
|
||||
copy:
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/docker/daemon.json
|
||||
content: |
|
||||
{
|
||||
"log-driver": "journald"
|
||||
"log-driver": "journald",
|
||||
"registry-mirrors": ["https://dockerregistry.vvzvlad.xyz"]
|
||||
}
|
||||
|
||||
- name: Restart Docker
|
||||
service:
|
||||
ansible.builtin.service:
|
||||
name: docker
|
||||
state: restarted
|
||||
|
||||
- name: Docker login
|
||||
shell: docker login -u {{ docker_username }} -p {{ docker_password }}
|
||||
- name: Docker pull hello-world
|
||||
ansible.builtin.shell: docker pull ritualnetwork/hello-world-infernet:latest
|
||||
|
||||
- name: Update journald log SystemMaxUse=2G configuration
|
||||
lineinfile:
|
||||
path: /etc/systemd/journald.conf
|
||||
line: 'SystemMaxUse=2G'
|
||||
insertafter: EOF
|
||||
create: yes
|
||||
|
||||
- name: Restart journald
|
||||
service:
|
||||
name: systemd-journald
|
||||
state: restarted
|
||||
# - name: Update journald log SystemMaxUse=2G configuration
|
||||
# ansible.builtin.lineinfile:
|
||||
# path: /etc/systemd/journald.conf
|
||||
# regexp: '^SystemMaxUse='
|
||||
# line: 'SystemMaxUse=2G'
|
||||
# state: present
|
||||
# backup: yes
|
||||
# validate: 'journaldctl check-config %s'
|
||||
#
|
||||
# - name: Restart journald
|
||||
# ansible.builtin.service:
|
||||
# name: systemd-journald
|
||||
# state: restarted
|
||||
|
||||
- name: Setup Foundry
|
||||
shell: |
|
||||
ansible.builtin.shell: |
|
||||
mkdir -p ~/foundry && cd ~/foundry
|
||||
curl -L https://foundry.paradigm.xyz | bash
|
||||
args:
|
||||
executable: /bin/bash
|
||||
|
||||
- name: Run foundryup
|
||||
shell: |
|
||||
ansible.builtin.shell: |
|
||||
source ~/.bashrc && foundryup
|
||||
args:
|
||||
executable: /bin/bash
|
||||
|
||||
- name: Clone ritual-says-gm repository
|
||||
git:
|
||||
repo: https://gitea.vvzvlad.xyz/vvzvlad/ritual-says-gm.git
|
||||
dest: ~/ritual-says-gm
|
||||
force: yes
|
||||
- name: Clone repository
|
||||
ansible.builtin.git:
|
||||
repo: https://gitea.vvzvlad.xyz/vvzvlad/ritual.git
|
||||
dest: "{{ ansible_env.HOME }}/node"
|
||||
version: "{{ git_version }}"
|
||||
force: true
|
||||
async: "{{ 60 * 15 }}"
|
||||
poll: 30
|
||||
|
||||
- name: Update wallet, private key and RPC URL in project
|
||||
shell: |
|
||||
cd ~/ritual-says-gm
|
||||
bash update.sh {{ wallet }} {{ private_key }} {{ rpc_url }}
|
||||
- name: Update environment variables
|
||||
ansible.builtin.shell: |
|
||||
chmod +x ./update.sh
|
||||
./update.sh ID "{{ serverid }}"
|
||||
./update.sh GRIST_SERVER "{{ grist_server }}"
|
||||
./update.sh GRIST_DOC_ID "{{ grist_doc_id }}"
|
||||
./update.sh GRIST_API_KEY "{{ grist_api_key }}"
|
||||
./update.sh WALLET_ADDRESS "{{ wallet }}"
|
||||
./update.sh PRIVATE_KEY "{{ private_key }}"
|
||||
./update.sh RPC_URL "{{ rpc_url }}"
|
||||
args:
|
||||
chdir: "{{ ansible_env.HOME }}/node"
|
||||
changed_when: false
|
||||
|
||||
- name: Remove old Forge and Infernet SDK
|
||||
shell: |
|
||||
cd ~/ritual-says-gm
|
||||
rm -rf projects/hello-world/contracts/lib/forge-std
|
||||
rm -rf projects/hello-world/contracts/lib/infernet-sdk
|
||||
|
||||
- name: Install Forge and Infernet SDK
|
||||
shell: |
|
||||
cd ~/foundry && source ~/.bashrc && foundryup
|
||||
cd ~/ritual-says-gm
|
||||
cd projects/hello-world/contracts
|
||||
ansible.builtin.shell: |
|
||||
rm -rf {{ ansible_env.HOME }}/node/projects/hello-world/contracts/lib/forge-std
|
||||
rm -rf {{ ansible_env.HOME }}/node/projects/hello-world/contracts/lib/infernet-sdk
|
||||
cd {{ ansible_env.HOME }}/foundry && source {{ ansible_env.HOME }}/.bashrc && foundryup
|
||||
cd {{ ansible_env.HOME }}/node/projects/hello-world/contracts
|
||||
forge install --no-commit foundry-rs/forge-std
|
||||
forge install --no-commit ritual-net/infernet-sdk
|
||||
args:
|
||||
executable: /bin/bash
|
||||
|
||||
- name: Deploy container
|
||||
shell: |
|
||||
cd ~/ritual-says-gm && project=hello-world make deploy-container
|
||||
ansible.builtin.shell: project=hello-world make deploy-container
|
||||
args:
|
||||
chdir: "{{ ansible_env.HOME }}/node"
|
||||
|
||||
- name: Deploy contracts
|
||||
shell: cd ~/ritual-says-gm && project=hello-world make deploy-contracts 2>&1
|
||||
ansible.builtin.shell: project=hello-world make deploy-contracts 2>&1
|
||||
register: contract_deploy_output
|
||||
ignore_errors: yes
|
||||
retries: 3
|
||||
delay: 53
|
||||
args:
|
||||
chdir: "{{ ansible_env.HOME }}/node"
|
||||
executable: /bin/bash
|
||||
retries: 5
|
||||
delay: 120
|
||||
async: 120
|
||||
poll: 30
|
||||
until: '"ONCHAIN EXECUTION COMPLETE & SUCCESSFUL" in contract_deploy_output.stdout'
|
||||
failed_when: false
|
||||
|
||||
- name: Update CallContract.s.sol with contract address
|
||||
shell: |
|
||||
cd ~/ritual-says-gm
|
||||
contract_address=$(jq -r '.transactions[0].contractAddress' projects/hello-world/contracts/broadcast/Deploy.s.sol/8453/run-latest.json)
|
||||
checksum_address=$(python3 toChecksumAddress.py $contract_address)
|
||||
sed -i "s/SaysGM(.*/SaysGM($checksum_address);/" projects/hello-world/contracts/script/CallContract.s.sol
|
||||
ansible.builtin.shell: bash update_contracts.sh
|
||||
args:
|
||||
chdir: "{{ ansible_env.HOME }}/node"
|
||||
|
||||
- name: Call contract
|
||||
shell: cd ~/ritual-says-gm && project=hello-world make call-contract 2>&1
|
||||
register: contract_output
|
||||
ignore_errors: yes
|
||||
retries: 3
|
||||
delay: 55
|
||||
until: '"ONCHAIN EXECUTION COMPLETE & SUCCESSFUL" in contract_output.stdout'
|
||||
ansible.builtin.shell: project=hello-world make call-contract 2>&1
|
||||
register: contract_call_output
|
||||
args:
|
||||
chdir: "{{ ansible_env.HOME }}/node"
|
||||
executable: /bin/bash
|
||||
retries: 5
|
||||
delay: 120
|
||||
async: 120
|
||||
poll: 30
|
||||
until: '"ONCHAIN EXECUTION COMPLETE & SUCCESSFUL" in contract_call_output.stdout'
|
||||
failed_when: false
|
||||
|
||||
- name: Set Docker containers to restart unless stopped
|
||||
shell: |
|
||||
docker update --restart unless-stopped hello-world
|
||||
docker update --restart unless-stopped infernet-node
|
||||
docker update --restart unless-stopped deploy-redis-1
|
||||
docker update --restart unless-stopped infernet-anvil
|
||||
docker update --restart unless-stopped deploy-fluentbit-1
|
||||
|
||||
- name: Create APT configuration file to assume yes
|
||||
copy:
|
||||
dest: /etc/apt/apt.conf.d/90forceyes
|
||||
- name: Copy checker service file
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/systemd/system/node-checker.service
|
||||
content: |
|
||||
APT::Get::Assume-Yes "true";
|
||||
[Unit]
|
||||
Description=Node Checker Service
|
||||
After=network.target
|
||||
|
||||
- name: Set permissions on APT configuration file
|
||||
file:
|
||||
path: /etc/apt/apt.conf.d/90forceyes
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
WorkingDirectory={{ ansible_env.HOME }}/node
|
||||
ExecStart=/usr/bin/python3 {{ ansible_env.HOME }}/node/checker.py
|
||||
Restart=always
|
||||
RestartSec=600
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
mode: '0644'
|
||||
|
||||
- name: Remove docker login credentials
|
||||
shell: rm -rf /root/.docker/config.json
|
||||
ignore_errors: yes
|
||||
- name: Enable and start node-checker service
|
||||
ansible.builtin.systemd:
|
||||
name: node-checker
|
||||
enabled: yes
|
||||
state: started
|
||||
daemon_reload: yes
|
||||
|
@ -5,29 +5,27 @@
|
||||
},
|
||||
"chain": {
|
||||
"enabled": true,
|
||||
"trail_head_blocks": 0,
|
||||
"trail_head_blocks": 3,
|
||||
"rpc_url": "###RPC_URL###",
|
||||
"registry_address": "0x3B1554f346DFe5c482Bb4BA31b880c1C18412170",
|
||||
"wallet": {
|
||||
"max_gas_limit": 4000000,
|
||||
"private_key": "###PRIVATE_KEY###"
|
||||
},
|
||||
"snapshot_sync": {
|
||||
"sleep": 3,
|
||||
"batch_size": 800,
|
||||
"starting_sub_id": 222001,
|
||||
"sync_period": 30
|
||||
}
|
||||
},
|
||||
"startup_wait": 1.0,
|
||||
"docker": {
|
||||
"username": "your-username",
|
||||
"password": ""
|
||||
},
|
||||
"redis": {
|
||||
"host": "redis",
|
||||
"port": 6379
|
||||
},
|
||||
"forward_stats": true,
|
||||
"snapshot_sync": {
|
||||
"sleep": 2,
|
||||
"batch_size": 10000,
|
||||
"starting_sub_id": 100000
|
||||
},
|
||||
|
||||
"containers": [
|
||||
{
|
||||
"id": "hello-world",
|
||||
|
8
rebuild.sh
Normal file
8
rebuild.sh
Normal file
@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
cd ~/node
|
||||
project=hello-world make deploy-container
|
||||
project=hello-world make deploy-contracts
|
||||
bash update_contracts.sh
|
||||
project=hello-world make call-contract
|
18
update.sh
18
update.sh
@ -1,23 +1,21 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if [ "$#" -ne 3 ]; then
|
||||
echo "Usage: $0 <wallet_address> <private_key> <rpc_url>"
|
||||
if [ "$#" -ne 2 ]; then
|
||||
echo "Usage: $0 <PARAMETER> <NEW_VALUE>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
WALLET_ADDRESS=$1
|
||||
PRIVATE_KEY=$2
|
||||
RPC_URL=$3
|
||||
PARAMETER=$1
|
||||
NEW_VALUE=$2
|
||||
|
||||
# List of files
|
||||
# Список файлов
|
||||
FILES=(
|
||||
"./projects/hello-world/container/config.json"
|
||||
"./projects/hello-world/contracts/Makefile"
|
||||
"grist.json"
|
||||
)
|
||||
|
||||
for FILE in "${FILES[@]}"; do
|
||||
EXPANDED_FILE=$(eval echo "$FILE")
|
||||
sed -i "s|###WALLET_ADDRESS###|$WALLET_ADDRESS|g" "$EXPANDED_FILE"
|
||||
sed -i "s|###PRIVATE_KEY###|$PRIVATE_KEY|g" "$EXPANDED_FILE"
|
||||
sed -i "s|###RPC_URL###|$RPC_URL|g" "$EXPANDED_FILE"
|
||||
sed -i "s|###$PARAMETER###|$NEW_VALUE|g" "$EXPANDED_FILE"
|
||||
done
|
6
update_contracts.sh
Normal file
6
update_contracts.sh
Normal file
@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
contract_address=$(jq -r '.transactions[0].contractAddress' projects/hello-world/contracts/broadcast/Deploy.s.sol/8453/run-latest.json)
|
||||
checksum_address=$(python3 toChecksumAddress.py $contract_address)
|
||||
sed -i "s/SaysGM(.*/SaysGM($checksum_address);/" projects/hello-world/contracts/script/CallContract.s.sol
|
Reference in New Issue
Block a user