diff --git a/.ansible-lint b/.ansible-lint index 4bb121a..45c4c5d 100755 --- a/.ansible-lint +++ b/.ansible-lint @@ -4,3 +4,4 @@ mock_modules: - community.postgresql.postgresql_db - community.postgresql.postgresql_user - community.postgresql.postgresql_owner + - community.docker.docker_image diff --git a/roles/docker/tasks/main.yaml b/roles/docker/tasks/main.yaml new file mode 100644 index 0000000..2050bec --- /dev/null +++ b/roles/docker/tasks/main.yaml @@ -0,0 +1,40 @@ +--- +- name: Install software + ansible.builtin.apt: + update_cache: true + name: + - apt-transport-https + - ca-certificates + - curl + - software-properties-common + +- name: Add apt key for required repositories + ansible.builtin.apt_key: + url: '{{ item }}' + state: present + with_items: + # docker + - https://download.docker.com/linux/ubuntu/gpg + +- name: Add required source repositories into sources list + ansible.builtin.apt_repository: + repo: '{{ item }}' + state: present + with_items: + - "deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable" + +- name: Install software + ansible.builtin.apt: + update_cache: true + name: + - docker-ce + - docker-ce-cli + - containerd.io + - docker-buildx-plugin + - docker-compose-plugin + +- name: Restart docker + ansible.builtin.systemd: + state: restarted + daemon_reload: true + name: docker diff --git a/roles/geth/tasks/main.yaml b/roles/geth/tasks/main.yaml index 4b1381a..f34b1da 100644 --- a/roles/geth/tasks/main.yaml +++ b/roles/geth/tasks/main.yaml @@ -17,6 +17,7 @@ remote_src: true dest: /tmp extra_opts: ['--strip-components=1', '--show-stored-names'] + when: not ansible_check_mode - name: Copy geth binary ansible.builtin.copy: @@ -26,3 +27,4 @@ owner: root group: root mode: '0755' + when: not ansible_check_mode diff --git a/roles/grafana_agent/defaults/main.yaml b/roles/grafana_agent/defaults/main.yaml index e38cee6..d5f3c19 100644 --- a/roles/grafana_agent/defaults/main.yaml +++ b/roles/grafana_agent/defaults/main.yaml @@ -1,5 +1,6 @@ --- grafana_agent_version: 0.43.0 grafana_agent_repository: grafana/agent -# config template may be loaded when the lookup plugin is enabled with the following snipped "{{ lookup('file', 'configs/grafana-agent-monitoring-template.yaml') }}" +# config template may be loaded when the lookup plugin is enabled with the following snipped: +# "{{ lookup('file', 'configs/grafana-agent-monitoring-template.yaml') }}" grafana_agent_config_content: "# empty content" diff --git a/roles/grafana_agent/handlers/main.yaml b/roles/grafana_agent/handlers/main.yaml index 10c0494..7fc95e6 100644 --- a/roles/grafana_agent/handlers/main.yaml +++ b/roles/grafana_agent/handlers/main.yaml @@ -1,6 +1,7 @@ +--- - name: Restart grafana-agent ansible.builtin.service: name: grafana-agent state: restarted listen: Restart grafana-agent - when: not ansible_check_mode \ No newline at end of file + when: not ansible_check_mode diff --git a/roles/grafana_agent/tasks/main.yaml b/roles/grafana_agent/tasks/main.yaml index 531b0c6..3200103 100644 --- a/roles/grafana_agent/tasks/main.yaml +++ b/roles/grafana_agent/tasks/main.yaml @@ -1,7 +1,7 @@ --- - name: Grafana Agent | Install grafana-agent ansible.builtin.apt: - deb: "https://github.com/{{- grafana_agent_repository -}}/releases/download/v{{- grafana_agent_version -}}/grafana-agent-{{- grafana_agent_version -}}-1.amd64.deb" + deb: "https://github.com/{{- grafana_agent_repository -}}/releases/download/v{{- grafana_agent_version -}}/grafana-agent-{{- grafana_agent_version -}}-1.amd64.deb" # noqa: yaml[line-length] - name: Grafana Agent | Update CUSTOM_ARGS environment variables for grafana config ansible.builtin.lineinfile: diff --git a/roles/pyth_price_scheduler/defaults/main.yaml b/roles/pyth_price_scheduler/defaults/main.yaml new file mode 100644 index 0000000..6424de2 --- /dev/null +++ b/roles/pyth_price_scheduler/defaults/main.yaml @@ -0,0 +1,10 @@ +--- +pyth_price_scheduler_docker_image: public.ecr.aws/pyth-network/xc-price-pusher:v8.0.0 +pyth_price_scheduler_mnemonic: "PUT_PRIVATE_KEY_HERE" +pyth_price_scheduler_endpoint: "PUT_HERE_RPC_URL" +pyth_price_scheduler_contract_address: "PUT_HERE_CONTRACT_ADDRESS" +pyth_price_scheduler_service_endpoint: https://hermes.pyth.network +pyth_price_scheduler_price_config_content: "PUT_CONFIG_HERE" + +pyth_price_scheduler_process_watcher_version: "v0.1.0" +pyth_price_scheduler_process_watcher_repository: "vegaprotocol/process-watcher" diff --git a/roles/pyth_price_scheduler/tasks/main.yaml b/roles/pyth_price_scheduler/tasks/main.yaml new file mode 100644 index 0000000..50bbead --- /dev/null +++ b/roles/pyth_price_scheduler/tasks/main.yaml @@ -0,0 +1,6 @@ +--- +- name: Process watcher + ansible.builtin.import_tasks: process-watcher.yaml + +- name: Price pusher + ansible.builtin.import_tasks: price-pusher.yaml diff --git a/roles/pyth_price_scheduler/tasks/price-pusher.yaml b/roles/pyth_price_scheduler/tasks/price-pusher.yaml new file mode 100644 index 0000000..0107340 --- /dev/null +++ b/roles/pyth_price_scheduler/tasks/price-pusher.yaml @@ -0,0 +1,62 @@ +--- +- name: Install python packages for Ansible + ansible.builtin.pip: + name: + - docker + +- name: Pull an price scheduler docker image + community.docker.docker_image: + name: "{{- pyth_price_scheduler_docker_image -}}" + source: pull + pull: + platform: amd64 + +- name: Ensure group "pyth-price-scheduler" exists + ansible.builtin.group: + name: pyth-price-scheduler + state: present + +- name: Add the user "pyth-price-scheduler" + ansible.builtin.user: + name: pyth-price-scheduler + comment: Price scheduler + groups: pyth-price-scheduler,docker + +- name: Copy service file + ansible.builtin.template: + src: "lib/systemd/system/pyth-price-scheduler.service.j2" + dest: "/lib/systemd/system/pyth-price-scheduler.service" + owner: root + group: root + mode: '0644' + +- name: "Create config directory for the pyth-price-scheduler" + ansible.builtin.file: + path: "/home/pyth-price-scheduler" + state: directory + owner: pyth-price-scheduler + group: pyth-price-scheduler + mode: '0755' + +- name: Copy config file + ansible.builtin.copy: + dest: "/home/pyth-price-scheduler/price-config.yaml" + content: "{{ pyth_price_scheduler_price_config_content }}" + owner: pyth-price-scheduler + group: pyth-price-scheduler + mode: "0644" + +- name: Save mnemonic + ansible.builtin.copy: + owner: pyth-price-scheduler + group: pyth-price-scheduler + content: "{{- pyth_price_scheduler_mnemonic -}}" + dest: /home/pyth-price-scheduler/mnemonic + mode: "0644" + +- name: Start and enable systemd service for pyth-price-scheduler + ansible.builtin.service: + name: "pyth-price-scheduler" + state: restarted + enabled: true + daemon_reload: true diff --git a/roles/pyth_price_scheduler/tasks/process-watcher.yaml b/roles/pyth_price_scheduler/tasks/process-watcher.yaml new file mode 100644 index 0000000..c55d6d0 --- /dev/null +++ b/roles/pyth_price_scheduler/tasks/process-watcher.yaml @@ -0,0 +1,44 @@ +--- +- name: Download binary + ansible.builtin.get_url: + url: "https://github.com/{{- pyth_price_scheduler_process_watcher_repository -}}/releases/download/{{- pyth_price_scheduler_process_watcher_version -}}/process-watcher-linux-amd64.zip" # noqa: yaml[line-length] + dest: &watcherdist /tmp/process-watcher.tar.gz + mode: '0600' + +- name: Unpack binary + ansible.builtin.unarchive: + src: *watcherdist + remote_src: true + dest: /tmp + +- name: Copy the binary + ansible.builtin.copy: + remote_src: true + src: "/tmp/process-watcher" + dest: /usr/bin/process-watcher + owner: root + group: root + mode: '0755' + +- name: Copy process watcher config + ansible.builtin.template: + src: "etc/pyth-process-watcher-config.toml" + dest: "/etc/pyth-process-watcher-config.toml" + owner: root + group: root + mode: '0644' + +- name: Copy process watcher service file + ansible.builtin.template: + src: "lib/systemd/system/pyth-process-watcher.service.j2" + dest: "/lib/systemd/system/pyth-process-watcher.service" + owner: root + group: root + mode: '0644' + +- name: Start pusher watcher service + ansible.builtin.service: + name: "pyth-process-watcher" + state: restarted + enabled: true + daemon_reload: true diff --git a/roles/pyth_price_scheduler/templates/etc/pyth-process-watcher-config.toml b/roles/pyth_price_scheduler/templates/etc/pyth-process-watcher-config.toml new file mode 100644 index 0000000..ab84735 --- /dev/null +++ b/roles/pyth_price_scheduler/templates/etc/pyth-process-watcher-config.toml @@ -0,0 +1,23 @@ +[commands] + # Define the log stream command + log-stream = [ + "/usr/bin/journalctl", + "-u", "pyth-price-scheduler", + "-n", "1", + "-f", + ] + # Define the command used to stop the service + stop = ["/usr/bin/systemctl", "stop", "pyth-price-scheduler"] + # Define the command to start the service + start = ["/usr/bin/systemctl", "start", "pyth-price-scheduler"] + + +[process-watcher] + # Watches if specific docker container is running + [process-watcher.docker] + enabled = true + container-name = "pyth-price-scheduler" + +[logs-watcher] + # Define the keywords that trigger process restart + failure-keywords = ["err", "failed", "throw err", "error"] \ No newline at end of file diff --git a/roles/pyth_price_scheduler/templates/lib/systemd/system/pyth-price-scheduler.service.j2 b/roles/pyth_price_scheduler/templates/lib/systemd/system/pyth-price-scheduler.service.j2 new file mode 100644 index 0000000..f947ae5 --- /dev/null +++ b/roles/pyth_price_scheduler/templates/lib/systemd/system/pyth-price-scheduler.service.j2 @@ -0,0 +1,31 @@ +[Unit] +Description=Pyth price pusher +Documentation=https://github.com/pyth-network/pyth-crosschain/tree/main/price_pusher +After=docker.service +Requires=docker.service + +[Service] +User=pyth-price-scheduler +Group=pyth-price-scheduler +TimeoutStartSec=0 +Restart=always +ExecStop=/usr/bin/docker kill pyth-price-scheduler +ExecStartPre=-/usr/bin/docker stop pyth-price-scheduler +ExecStartPre=-/usr/bin/docker rm pyth-price-scheduler +ExecStartPre=/usr/bin/docker pull {{ pyth_price_scheduler_docker_image }} +ExecStart=/usr/bin/docker run \ + --name pyth-price-scheduler \ + -v /home/pyth-price-scheduler:/config \ + {{ pyth_price_scheduler_docker_image }} \ + npm run start -- \ + evm \ + --endpoint "{{- pyth_price_scheduler_endpoint -}}" \ + --mnemonic-file "/config/mnemonic" \ + --pyth-contract-address "{{- pyth_price_scheduler_contract_address -}}" \ + --price-service-endpoint "{{- pyth_price_scheduler_service_endpoint -}}" \ + --price-config-file "/config/price-config.yaml" \ + --polling-frequency 5 + + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/roles/pyth_price_scheduler/templates/lib/systemd/system/pyth-process-watcher.service.j2 b/roles/pyth_price_scheduler/templates/lib/systemd/system/pyth-process-watcher.service.j2 new file mode 100644 index 0000000..33004f3 --- /dev/null +++ b/roles/pyth_price_scheduler/templates/lib/systemd/system/pyth-process-watcher.service.j2 @@ -0,0 +1,17 @@ +[Unit] +Description=Pyth price process watcher +Documentation=https://github.com/vegaprotocol/process-watcher +After=docker.service +Requires=docker.service +After=network.target network-online.target +Requires=network-online.target + +[Service] +User=root +Group=root +TimeoutStartSec=0 +Restart=always +ExecStart=/usr/bin/process-watcher run --config-path /etc/pyth-process-watcher-config.toml + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/roles/vega_common/tasks/main.yaml b/roles/vega_common/tasks/main.yaml index 6aa1eee..15c05c9 100644 --- a/roles/vega_common/tasks/main.yaml +++ b/roles/vega_common/tasks/main.yaml @@ -11,6 +11,14 @@ - acl - unzip - gzip + - tar + - bzip2 + +- name: Install Python and pip + ansible.builtin.apt: + pkg: + - python3 + - python3-pip - name: Ensure group "vega" exists ansible.builtin.group: diff --git a/roles/vega_core/tasks/get-binaries.yaml b/roles/vega_core/tasks/get-binaries.yaml index 9ff59c9..7219cb5 100644 --- a/roles/vega_core/tasks/get-binaries.yaml +++ b/roles/vega_core/tasks/get-binaries.yaml @@ -11,6 +11,7 @@ src: *vega_dest remote_src: true dest: /tmp + when: not ansible_check_mode - name: Copy vega binary ansible.builtin.copy: @@ -20,6 +21,7 @@ owner: root group: root mode: '0755' + when: not ansible_check_mode - name: Download visor binary ansible.builtin.get_url: @@ -33,6 +35,7 @@ src: *visor_dest remote_src: true dest: /tmp + when: not ansible_check_mode - name: Copy visor binary ansible.builtin.copy: @@ -42,3 +45,4 @@ owner: root group: root mode: '0755' + when: not ansible_check_mode