From 161e2109854a334e99179850520d75cc87477430 Mon Sep 17 00:00:00 2001 From: Adw8 Date: Thu, 5 Sep 2024 19:03:33 +0530 Subject: [PATCH] Decouple playbook to deploy nitro contracts --- nitro-bridge-setup/bridge-vars-example.yml | 8 +- nitro-bridge-setup/deploy-contracts.yml | 103 ++++++++++++++++++ nitro-bridge-setup/run-nitro-bridge.yml | 59 ---------- .../templates/specs/bridge-nitro-spec.yml.j2 | 8 +- .../specs/nitro-contracts-spec.yml.j2 | 4 +- 5 files changed, 116 insertions(+), 66 deletions(-) create mode 100644 nitro-bridge-setup/deploy-contracts.yml diff --git a/nitro-bridge-setup/bridge-vars-example.yml b/nitro-bridge-setup/bridge-vars-example.yml index 090b8f0..3697d49 100644 --- a/nitro-bridge-setup/bridge-vars-example.yml +++ b/nitro-bridge-setup/bridge-vars-example.yml @@ -7,4 +7,10 @@ geth_url: "" optimism_url: "" geth_deployer_pk: "" optimism_deployer_pk: "" -token_name: "" +token_name: "LaconicNetworkToken" +token_symbol: "LNT" +intial_token_supply: "129600" +na_address: "" +vpa_address: "" +ca_address: "" +l1_asset_address: "" diff --git a/nitro-bridge-setup/deploy-contracts.yml b/nitro-bridge-setup/deploy-contracts.yml new file mode 100644 index 0000000..cd10d1e --- /dev/null +++ b/nitro-bridge-setup/deploy-contracts.yml @@ -0,0 +1,103 @@ +- name: Deploy nitro contracts + hosts: "{{ target_host }}" + + vars_files: + - setup-vars.yml + - bridge-vars.yml + + environment: + PATH: "{{ ansible_env.PATH }}:/home/{{ansible_user}}/bin" + + tasks: + - name: Create directory for nitro bridge deployment + file: + path: "{{ nitro_directory }}" + state: directory + become: yes + + - name: Clone go-nitro stack repo + command: laconic-so fetch-stack git.vdb.to/cerc-io/nitro-stack --git-ssh --pull + ignore_errors: yes + + - name: Change owner of nitro-directory + file: + path: "{{ nitro_directory }}" + owner: "{{ansible_user}}" + group: "{{ansible_user}}" + state: directory + recurse: yes + become: yes + + - name: Clone repositories required for nitro-stack + command: laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/bridge setup-repositories --git-ssh --pull + ignore_errors: yes + + - name: Build containers + command: laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/bridge build-containers --force-rebuild + when: not skip_container_build + + - name: Generate spec file for nitro contracts deployment + template: + src: "./templates/specs/nitro-contracts-spec.yml.j2" + dest: "{{ nitro_directory }}/nitro-contracts-spec.yml" + + - name: Check if deployment exists for nitro contracts + stat: + path: "{{ nitro_directory }}/nitro-contracts-deployment" + register: nitro_contracts_deployment + become: yes + + - name: Create a deployment for nitro contracts + command: laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-contracts deploy create --spec-file nitro-contracts-spec.yml --deployment-dir nitro-contracts-deployment + args: + chdir: "{{ nitro_directory }}" + when: not nitro_contracts_deployment.stat.exists + + - name: Start deployment for nitro-contracts + command: laconic-so deployment --dir nitro-contracts-deployment start + args: + chdir: "{{ nitro_directory }}" + + - name: Wait for the contracts to be deployed + wait_for: + path: "{{ nitro_directory }}/nitro-contracts-deployment/data/nitro_deployment/nitro-addresses.json" + timeout: 60 + + - name: Export NA_ADDRESS + shell: laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "jq -r '.\"1212\"[0].contracts.NitroAdjudicator.address' /app/deployment/nitro-addresses.json" + args: + chdir: "{{ nitro_directory }}" + register: na_address + - debug: + msg: "NA_ADDRESS: {{ na_address.stdout }}" + + - name: Export CA_ADDRESS + shell: laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "jq -r '.\"1212\"[0].contracts.ConsensusApp.address' /app/deployment/nitro-addresses.json" + args: + chdir: "{{ nitro_directory }}" + register: ca_address + - debug: + msg: "CA_ADDRESS: {{ ca_address.stdout }}" + + - name: Export VPA_ADDRESS + shell: laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "jq -r '.\"1212\"[0].contracts.VirtualPaymentApp.address' /app/deployment/nitro-addresses.json" + args: + chdir: "{{ nitro_directory }}" + register: vpa_address + - debug: + msg: "VPA_ADDRESS: {{ vpa_address.stdout }}" + + - name: Export L1_ASSET_ADDRESS + shell: laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "jq -r '.\"1212\"[0].contracts.Token.address' /app/deployment/nitro-addresses.json" + args: + chdir: "{{ nitro_directory }}" + register: l1_asset_address + - debug: + msg: "L1_ASSET_ADDRESS: {{ l1_asset_address.stdout }}" + + - name: Set contract addresses + set_fact: + na_address: "{{ na_address.stdout }}" + ca_address: "{{ ca_address.stdout }}" + vpa_address: "{{ vpa_address.stdout }}" + l1_asset_address: "{{ l1_asset_address.stdout }}" diff --git a/nitro-bridge-setup/run-nitro-bridge.yml b/nitro-bridge-setup/run-nitro-bridge.yml index 0118512..e3d02ff 100644 --- a/nitro-bridge-setup/run-nitro-bridge.yml +++ b/nitro-bridge-setup/run-nitro-bridge.yml @@ -36,65 +36,6 @@ command: laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/bridge build-containers --force-rebuild when: not skip_container_build - - name: Generate spec file for nitro contracts deployment - template: - src: "./templates/specs/nitro-contracts-spec.yml.j2" - dest: "{{ nitro_directory }}/nitro-contracts-spec.yml" - - - name: Check if deployment exists for nitro contracts - stat: - path: "{{ nitro_directory }}/nitro-contracts-deployment" - register: nitro_contracts_deployment - become: yes - - - name: Create a deployment for nitro contracts - command: laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-contracts deploy create --spec-file nitro-contracts-spec.yml --deployment-dir nitro-contracts-deployment - args: - chdir: "{{ nitro_directory }}" - when: not nitro_contracts_deployment.stat.exists - - - name: Start deployment for nitro-contracts - command: laconic-so deployment --dir nitro-contracts-deployment start - args: - chdir: "{{ nitro_directory }}" - - - name: Wait for the contracts to be deployed - wait_for: - path: "{{ nitro_directory }}/nitro-contracts-deployment/data/nitro_deployment/nitro-addresses.json" - timeout: 60 - - - name: Export NA_ADDRESS - shell: laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "jq -r '.\"1212\"[0].contracts.NitroAdjudicator.address' /app/deployment/nitro-addresses.json" - args: - chdir: "{{ nitro_directory }}" - register: na_address - - debug: - msg: "NA_ADDRESS: {{ na_address.stdout }}" - - - name: Export CA_ADDRESS - shell: laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "jq -r '.\"1212\"[0].contracts.ConsensusApp.address' /app/deployment/nitro-addresses.json" - args: - chdir: "{{ nitro_directory }}" - register: ca_address - - debug: - msg: "CA_ADDRESS: {{ ca_address.stdout }}" - - - name: Export VPA_ADDRESS - shell: laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "jq -r '.\"1212\"[0].contracts.VirtualPaymentApp.address' /app/deployment/nitro-addresses.json" - args: - chdir: "{{ nitro_directory }}" - register: vpa_address - - debug: - msg: "VPA_ADDRESS: {{ vpa_address.stdout }}" - - - name: Export L1_ASSET_ADDRESS - shell: laconic-so deployment --dir nitro-contracts-deployment exec nitro-contracts "jq -r '.\"1212\"[0].contracts.Token.address' /app/deployment/nitro-addresses.json" - args: - chdir: "{{ nitro_directory }}" - register: l1_asset_address - - debug: - msg: "L1_ASSET_ADDRESS: {{ l1_asset_address.stdout }}" - - name: Check if deployment exists for bridge node stat: path: "{{ nitro_directory }}/bridge-deployment" diff --git a/nitro-bridge-setup/templates/specs/bridge-nitro-spec.yml.j2 b/nitro-bridge-setup/templates/specs/bridge-nitro-spec.yml.j2 index f63701a..6244d66 100644 --- a/nitro-bridge-setup/templates/specs/bridge-nitro-spec.yml.j2 +++ b/nitro-bridge-setup/templates/specs/bridge-nitro-spec.yml.j2 @@ -11,10 +11,10 @@ config: TOKEN_NAME: {{ token_name }} TOKEN_SYMBOL: LNT INITIAL_TOKEN_SUPPLY: 129600 - NA_ADDRESS: {{ na_address.stdout }} - VPA_ADDRESS: {{ vpa_address.stdout }} - CA_ADDRESS: {{ ca_address.stdout }} - L1_ASSET_ADDRESS: {{ l1_asset_address.stdout }} + NA_ADDRESS: {{ na_address }} + VPA_ADDRESS: {{ vpa_address }} + CA_ADDRESS: {{ ca_address }} + L1_ASSET_ADDRESS: {{ l1_asset_address }} network: ports: nitro-bridge: diff --git a/nitro-bridge-setup/templates/specs/nitro-contracts-spec.yml.j2 b/nitro-bridge-setup/templates/specs/nitro-contracts-spec.yml.j2 index e725236..9c2f4ad 100644 --- a/nitro-bridge-setup/templates/specs/nitro-contracts-spec.yml.j2 +++ b/nitro-bridge-setup/templates/specs/nitro-contracts-spec.yml.j2 @@ -5,8 +5,8 @@ config: GETH_CHAIN_ID: {{ geth_chain_id }} GETH_DEPLOYER_PK: {{ geth_deployer_pk }} TOKEN_NAME: {{ token_name }} - TOKEN_SYMBOL: LNT - INITIAL_TOKEN_SUPPLY: 129600 + TOKEN_SYMBOL: {{ token_symbol }} + INITIAL_TOKEN_SUPPLY: {{ intial_token_supply }} network: ports: {} volumes: