Skip to content

Commit 44c81a1

Browse files
committed
Improved explorer ansible.
1 parent b65d425 commit 44c81a1

6 files changed

Lines changed: 80 additions & 10 deletions

File tree

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,3 +1207,7 @@ ansible_operator_deploy: ## Deploy the Operator. Parameters: INVENTORY
12071207
-i $(INVENTORY) \
12081208
-e "ecdsa_keystore_path=$(ECDSA_KEYSTORE)" \
12091209
-e "bls_keystore_path=$(BLS_KEYSTORE)"
1210+
1211+
ansible_explorer_deploy:
1212+
@ansible-playbook infra/ansible/playbooks/explorer.yaml \
1213+
-i $(INVENTORY)

infra/ansible/playbooks/explorer.yaml

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
ansible.builtin.import_playbook: postgres.yaml
1818
vars:
1919
host: explorer
20+
ini_file: ini/config-explorer.ini
2021

21-
- hosts: explorer
22+
- name: Setup Explorer
23+
hosts: explorer
2224
vars:
2325
service: "explorer"
2426

@@ -31,26 +33,53 @@
3133
ansible_ssh_user: "{{ admin_user }}"
3234

3335
- name: Clone the aligned_layer repository
34-
register: clone_repo
3536
ansible.builtin.git:
3637
repo: https://github.com/yetanotherco/aligned_layer
37-
dest: "{{ ansible_env.HOME }}/aligned_layer"
38+
dest: "/home/{{ ansible_user }}/repos/explorer/aligned_layer"
39+
version: explorer-ssl
3840
update: yes
3941

4042
tasks:
43+
- name: Add environment file for Explorer
44+
template:
45+
src: explorer/explorer_env.j2
46+
dest: /home/{{ ansible_user }}/repos/explorer/aligned_layer/explorer/.env
47+
vars:
48+
RPC_URL: "{{ lookup('ini', 'RPC_URL file=ini/config-explorer.ini') }}"
49+
ENVIRONMENT: "{{ lookup('ini', 'ENVIRONMENT file=ini/config-explorer.ini') }}"
50+
ALIGNED_CONFIG_FILE: "{{ lookup('ini', 'ALIGNED_CONFIG_FILE file=ini/config-explorer.ini') }}"
51+
PHX_HOST: "{{ lookup('ini', 'PHX_HOST file=ini/config-explorer.ini') }}"
52+
ELIXIR_HOSTNAME: "{{ lookup('ini', 'ELIXIR_HOSTNAME file=ini/config-explorer.ini') }}"
53+
DB_NAME: "{{ lookup('ini', 'DB_NAME file=ini/config-explorer.ini') }}"
54+
DB_USER: "{{ lookup('ini', 'DB_USER file=ini/config-explorer.ini') }}"
55+
DB_PASS: "{{ lookup('ini', 'DB_PASS file=ini/config-explorer.ini') }}"
56+
DB_HOST: "{{ lookup('ini', 'DB_HOST file=ini/config-explorer.ini') }}"
57+
TRACKER_API_URL: "{{ lookup('ini', 'TRACKER_API_URL file=ini/config-explorer.ini') }}"
58+
SECRET_KEY_BASE: "{{ lookup('ini', 'SECRET_KEY_BASE file=ini/config-explorer.ini') }}"
59+
4160
- name: Build the explorer release
4261
args:
43-
chdir: "{{ clone_repo.git_dir_now }}"
62+
chdir: "/home/{{ ansible_user }}/repos/explorer/aligned_layer/explorer"
4463
environment:
4564
MIX_ENV: prod
46-
ansible.builtin.shell:
65+
shell:
66+
executable: /bin/bash
4767
cmd: |
4868
set -ex
69+
source .env
4970
mix local.hex --force
5071
mix local.rebar --force
5172
mix deps.get --only $MIX_ENV
5273
mix compile
5374
pnpm --prefix=assets/ install
5475
mix phx.digest
5576
mix assets.deploy
56-
mix release
77+
mix release --overwrite
78+
79+
- name: Set CAP_NET_BIND_SERVICE to beam
80+
shell:
81+
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
82+
vars:
83+
ansible_ssh_user: "{{ admin_user }}"
84+
85+
# TODO: add systemd service
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[global]
2+
RPC_URL=
3+
ENVIRONMENT=
4+
ALIGNED_CONFIG_FILE=
5+
PHX_HOST=
6+
ELIXIR_HOSTNAME=
7+
DB_NAME=
8+
DB_USER=
9+
DB_PASS=
10+
DB_HOST=
11+
TRACKER_API_URL=
12+
SECRET_KEY_BASE=

infra/ansible/playbooks/postgres.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
ansible_ssh_user: "{{ admin_user }}"
66

77
tasks:
8-
98
- name: Update apt and install required system packages
109
become: true
1110
ansible.builtin.apt:
@@ -21,7 +20,7 @@
2120
path: /usr/share/postgresql-common/pgdg
2221
state: directory
2322
mode: '0755'
24-
23+
2524
- name: Download postgres ca-certificates if not already present
2625
become: true
2726
ansible.builtin.get_url:
@@ -45,3 +44,14 @@
4544
- postgresql-16
4645
state: latest
4746
update_cache: true
47+
48+
- name: Create PostgreSQL credentials
49+
shell:
50+
cmd: |
51+
sudo -u postgres psql -U postgres -c "CREATE USER {{ DB_USER }} WITH PASSWORD '{{ DB_PASS }}';"
52+
sudo -u postgres psql -U postgres -c "CREATE DATABASE {{ DB_NAME }} OWNER {{ DB_USER }};"
53+
vars:
54+
DB_USER: "{{ lookup('ini', 'DB_USER', file=ini_file) }}"
55+
DB_PASS: "{{ lookup('ini', 'DB_PASS', file=ini_file) }}"
56+
DB_NAME: "{{ lookup('ini', 'DB_NAME', file=ini_file) }}"
57+
ignore_errors: true
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export RPC_URL={{ RPC_URL }}
2+
export ENVIRONMENT={{ ENVIRONMENT }}
3+
export ALIGNED_CONFIG_FILE={{ ALIGNED_CONFIG_FILE }}
4+
export PHX_HOST={{ PHX_HOST }}
5+
export ELIXIR_HOSTNAME={{ ELIXIR_HOSTNAME }}
6+
7+
# Database
8+
export DB_NAME={{ DB_NAME }}
9+
export DB_USER={{ DB_USER }}
10+
export DB_PASS={{ DB_PASS }}
11+
export DB_HOST={{ DB_HOST }}
12+
13+
# Tracker API
14+
export TRACKER_API_URL={{ TRACKER_API_URL }}
15+
export SECRET_KEY_BASE={{ SECRET_KEY_BASE }}

infra/ansible/stage_inventory.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ batcher:
1515
explorer:
1616
hosts:
1717
aligned-holesky-explorer:
18-
ansible_host: aligned-holesky-stage-2-explorer
18+
ansible_host: aligned-holesky-stage-1-explorer
1919
admin_user: admin
20-
ansible_user: dev
20+
ansible_user: app
2121
ansible_python_interpreter: /usr/bin/python3
2222
operator:
2323
hosts:

0 commit comments

Comments
 (0)