Skip to content
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
65facbf
Adapt elixir playbook to admin_user var usage
klaus993 Nov 19, 2024
4f7a523
Use sudo and verbose builtin
klaus993 Nov 19, 2024
4d022ee
Remove ubuntu packages
klaus993 Nov 19, 2024
0f12ea5
Remove java
klaus993 Nov 19, 2024
7f5e43b
Install libssl1.1 (erlang dependency)
klaus993 Nov 19, 2024
17c13c7
Install Erlang globally (without asdf)
klaus993 Nov 19, 2024
10ddfcf
Install Elixir globally (without asdf)
klaus993 Nov 19, 2024
3175192
Add name to setup.yaml playbook
klaus993 Nov 19, 2024
a0e5cd7
Add Nodejs playbook
klaus993 Nov 19, 2024
c7048b0
Add PostgreSQL playbook
klaus993 Nov 19, 2024
7e3b29c
Migrate to another way of importing playbooks
klaus993 Nov 19, 2024
8144463
Uncomment explorer in inventory
klaus993 Nov 19, 2024
9686e28
Fix gitignore
klaus993 Nov 26, 2024
33c7059
Ran mix phx.gen.release
klaus993 Nov 26, 2024
d01e9d1
Adapt to new way of sending user
klaus993 Nov 26, 2024
efb20e5
Clone aligned repository
klaus993 Nov 26, 2024
a9fac2c
Add pnpm and explorer build
klaus993 Nov 29, 2024
beca81b
Added Caddyfile creation for explorer, added cloudflare API token.
samoht9277 Dec 2, 2024
98a39b7
Added caddy build with Cloudflare DNS module.
samoht9277 Dec 2, 2024
90115d6
Added small fixes to check if nodejs is installed.
samoht9277 Dec 3, 2024
b65d425
Remoded Caddy.
samoht9277 Dec 9, 2024
44c81a1
Improved explorer ansible.
samoht9277 Dec 10, 2024
6e64720
Added systemd service to run the explorer.
samoht9277 Dec 16, 2024
f170bbf
Removed extra whitespace.
samoht9277 Dec 16, 2024
050ea6e
Merge branch 'testnet' into explorer_ansible
samoht9277 Jan 3, 2025
40c10dd
Removed file.
samoht9277 Jan 3, 2025
3de7549
Merge branch 'explorer_ansible' of github.com:yetanotherco/aligned_la…
samoht9277 Jan 3, 2025
d6d7da8
Added missing variables and UFW rule.
samoht9277 Jan 6, 2025
cb3b8ff
Merge branch 'testnet' into explorer_ansible
JuArce Jan 10, 2025
82e6a1d
fix: add ecto migrate
JuArce Mar 19, 2025
1ecf17e
Merge branch 'refs/heads/staging' into explorer_ansible
JuArce Mar 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ config-files/*.last_processed_batch.json
nonce_*.bin

infra/ansible/playbooks/ini/**.ini
infra/ansible/playbooks/files/**.pem
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1208,3 +1208,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)
2 changes: 1 addition & 1 deletion explorer/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ explorer-*.tar

# In case you use Node.js/npm, you want to ignore these.
npm-debug.log
/assets/node_modules/
assets/node_modules/

# Environment Variables
/.env
Expand Down
28 changes: 28 additions & 0 deletions explorer/lib/explorer/release.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
defmodule Explorer.Release do
@moduledoc """
Used for executing DB release tasks when run in production without Mix
installed.
"""
@app :explorer

def migrate do
load_app()

for repo <- repos() do
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
end
end

def rollback(repo, version) do
load_app()
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
end

defp repos do
Application.fetch_env!(@app, :ecto_repos)
end

defp load_app do
Application.load(@app)
end
end
5 changes: 5 additions & 0 deletions explorer/rel/overlays/bin/migrate
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
set -eu

cd -P -- "$(dirname -- "$0")"
exec ./explorer eval Explorer.Release.migrate
1 change: 1 addition & 0 deletions explorer/rel/overlays/bin/migrate.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
call "%~dp0\explorer" eval Explorer.Release.migrate
5 changes: 5 additions & 0 deletions explorer/rel/overlays/bin/server
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
set -eu

cd -P -- "$(dirname -- "$0")"
PHX_SERVER=true exec ./explorer start
2 changes: 2 additions & 0 deletions explorer/rel/overlays/bin/server.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set PHX_SERVER=true
call "%~dp0\explorer" start
105 changes: 67 additions & 38 deletions infra/ansible/playbooks/elixir.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
- name: Elixir Setup
hosts: all
become: true
hosts: "{{ host }}"

vars:
user: "{{ user }}"
erlang_version: 26.0
elixir_version: 1.16.2-otp-26
ansible_ssh_user: "{{ admin_user }}"

tasks:
# Install required packages
- name: Update apt and install required system packages
apt:
become: true
ansible.builtin.apt:
pkg:
- build-essential
- autoconf
- m4
- libncurses5-dev
- libwxgtk3.0-gtk3-dev
- libwxgtk-webview3.0-gtk3-dev
- libgl1-mesa-dev
- libglu1-mesa-dev
- libpng-dev
Expand All @@ -26,44 +23,76 @@
- fop
- libxml2-utils
- libncurses-dev
- openjdk-11-jdk
state: latest
update_cache: true

- name: Clone asdf repository into ~/.asdf
ansible.builtin.git:
name: https://github.com/asdf-vm/asdf.git
dest: ~/.asdf
single_branch: yes
version: v0.14.0
become_user: "{{ user }}"
########## Install libssl1.1 ##########
- name: Check if libssl1.1 is installed
become: true
ansible.builtin.shell:
cmd: dpkg -l | grep libssl1.1
register: libssl_check
changed_when: false
failed_when: libssl_check.rc not in [0, 1]

- name: Insert lines to ~/.bashrc to source asdf
ansible.builtin.blockinfile:
path: "/home/{{ user }}/.bashrc"
block: |
. "$HOME/.asdf/asdf.sh"
. "$HOME/.asdf/completions/asdf.bash"
become_user: "{{ user }}"
- name: Download libssl1.1
become: true
register: download_libssl
ansible.builtin.get_url:
url: http://ftp.de.debian.org/debian/pool/main/o/openssl/libssl1.1_1.1.1w-0+deb11u1_amd64.deb
dest: /root/
when: libssl_check.rc != 0

# - name: Add asdf to the shell
# shell: export ASDF_DIR="$HOME/.asdf" && . ~/.asdf/asdf.sh
# become_user: "{{ user }}"
- name: Install libssl1.1
become: true
ansible.builtin.apt:
deb: "{{ download_libssl.dest }}"
when: libssl_check.rc != 0

- name: Add Erlang plugin to asdf
shell: asdf plugin add erlang
########## Install Erlang 26.2.1-1 ##########
- name: Check if Erlang 26.2.1-1 is installed
become: true
ansible.builtin.shell:
cmd: dpkg -l | grep esl-erlang
register: erlang_check
changed_when: false
failed_when: erlang_check.rc not in [0, 1]

- name: Add Erlang version to asdf
shell: asdf install erlang {{ erlang_version }}
- name: Download Erlang 26.2.1-1
become: true
register: download_erlang
ansible.builtin.get_url:
url: https://binaries2.erlang-solutions.com/debian/pool/contrib/e/esl-erlang/esl-erlang_26.2.1-1~debian~bullseye_amd64.deb
dest: /root/
when: erlang_check.rc != 0

- name: Set Erlang version as global
shell: asdf global erlang {{ erlang_version }}
- name: Install Erlang 26.2.1-1
become: true
ansible.builtin.apt:
deb: "{{ download_erlang.dest }}"
when: erlang_check.rc != 0

- name: Add Elixir plugin to asdf
shell: asdf plugin add elixir
########## Install Elixir v1.16.2-otp-26 ##########
- name: Check if Elixir v1.16.2 is installed
become: true
ansible.builtin.shell:
cmd: elixir --version | grep "Elixir 1.16.2"
register: elixir_check
changed_when: false
failed_when: elixir_check.rc not in [0, 1]

- name: Add Elixir version to asdf
shell: asdf install elixir {{ elixir_version }}
- name: Download Elixir v1.16.2-otp-26
become: true
register: download_elixir
ansible.builtin.get_url:
url: https://github.com/elixir-lang/elixir/releases/download/v1.16.2/elixir-otp-26.zip
dest: /root/
when: elixir_check.rc != 0

- name: Set Elixir version as global
shell: asdf global elixir {{ elixir_version }}
- name: Install Elixir v1.16.2-otp-26
become: true
ansible.builtin.unarchive:
remote_src: true
src: "{{ download_elixir.dest }}"
dest: /usr/local/
when: elixir_check.rc != 0
160 changes: 124 additions & 36 deletions infra/ansible/playbooks/explorer.yaml
Original file line number Diff line number Diff line change
@@ -1,43 +1,131 @@
- import_playbook: setup.yaml
- import_playbook: webserver.yaml
#- import_playbook: elixir.yaml # Not working
#- import_playbook: docker.yaml
- name: Run setup playbook
ansible.builtin.import_playbook: setup.yaml
vars:
host: explorer

- name: Run elixir playbook
ansible.builtin.import_playbook: elixir.yaml
vars:
host: explorer

- name: Run nodejs playbook
ansible.builtin.import_playbook: nodejs.yaml
vars:
host: explorer

- hosts: aligned-holesky-explorer
become: true
- name: Run postgres playbook
ansible.builtin.import_playbook: postgres.yaml
vars:
user: "{{ user }}"
host: explorer
ini_file: ini/config-explorer.ini

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

pre_tasks:
- name: Install pnpm
become: true
ansible.builtin.shell:
cmd: npm install -g pnpm
vars:
ansible_ssh_user: "{{ admin_user }}"

- name: Allow all access to tcp port 443
become: true
ufw:
rule: allow
port: 443
proto: tcp
vars:
ansible_ssh_user: "{{ admin_user }}"

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

- name: Create .ssl directory
file:
path: /home/{{ ansible_user }}/.ssl/
state: directory

- name: Upload SSL key to server (infra/ansible/playbooks/files/key.pem)
copy:
src: key.pem
dest: /home/{{ ansible_user }}/.ssl/key.pem

- name: Upload SSL certificate to server (infra/ansible/playbooks/files/cert.pem)
copy:
src: cert.pem
dest: /home/{{ ansible_user }}/.ssl/cert.pem

tasks:
# Install required packages
- name: Update apt and install required system packages
apt:
pkg:
- unzip
state: latest
update_cache: true

# Create directories for each service
- name: Create directories for each service if do not exist
ansible.builtin.file:
path: /home/{{ user }}/repos/{{ item }}
- 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') }}"
KEYFILE_PATH: "{{ lookup('ini', 'KEYFILE_PATH file=ini/config-explorer.ini') }}"
CERTFILE_PATH: "{{ lookup('ini', 'CERTFILE_PATH file=ini/config-explorer.ini') }}"
BATCH_TTL_MINUTES: "{{ lookup('ini', 'BATCH_TTL_MINUTES file=ini/config-explorer.ini') }}"
SCHEDULED_BATCH_INTERVAL_MINUTES: "{{ lookup('ini', 'SCHEDULED_BATCH_INTERVAL_MINUTES file=ini/config-explorer.ini') }}"

- name: Build the explorer release
args:
chdir: "/home/{{ ansible_user }}/repos/explorer/aligned_layer/explorer"
environment:
MIX_ENV: prod
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 --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 }}"

- name: Create .env for Explorer systemd service
shell: cat /home/{{ ansible_user }}/repos/explorer/aligned_layer/explorer/.env | sed 's/export //g' > /home/{{ ansible_user }}/config/.env.explorer

- name: Create systemd services directory
file:
path: "/home/{{ ansible_user }}/.config/systemd/user/"
state: directory
mode: '0755'
become_user: "{{ user }}"
loop:
- explorer

# Clone Aligned repository for each service
- name: Clone Aligned repository
ansible.builtin.git:
repo: https://github.com/yetanotherco/aligned_layer.git
dest: /home/{{ user }}/repos/{{ item }}/aligned_layer
version: v0.10.2
become_user: "{{ user }}"
loop:
- explorer
register: repo_clone
failed_when:
- repo_clone.failed
- not 'Local modifications exist in the destination' in repo_clone.msg
- name: Add service to systemd
template:
src: services/explorer.service.j2
dest: "/home/{{ ansible_user }}/.config/systemd/user/explorer.service"
force: no

- name: Start explorer service
systemd_service:
name: explorer
state: started
enabled: true
scope: user
14 changes: 14 additions & 0 deletions infra/ansible/playbooks/ini/config-explorer.ini.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[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=
KEYFILE_PATH=
CERTFILE_PATH=
Loading