Skip to content

Commit

Permalink
Merge pull request #36 from blinklabs-io/feat-add-role-for-deploying-…
Browse files Browse the repository at this point in the history
…snek
  • Loading branch information
verbotenj authored Dec 5, 2023
2 parents d7482b4 + b4a3303 commit 31f13eb
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 0 deletions.
50 changes: 50 additions & 0 deletions roles/snek/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Snek
=========

This role deploys an Snek 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.snek
```
License
-------
Apache 2.0
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
47 changes: 47 additions & 0 deletions roles/snek/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
# Install method
snek_install_method: 'docker'

# Snek version
snek_version: '0.15.0'

# Base host directory for node data
cardano_node_dir: /opt/cardano

# DB directory for host/container
snek_db_dir: '{{ cardano_node_dir }}/snek'

# Config directory for host/container
cardano_node_config_dir: '{{ cardano_node_dir }}/config'
snek_config_container_dir: '{{ cardano_node_config_dir }}'

# IPC directory for host/container
cardano_node_ipc_dir: '{{ cardano_node_dir }}/ipc'
snek_ipc_container_dir: '/node-ipc'

# User/group for file/directory ownership
cardano_node_user: root
cardano_node_group: root

# Docker image
snek_docker_image: 'ghcr.io/blinklabs-io/snek:{{ snek_version }}'

# Docker container name
snek_docker_container_name: snek

# Port for host/container
snek_container_port: 8080
snek_port: '{{ snek_container_port }}'

# Cardano network
snek_network: mainnet

cardano_node_socket_name: node.socket

# snek arguments (defaults to everything)
snek_arguments:
# Local node
# - '-v'
# - '{{ cardano_node_ipc_dir }}:{{ snek_ipc_container_dir }}'
- '-input-chainsync-network'
- '{{ snek_network }}'
3 changes: 3 additions & 0 deletions roles/snek/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
galaxy_info: {}

dependencies: []
19 changes: 19 additions & 0 deletions roles/snek/tasks/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Initialize snek_docker_volumes fact
set_fact:
snek_docker_volumes: '{{ snek_docker_volumes | default([]) + [item] }}'
loop:
- '{{ cardano_node_ipc_dir }}:{{ snek_ipc_container_dir }}'

- name: Create container
docker_container:
name: '{{ snek_docker_container_name }}'
image: '{{ snek_docker_image }}'
restart_policy: unless-stopped
command:
- "{{ snek_arguments | default([]) }}"
ports:
- '{{ snek_port }}:{{ snek_container_port }}'
env:
CARDANO_NETWORK: '{{ snek_network }}'
volumes: '{{ snek_docker_volumes | list }}'
26 changes: 26 additions & 0 deletions roles/snek/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- name: Echo Snek
command: echo "hello snek"

- name: Check install method
vars:
_allowed_install_methods: ['docker']
ansible.builtin.assert:
that:
- snek_install_method in _allowed_install_methods
fail_msg: 'The specified install method ({{ snek_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: snek_install_method == 'docker'

0 comments on commit 31f13eb

Please sign in to comment.