From 44c0894c5337ee7db4b5970d19560eb57c8c371b Mon Sep 17 00:00:00 2001 From: Chris Gianelloni Date: Tue, 14 Nov 2023 10:55:58 -0500 Subject: [PATCH] feat: cardano-node-api Signed-off-by: Chris Gianelloni --- roles/cardano_node_api/README.md | 51 ++++++++++++++++++++++++ roles/cardano_node_api/defaults/main.yml | 34 ++++++++++++++++ roles/cardano_node_api/meta/main.yml | 3 ++ roles/cardano_node_api/tasks/docker.yml | 13 ++++++ roles/cardano_node_api/tasks/main.yml | 23 +++++++++++ 5 files changed, 124 insertions(+) create mode 100644 roles/cardano_node_api/README.md create mode 100644 roles/cardano_node_api/defaults/main.yml create mode 100644 roles/cardano_node_api/meta/main.yml create mode 100644 roles/cardano_node_api/tasks/docker.yml create mode 100644 roles/cardano_node_api/tasks/main.yml diff --git a/roles/cardano_node_api/README.md b/roles/cardano_node_api/README.md new file mode 100644 index 0000000..4951165 --- /dev/null +++ b/roles/cardano_node_api/README.md @@ -0,0 +1,51 @@ +cardano_node_api +========= + +This role deploys a Cardano Node API instance. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should +be mentioned here. For instance, if the role uses the EC2 module, it may be a +good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including +any variables that are in defaults/main.yml, vars/main.yml, and any variables +that can/should be set via parameters to the role. Any variables that are read +from other roles and/or the global scope (ie. hostvars, group vars, etc.) +should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in +regards to parameters that may need to be set for other roles, or variables +that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables +passed in as parameters) is always nice for users too: + +```yaml + - hosts: servers + tasks: + - include_role: + name: blinklabs.cardano.cardano_node_api +``` + +License +------- + +Apache 2.0 + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a +website (HTML is not allowed). diff --git a/roles/cardano_node_api/defaults/main.yml b/roles/cardano_node_api/defaults/main.yml new file mode 100644 index 0000000..22f0a88 --- /dev/null +++ b/roles/cardano_node_api/defaults/main.yml @@ -0,0 +1,34 @@ +--- +# Install method +cardano_node_api_install_method: 'docker' + +# Cardano Submit API version +cardano_node_api_version: 'main' + +# Base host directory for node data +cardano_node_dir: /opt/cardano + +# IPC directory for host/container +cardano_node_ipc_dir: '{{ cardano_node_dir }}/ipc' +cardano_node_api_ipc_container_dir: '/node-ipc' + +# User/group for file/directory ownership +cardano_node_user: root +cardano_node_group: root + +# Docker image +cardano_node_api_docker_image: 'ghcr.io/blinklabs-io/cardano-node-api:{{ cardano_node_api_version }}' + +# Docker container name +cardano_node_api_docker_container_name: cardano-node-api + +# Port for host/container +cardano_node_api_container_port: 8080 +cardano_node_api_port: '{{ cardano_node_api_container_port }}' + +# Metrics port for host/container +cardano_node_api_metrics_container_port: 8081 +cardano_node_api_metrics_port: '{{ cardano_node_api_metrics_container_port }}' + +# Cardano network +cardano_node_api_network: mainnet diff --git a/roles/cardano_node_api/meta/main.yml b/roles/cardano_node_api/meta/main.yml new file mode 100644 index 0000000..e8fe48d --- /dev/null +++ b/roles/cardano_node_api/meta/main.yml @@ -0,0 +1,3 @@ +galaxy_info: {} + +dependencies: [] diff --git a/roles/cardano_node_api/tasks/docker.yml b/roles/cardano_node_api/tasks/docker.yml new file mode 100644 index 0000000..e1f3e66 --- /dev/null +++ b/roles/cardano_node_api/tasks/docker.yml @@ -0,0 +1,13 @@ +--- +- name: Create container + docker_container: + name: '{{ cardano_node_api_docker_container_name }}' + image: '{{ cardano_node_api_docker_image }}' + restart_policy: unless-stopped + ports: + - '{{ cardano_node_api_port }}:{{ cardano_node_api_container_port }}' + - '{{ cardano_node_api_metrics_port }}:{{ cardano_node_api_metrics_container_port }}' + env: + CARDANO_NETWORK: '{{ cardano_node_api_network }}' + volumes: + - '{{ cardano_node_ipc_dir }}:{{ cardano_node_api_ipc_container_dir }}' diff --git a/roles/cardano_node_api/tasks/main.yml b/roles/cardano_node_api/tasks/main.yml new file mode 100644 index 0000000..0a4a829 --- /dev/null +++ b/roles/cardano_node_api/tasks/main.yml @@ -0,0 +1,23 @@ +--- +- name: Check install method + vars: + _allowed_install_methods: ['docker'] + ansible.builtin.assert: + that: + - cardano_node_api_install_method in _allowed_install_methods + fail_msg: 'The specified install method ({{ cardano_node_api_install_method }}) is not one of the allowed values ({{ _allowed_install_methods | join(", ") }})' + +# We use the node owner and group +- name: Create directories + ansible.builtin.file: + state: directory + path: '{{ item }}' + owner: '{{ cardano_node_user }}' + group: '{{ cardano_node_group }}' + mode: '0755' + loop: + - '{{ cardano_node_ipc_dir }}' + +- name: Include docker-related tasks + ansible.builtin.include_tasks: docker.yml + when: cardano_node_api_install_method == 'docker'