From 6764862589af99f1cb44c7de5d8e2cd82e5899d0 Mon Sep 17 00:00:00 2001 From: Adw8 Date: Tue, 3 Sep 2024 15:42:04 +0530 Subject: [PATCH] Add playbook for running L2 deployment --- l2-setup/README.md | 52 ++++++++++++++++++++ l2-setup/run-optimism.yml | 62 ++++++++++++++++++++++++ l2-setup/templates/configs/l2-config.env | 9 ++++ l2-setup/templates/specs/l2-spec.yml.j2 | 18 +++++++ 4 files changed, 141 insertions(+) create mode 100644 l2-setup/README.md create mode 100644 l2-setup/run-optimism.yml create mode 100644 l2-setup/templates/configs/l2-config.env create mode 100644 l2-setup/templates/specs/l2-spec.yml.j2 diff --git a/l2-setup/README.md b/l2-setup/README.md new file mode 100644 index 0000000..8bfe744 --- /dev/null +++ b/l2-setup/README.md @@ -0,0 +1,52 @@ +# l2-setup + +## Setup Ansible + +To get started, follow the [installation](../README.md#installation) guide to setup ansible on your machine + +## Setup and Run Optimism + +The following commands have to be executed in [`l2-setup`](./) directory + +- Edit [`l2-config.env.j2`](./templates/configs/l2-config.env.j2) and fill in the following values + + ```bash + # Chain ID of the L1 chain + CERC_L1_CHAIN_ID= + + # L1 RPC endpoint + CERC_L1_RPC= + + # Amount to send the proposer on L2 (default: 0.2 ether) + CERC_L2_PROPOSER_AMOUNT= + + # Amount to send the batcher on L2 (default: 0.1 ether) + CERC_L2_BATCHER_AMOUNT= + + # L1 RPC endpoint host or IP address + CERC_L1_HOST= + + # L1 RPC endpoint port number + CERC_L1_PORT= + + # Address of the funded account on L1 + # Used for optimism contracts deployment + CERC_L1_ADDRESS= + + # Private key of the funded account on L1 + CERC_L1_PRIV_KEY= + ``` + +- To setup and run L2, execute the `run-optimism.yml` Ansible playbook by running the following command. + + NOTE: By default, deployments are created in the `l2-setup/out` directory. To change this location, update the `l2_directory` variable in the [vars.yml](./vars.yml) file. + + ```bash + LANG=en_US.utf8 ansible-playbook -i localhost, --connection=local run-optimism.yml --extra-vars='{ "target_host": "localhost"}' --user $USER + ``` + + - For skipping container build, set `"skip_container_build" : true` in the `--extra-vars` parameter: + + ```bash + LANG=en_US.utf8 ansible-playbook -i localhost, --connection=local run-optimism.yml --extra-vars='{"target_host" : "localhost", "skip_container_build": true}' -kK --user $USER + ``` diff --git a/l2-setup/run-optimism.yml b/l2-setup/run-optimism.yml new file mode 100644 index 0000000..5099f71 --- /dev/null +++ b/l2-setup/run-optimism.yml @@ -0,0 +1,62 @@ +- name: Setup L2 on host + hosts: "{{ target_host }}" + + vars_files: + - vars.yml + + environment: + PATH: "{{ ansible_env.PATH }}:/home/{{ansible_user}}/bin" + + tasks: + - name: Create directory for L2 + file: + path: "{{ l2_directory }}" + state: directory + + - name: Change owner of l2-directory + file: + path: "{{ l2_directory }}" + owner: "{{ansible_user}}" + group: "{{ansible_user}}" + state: directory + recurse: yes + + - name: Clone fixturenet-optimism-stack + command: laconic-so fetch-stack git.vdb.to/cerc-io/fixturenet-optimism-stack --pull + ignore_errors: yes + + - name: Clone required repositories for fixturenet-optimism + command: laconic-so --stack ~/cerc/fixturenet-optimism-stack/stack/fixturenet-optimism setup-repositories --pull + + - name: Build container images for L2 + command: laconic-so --stack ~/cerc/fixturenet-optimism-stack/stack/fixturenet-optimism build-containers --force-rebuild + when: not skip_container_build + + - name: Remove any dangling docker images + command: docker image prune -f + + - name: Copy over spec file for L2 deployment + template: + src: "./templates/specs/l2-spec.yml.j2" + dest: "{{ l2_directory }}/fixturenet-optimism-spec.yml" + + - name: Check if the deployment directory exists for L2 + stat: + path: "{{ l2_directory }}/fixturenet-optimism-deployment" + register: l2_deployment_dir + + - name: Create a deployment from the spec file for L2 + command: laconic-so --stack ~/cerc/fixturenet-optimism-stack/stack/fixturenet-optimism deploy create --spec-file fixturenet-optimism-spec.yml --deployment-dir fixturenet-optimism-deployment + args: + chdir: "{{ l2_directory }}" + when: not l2_deployment_dir.stat.exists + + - name: Copy config.env for L2 deployment + template: + src: "./templates/configs/l2-config.env" + dest: "{{ l2_directory }}/fixturenet-optimism-deployment/config.env" + + - name: Start L2-deployment + command: laconic-so deployment --dir fixturenet-optimism-deployment start + args: + chdir: "{{ l2_directory }}" diff --git a/l2-setup/templates/configs/l2-config.env b/l2-setup/templates/configs/l2-config.env new file mode 100644 index 0000000..02087b7 --- /dev/null +++ b/l2-setup/templates/configs/l2-config.env @@ -0,0 +1,9 @@ +CERC_ALLOW_UNPROTECTED_TXS=true +CERC_L1_CHAIN_ID= +CERC_L1_RPC= +CERC_L2_PROPOSER_AMOUNT= +CERC_L2_BATCHER_AMOUNT= +CERC_L1_HOST= +CERC_L1_PORT= +CERC_L1_ADDRESS= +CERC_L1_PRIV_KEY= diff --git a/l2-setup/templates/specs/l2-spec.yml.j2 b/l2-setup/templates/specs/l2-spec.yml.j2 new file mode 100644 index 0000000..456e557 --- /dev/null +++ b/l2-setup/templates/specs/l2-spec.yml.j2 @@ -0,0 +1,18 @@ +stack: /home/{{ansible_user}}/cerc/fixturenet-optimism-stack/stack/fixturenet-optimism +deploy-to: compose +network: + ports: + op-geth: + - '9545:8545' + - '9546:8546' + op-node: + - '8547' + op-batcher: + - '8548' + op-proposer: + - '8560' +volumes: + l1_deployment: ./data/l1_deployment + l2_accounts: ./data/l2_accounts + l2_config: ./data/l2_config + l2_geth_data: ./data/l2_geth_data