From 98027d45629481b62ee0bc4c8ab095b13a56343c Mon Sep 17 00:00:00 2001 From: Adw8 Date: Fri, 20 Sep 2024 14:11:12 +0530 Subject: [PATCH] Add playbooks to setup fixturenet-laconicd and laconic-console --- .../run-laconic-console.yml | 66 +++++++++++++++++++ service-provider-setup/run-laconicd.yml | 33 ++++++++++ .../setup-container-registry.yml | 2 +- .../templates/configs/console-config.env.j2 | 2 + .../{ => specs}/container-registry.spec.j2 | 0 .../specs/fixturenet-laconicd-spec.yml.j2 | 15 +++++ .../specs/laconic-console-spec.yml.j2 | 9 +++ 7 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 service-provider-setup/run-laconic-console.yml create mode 100644 service-provider-setup/run-laconicd.yml create mode 100644 service-provider-setup/templates/configs/console-config.env.j2 rename service-provider-setup/templates/{ => specs}/container-registry.spec.j2 (100%) create mode 100644 service-provider-setup/templates/specs/fixturenet-laconicd-spec.yml.j2 create mode 100644 service-provider-setup/templates/specs/laconic-console-spec.yml.j2 diff --git a/service-provider-setup/run-laconic-console.yml b/service-provider-setup/run-laconic-console.yml new file mode 100644 index 0000000..037606b --- /dev/null +++ b/service-provider-setup/run-laconic-console.yml @@ -0,0 +1,66 @@ +- name: Setup and run laconic console + hosts: "{{target_host}}" + + environment: + PATH: "{{ ansible_env.PATH }}:/home/{{ansible_user}}/bin" + + tasks: + - name: Clone the stack repo + command: laconic-so fetch-stack git.vdb.to/cerc-io/testnet-laconicd-stack --pull + ignore_errors: yes + + - name: Clone required repositories for laconic-console + command: laconic-so --stack ~/cerc/testnet-laconicd-stack/stack-orchestrator/stacks/laconic-console setup-repositories --pull + + - name: Build container images + command: laconic-so --stack ~/cerc/testnet-laconicd-stack/stack-orchestrator/stacks/laconic-console build-containers --force-rebuild + + - name: Generate spec file for laconic console deployment + template: + src: "./templates/specs/laconic-console-spec.yml.j2" + dest: "laconic-console-spec.yml" + + - name: Check if the deployment directory exists + stat: + path: laconic-console-deployment + register: deployment_dir + + - name: Create a deployment from the spec file + command: laconic-so --stack ~/cerc/testnet-laconicd-stack/stack-orchestrator/stacks/laconic-console deploy create --spec-file laconic-console-spec.yml --deployment-dir laconic-console-deployment + when: not deployment_dir.stat.exists + + - name: Place deployment in the same namespace as fixturenet-laconicd + copy: + src: "fixturenet-laconicd-deployment/deployment.yml" + dest: "laconic-console-deployment/deployment.yml" + remote_src: yes + + - name: Fetch user key from laconicd + command: laconic-so deployment --dir fixturenet-laconicd-deployment exec laconicd "echo y | laconicd keys export alice --unarmored-hex --unsafe" + register: alice_pk + + - name: Set Private key for console deployment + set_fact: + ALICE_PK: "{{ alice_pk.stdout }}" + + - name: Start the laconic console deployment + command: laconic-so deployment --dir laconic-console-deployment start + + - name: Create a bond using cli + shell: laconic-so deployment --dir laconic-console-deployment exec cli "laconic registry bond create --type alnt --quantity 1000000000000 --user-key {{ALICE_PK}}" | jq -r '.bondId' + register: bond_id + + - name: Set Bond ID for console deployment + set_fact: + BOND_ID: "{{ bond_id.stdout }}" + + - name: Stop the console deployment + command: laconic-so deployment --dir laconic-console-deployment stop + + - name: Modify the console config with alice_pk and bond_id + template: + src: "./templates/configs/console-config.env.j2" + dest: "laconic-console-deployment/config.env" + + - name: Start the laconic console deployment with updated config + command: laconic-so deployment --dir laconic-console-deployment start diff --git a/service-provider-setup/run-laconicd.yml b/service-provider-setup/run-laconicd.yml new file mode 100644 index 0000000..33efa74 --- /dev/null +++ b/service-provider-setup/run-laconicd.yml @@ -0,0 +1,33 @@ +- name: Setup and run fixturnet-laconicd-stack + hosts: "{{ target_host }}" + + environment: + PATH: "{{ ansible_env.PATH }}:/home/{{ansible_user}}/bin" + + tasks: + - name: Clone the stack repo + command: laconic-so fetch-stack git.vdb.to/cerc-io/fixturenet-laconicd-stack --pull + ignore_errors: yes + + - name: Clone the fixturenet-laconicd repo + command: laconic-so --stack ~/cerc/fixturenet-laconicd-stack/stack-orchestrator/stacks/fixturenet-laconicd setup-repositories + + - name: Build container images + command: laconic-so --stack ~/cerc/fixturenet-laconicd-stack/stack-orchestrator/stacks/fixturenet-laconicd build-containers --force-rebuild + + - name: Generate over spec file for laconicd deployment + template: + src: "./templates/specs/fixturenet-laconicd-spec.yml.j2" + dest: "fixturenet-laconicd-spec.yml" + + - name: Check if the deployment directory exists + stat: + path: "fixturenet-laconicd-deployment" + register: deployment_dir + + - name: Create the deployment from the spec file + command: laconic-so --stack ~/cerc/fixturenet-laconicd-stack/stack-orchestrator/stacks/fixturenet-laconicd deploy create --spec-file fixturenet-laconicd-spec.yml --deployment-dir fixturenet-laconicd-deployment + when: not deployment_dir.stat.exists + + - name: Start the deployment + command: laconic-so deployment --dir fixturenet-laconicd-deployment start diff --git a/service-provider-setup/setup-container-registry.yml b/service-provider-setup/setup-container-registry.yml index ca81cfd..ba94611 100644 --- a/service-provider-setup/setup-container-registry.yml +++ b/service-provider-setup/setup-container-registry.yml @@ -11,7 +11,7 @@ tasks: - name: Generate the spec file for the container-registry stack template: - src: "./templates/container-registry.spec.j2" + src: "./templates/specs/container-registry.spec.j2" dest: "{{ansible_env.HOME}}/container-registry.spec" - name: Create a deployment for the container-registry stack diff --git a/service-provider-setup/templates/configs/console-config.env.j2 b/service-provider-setup/templates/configs/console-config.env.j2 new file mode 100644 index 0000000..7ecc724 --- /dev/null +++ b/service-provider-setup/templates/configs/console-config.env.j2 @@ -0,0 +1,2 @@ +CERC_LACONICD_USER_KEY={{ALICE_PK}} +CERC_LACONICD_BOND_ID={{BOND_ID}} diff --git a/service-provider-setup/templates/container-registry.spec.j2 b/service-provider-setup/templates/specs/container-registry.spec.j2 similarity index 100% rename from service-provider-setup/templates/container-registry.spec.j2 rename to service-provider-setup/templates/specs/container-registry.spec.j2 diff --git a/service-provider-setup/templates/specs/fixturenet-laconicd-spec.yml.j2 b/service-provider-setup/templates/specs/fixturenet-laconicd-spec.yml.j2 new file mode 100644 index 0000000..b6ef644 --- /dev/null +++ b/service-provider-setup/templates/specs/fixturenet-laconicd-spec.yml.j2 @@ -0,0 +1,15 @@ +stack: + /home/{{ansible_user}}/cerc/fixturenet-laconicd-stack/stack-orchestrator/stacks/fixturenet-laconicd +deploy-to: compose +network: + ports: + laconicd: + - '6060:6060' + - '26657:26657' + - '26656:26656' + - '9473:9473' + - '9090:9090' + - '1317:1317' +volumes: + laconicd-data: ./data/laconicd-data + genesis-config: ./data/genesis-config diff --git a/service-provider-setup/templates/specs/laconic-console-spec.yml.j2 b/service-provider-setup/templates/specs/laconic-console-spec.yml.j2 new file mode 100644 index 0000000..a379476 --- /dev/null +++ b/service-provider-setup/templates/specs/laconic-console-spec.yml.j2 @@ -0,0 +1,9 @@ +stack: + /home/{{ansible_user}}/cerc/testnet-laconicd-stack/stack-orchestrator/stacks/laconic-console +deploy-to: compose +network: + ports: + console: + - '8080:80' +volumes: + laconic-registry-data: ./data/laconic-registry-data