Skip to content

Commit

Permalink
Improved explorer ansible.
Browse files Browse the repository at this point in the history
  • Loading branch information
samoht9277 committed Dec 10, 2024
1 parent b65d425 commit 44c81a1
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1207,3 +1207,7 @@ ansible_operator_deploy: ## Deploy the Operator. Parameters: INVENTORY
-i $(INVENTORY) \
-e "ecdsa_keystore_path=$(ECDSA_KEYSTORE)" \
-e "bls_keystore_path=$(BLS_KEYSTORE)"

ansible_explorer_deploy:
@ansible-playbook infra/ansible/playbooks/explorer.yaml \
-i $(INVENTORY)
41 changes: 35 additions & 6 deletions infra/ansible/playbooks/explorer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
ansible.builtin.import_playbook: postgres.yaml
vars:
host: explorer
ini_file: ini/config-explorer.ini

- hosts: explorer
- name: Setup Explorer
hosts: explorer
vars:
service: "explorer"

Expand All @@ -31,26 +33,53 @@
ansible_ssh_user: "{{ admin_user }}"

- name: Clone the aligned_layer repository
register: clone_repo
ansible.builtin.git:
repo: https://github.com/yetanotherco/aligned_layer
dest: "{{ ansible_env.HOME }}/aligned_layer"
dest: "/home/{{ ansible_user }}/repos/explorer/aligned_layer"
version: explorer-ssl
update: yes

tasks:
- name: Add environment file for Explorer
template:
src: explorer/explorer_env.j2
dest: /home/{{ ansible_user }}/repos/explorer/aligned_layer/explorer/.env
vars:
RPC_URL: "{{ lookup('ini', 'RPC_URL file=ini/config-explorer.ini') }}"
ENVIRONMENT: "{{ lookup('ini', 'ENVIRONMENT file=ini/config-explorer.ini') }}"
ALIGNED_CONFIG_FILE: "{{ lookup('ini', 'ALIGNED_CONFIG_FILE file=ini/config-explorer.ini') }}"
PHX_HOST: "{{ lookup('ini', 'PHX_HOST file=ini/config-explorer.ini') }}"
ELIXIR_HOSTNAME: "{{ lookup('ini', 'ELIXIR_HOSTNAME file=ini/config-explorer.ini') }}"
DB_NAME: "{{ lookup('ini', 'DB_NAME file=ini/config-explorer.ini') }}"
DB_USER: "{{ lookup('ini', 'DB_USER file=ini/config-explorer.ini') }}"
DB_PASS: "{{ lookup('ini', 'DB_PASS file=ini/config-explorer.ini') }}"
DB_HOST: "{{ lookup('ini', 'DB_HOST file=ini/config-explorer.ini') }}"
TRACKER_API_URL: "{{ lookup('ini', 'TRACKER_API_URL file=ini/config-explorer.ini') }}"
SECRET_KEY_BASE: "{{ lookup('ini', 'SECRET_KEY_BASE file=ini/config-explorer.ini') }}"

- name: Build the explorer release
args:
chdir: "{{ clone_repo.git_dir_now }}"
chdir: "/home/{{ ansible_user }}/repos/explorer/aligned_layer/explorer"
environment:
MIX_ENV: prod
ansible.builtin.shell:
shell:
executable: /bin/bash
cmd: |
set -ex
source .env
mix local.hex --force
mix local.rebar --force
mix deps.get --only $MIX_ENV
mix compile
pnpm --prefix=assets/ install
mix phx.digest
mix assets.deploy
mix release
mix release --overwrite
- name: Set CAP_NET_BIND_SERVICE to beam
shell:
cmd: sudo setcap CAP_NET_BIND_SERVICE=+eip /home/app/repos/explorer/aligned_layer/explorer/_build/prod/rel/explorer/erts-14.2.1/bin/beam.smp
vars:
ansible_ssh_user: "{{ admin_user }}"

# TODO: add systemd service
12 changes: 12 additions & 0 deletions infra/ansible/playbooks/ini/config-explorer.ini.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[global]
RPC_URL=
ENVIRONMENT=
ALIGNED_CONFIG_FILE=
PHX_HOST=
ELIXIR_HOSTNAME=
DB_NAME=
DB_USER=
DB_PASS=
DB_HOST=
TRACKER_API_URL=
SECRET_KEY_BASE=
14 changes: 12 additions & 2 deletions infra/ansible/playbooks/postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
ansible_ssh_user: "{{ admin_user }}"

tasks:

- name: Update apt and install required system packages
become: true
ansible.builtin.apt:
Expand All @@ -21,7 +20,7 @@
path: /usr/share/postgresql-common/pgdg
state: directory
mode: '0755'

- name: Download postgres ca-certificates if not already present
become: true
ansible.builtin.get_url:
Expand All @@ -45,3 +44,14 @@
- postgresql-16
state: latest
update_cache: true

- name: Create PostgreSQL credentials
shell:
cmd: |
sudo -u postgres psql -U postgres -c "CREATE USER {{ DB_USER }} WITH PASSWORD '{{ DB_PASS }}';"
sudo -u postgres psql -U postgres -c "CREATE DATABASE {{ DB_NAME }} OWNER {{ DB_USER }};"
vars:
DB_USER: "{{ lookup('ini', 'DB_USER', file=ini_file) }}"
DB_PASS: "{{ lookup('ini', 'DB_PASS', file=ini_file) }}"
DB_NAME: "{{ lookup('ini', 'DB_NAME', file=ini_file) }}"
ignore_errors: true
15 changes: 15 additions & 0 deletions infra/ansible/playbooks/templates/explorer/explorer_env.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export RPC_URL={{ RPC_URL }}
export ENVIRONMENT={{ ENVIRONMENT }}
export ALIGNED_CONFIG_FILE={{ ALIGNED_CONFIG_FILE }}
export PHX_HOST={{ PHX_HOST }}
export ELIXIR_HOSTNAME={{ ELIXIR_HOSTNAME }}

# Database
export DB_NAME={{ DB_NAME }}
export DB_USER={{ DB_USER }}
export DB_PASS={{ DB_PASS }}
export DB_HOST={{ DB_HOST }}

# Tracker API
export TRACKER_API_URL={{ TRACKER_API_URL }}
export SECRET_KEY_BASE={{ SECRET_KEY_BASE }}
4 changes: 2 additions & 2 deletions infra/ansible/stage_inventory.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ batcher:
explorer:
hosts:
aligned-holesky-explorer:
ansible_host: aligned-holesky-stage-2-explorer
ansible_host: aligned-holesky-stage-1-explorer
admin_user: admin
ansible_user: dev
ansible_user: app
ansible_python_interpreter: /usr/bin/python3
operator:
hosts:
Expand Down

0 comments on commit 44c81a1

Please sign in to comment.