laconicd-stack/playbooks/validator/setup-validator.yml
Prathamesh Musale d91ed4280f Update yq setup and remove --git-ssh usage (#30)
Part of https://www.notion.so/Create-stacks-for-mainnet-1f2a6b22d4728034be4be2c51decf94e
- Add step for installing `zstd` in macOS
- Use ansible command module for running docker commands

Co-authored-by: Shreerang Kale <shreerangkale@gmail.com>
Reviewed-on: #30
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
2025-06-19 13:18:56 +00:00

114 lines
4.4 KiB
YAML

---
- name: Setup mainnet validator node
hosts: localhost
vars_files:
- validator-vars.yml
vars:
data_directory: "{{ lookup('env', 'DATA_DIRECTORY') }}"
mainnet_deployment_dir: "{{ lookup('env', 'MAINNET_DEPLOYMENT_DIR') }}"
spec_file: "{{data_directory}}/laconicd-validator-spec.yml"
spec_template: "./templates/specs/spec-template.yml.j2"
build_args: "{{ '--force-rebuild' if (lookup('env', 'FORCE_REBUILD') | default(omit, true)) not in [ 'false', 'False', '0' ] else '' }}"
BUILD_ONLY: "{{ lookup('env', 'BUILD_ONLY') | default(false) | bool }}"
tasks:
- name: Include setup tasks
ansible.builtin.import_tasks: ../setup.yml
- name: Fail if DATA_DIRECTORY or MAINNET_DEPLOYMENT_DIR env vars are not set
fail:
msg: >-
Required environment variables are not set.
Please export both DATA_DIRECTORY and MAINNET_DEPLOYMENT_DIR before running the playbook.
when: not BUILD_ONLY and (lookup('env', 'DATA_DIRECTORY') == '' or lookup('env', 'MAINNET_DEPLOYMENT_DIR') == '')
- name: Fail if required key files are not defined
fail:
msg: >-
Required key files are not defined.
Please set genesis_file and staking_amount_file in validator-vars.yml.
when: not BUILD_ONLY and (not genesis_file or not staking_amount_file)
- name: Setup required repositories
shell: >
laconic-so --stack ~/cerc/laconicd-stack/stack-orchestrator/stacks/mainnet-laconicd
setup-repositories --pull
- name: Build container images
shell: |
laconic-so --stack ~/cerc/laconicd-stack/stack-orchestrator/stacks/mainnet-laconicd build-containers {{ build_args }}
- name: Create deployment spec file
when: not BUILD_ONLY
shell: |
laconic-so --stack ~/cerc/laconicd-stack/stack-orchestrator/stacks/mainnet-laconicd deploy init --output {{ spec_file }}
- name: Replace network section in spec_file
when: not BUILD_ONLY
shell: >
{{ yq_path }} eval '(.network) = load("{{ spec_template }}").network' -i {{ spec_file }}
- name: Create deployment from spec file
when: not BUILD_ONLY
shell: |
laconic-so --stack ~/cerc/laconicd-stack/stack-orchestrator/stacks/mainnet-laconicd deploy create --spec-file {{ spec_file }} --deployment-dir {{data_directory}}/{{ mainnet_deployment_dir }}
- name: Create config.env
when: not BUILD_ONLY
copy:
dest: "{{data_directory}}/{{ mainnet_deployment_dir }}/config.env"
content: |
CERC_MONIKER: "{{ cerc_moniker }}"
CERC_CHAIN_ID: "{{ cerc_chain_id }}"
CERC_PEERS: "{{ cerc_peers }}"
MIN_GAS_PRICE: "{{ min_gas_price }}"
CERC_LOGLEVEL: "{{ cerc_loglevel }}"
TMKMS_ENABLED: "{{ tmkms_enabled }}"
mode: '0777'
- name: Ensure tmp directory exists inside laconicd-data
when: not BUILD_ONLY
file:
path: "{{data_directory}}/{{ mainnet_deployment_dir }}/data/laconicd-data/tmp"
state: directory
mode: '0755'
- name: Copy compressed genesis file to laconicd-data tmp directory
when: not BUILD_ONLY
copy:
src: "{{ genesis_file }}"
dest: "{{ data_directory }}/{{ mainnet_deployment_dir }}/data/laconicd-data/tmp/genesis.json.zst"
mode: '0644'
- name: Decompress genesis file in tmp directory
when: not BUILD_ONLY
ansible.builtin.command:
argv:
- zstd
- -d
- "-f"
- "{{ data_directory }}/{{ mainnet_deployment_dir }}/data/laconicd-data/tmp/genesis.json.zst"
- "-o"
- "{{ data_directory }}/{{ mainnet_deployment_dir }}/data/laconicd-data/tmp/genesis.json"
args:
creates: "{{ data_directory }}/{{ mainnet_deployment_dir }}/data/laconicd-data/tmp/genesis.json"
- name: Initialize laconicd node
when: not BUILD_ONLY
command:
argv:
- docker
- run
- -i
- -v
- "{{data_directory}}/{{ mainnet_deployment_dir }}/data/laconicd-data:/root/.laconicd"
- -v
- "{{data_directory}}/{{ mainnet_deployment_dir }}/config/mainnet-laconicd:/scripts"
- -e
- "CERC_MONIKER={{ cerc_moniker }}"
- -e
- "CERC_CHAIN_ID={{ cerc_chain_id }}"
- cerc/laconicd:local
- bash
- -c
- "/scripts/setup-laconicd.sh"