diff --git a/Vagrantfile b/Vagrantfile index 1d48dfc..448d638 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -3,7 +3,7 @@ ENV["LC_ALL"] = "en_US.UTF-8" Vagrant.configure("2") do |config| - servers = [ "validator", "explorer", "moc", "bootnode", "netstat" ] + servers = [ "validator", "explorer", "moc", "bootnode", "netstat", "blockscout" ] platform_os = ENV["poa_platform"] if platform_os == "ubuntu" @@ -19,6 +19,10 @@ Vagrant.configure("2") do |config| node.vm.box = platform node.vm.hostname = machine + if machine == "blockscout" + node.vm.network "forwarded_port", guest: 4000, host: 4001 + end + node.vm.provision :ansible do |ansible| ansible.compatibility_mode = "2.0" ansible.playbook = "site.yml" @@ -28,8 +32,9 @@ Vagrant.configure("2") do |config| "netstat" => ["netstat"], "moc" => ["moc"], "bootnode" => ["bootnode"], + "blockscout" => ["blockscout"], } - ansible.groups[platform_os] = [ "validator", "explorer", "netstat", "moc", "bootnode" ] + ansible.groups[platform_os] = [ "validator", "explorer", "netstat", "moc", "bootnode", "blockscout" ] end node.vm.provision :shell do |shell| diff --git a/blockscout.yml b/blockscout.yml new file mode 100644 index 0000000..0918240 --- /dev/null +++ b/blockscout.yml @@ -0,0 +1,4 @@ +- hosts: blockscout + become: True + roles: + - blockscout \ No newline at end of file diff --git a/group_vars/blockscout.yml.example b/group_vars/blockscout.yml.example new file mode 100644 index 0000000..02cbfc5 --- /dev/null +++ b/group_vars/blockscout.yml.example @@ -0,0 +1,16 @@ +username: "blockscout" +users: +- name: "{{ username }}" +home: "/home/{{ username }}" + +nginx_headers: "off" +PROXY_PORT: "3000" +configure_extended_tcp_settings: false + +install_debug_tools: "yes" +reboot_after_completion: false + +blockscout_version: "master" +postgres_password: "dhu4Hfdlllf2htHYbjeeuhy34" +db_user: "blockscout" +db_user_password: "dvYYTbhdhuuOLMf74ghu" diff --git a/roles/blockscout/defaults/main.yml b/roles/blockscout/defaults/main.yml new file mode 100644 index 0000000..2df240b --- /dev/null +++ b/roles/blockscout/defaults/main.yml @@ -0,0 +1,27 @@ +--- + +user: ubuntu + +allow_explorer_ssh: true +allow_explorer_p2p: true +allow_explorer_http: true + +username: "blockscout" +users: +- name: "{{ username }}" +home: "/home/{{ username }}" + +nginx_headers: "off" +PROXY_PORT: "3000" + +MAIN_REPO_FETCH: "poanetwork" +MOC_ADDRESS: "0xdd0bb0e2a1594240fed0c2f2c17c1e9ab4f87126" + +reboot_after_completion: false +install_debug_tools: "no" +install_firewall: false + +blockscout_version: "master" +postgres_password: "dhu4Hfdlllf2htHYbjeeuhy34" +db_user: "blockscout" +db_user_password: "dvYYTbhdhuuOLMf74ghu" \ No newline at end of file diff --git a/roles/blockscout/meta/main.yml b/roles/blockscout/meta/main.yml new file mode 100644 index 0000000..abfbd48 --- /dev/null +++ b/roles/blockscout/meta/main.yml @@ -0,0 +1,9 @@ +dependencies: +- { role: usermanager } +- { role: preconf } +- { role: nodejs } +- { role: poa-logrotate } +- { role: poa-parity } +- { role: poa-pm2 } +- { role: nginx } +- { role: debug-tools, when: "install_debug_tools == 'yes'" } diff --git a/roles/blockscout/tasks/main.yml b/roles/blockscout/tasks/main.yml new file mode 100644 index 0000000..192a6f4 --- /dev/null +++ b/roles/blockscout/tasks/main.yml @@ -0,0 +1,89 @@ +--- + +- name: Add ubuntu/erlang_solutions signing key + apt_key: + url: https://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc + state: present + +- name: Add erlang-solutions repository into sources list + apt_repository: + repo: deb https://packages.erlang-solutions.com/ubuntu xenial contrib + state: present + +- name: Install erlang and elixir + apt: + pkg: "{{ item }}" + state: present + update_cache: yes + cache_valid_time: 3600 + with_items: + - esl-erlang + - elixir + +- name: Add PostgreSQL signing key + become: True + shell: wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | apt-key add - + +- name: Add PostgreSQL into sources list + become: True + shell: sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list' + +- name: Install PostgreSQL + become: True + shell: apt-get update && apt-get install postgresql postgresql-contrib -y + +- name: Install tools + apt: + pkg: "{{ item }}" + state: present + update_cache: yes + cache_valid_time: 3600 + with_items: + - automake + - libtool + - libpng-dev + - zlib1g-dev + +- name: Clone poanetwork/blockscout repo from GitHub + git: + repo: "https://github.com/{{ MAIN_REPO_FETCH }}/blockscout" + dest: "{{ home }}/blockscout" + version: "{{ blockscout_version }}" + +- name: Add explorer dev.secret + template: + src: dev.secret.j2 + dest: "{{ home }}/blockscout/apps/explorer/config/dev.secret.exs" + +- name: Add block_scout_web dev.secret + shell: cp {{ home }}/blockscout/apps/block_scout_web/config/dev.secret.exs.example {{ home }}/blockscout/apps/block_scout_web/config/dev.secret.exs + +- name: Install dependencies + shell: cd {{ home }}/blockscout && mix local.hex --force && mix do deps.get, local.rebar --force, deps.compile, compile + +- name: Change postgres password + shell: sudo -u postgres psql -c "alter user postgres with encrypted password '{{ postgres_password }}';" + +- name: Create db user + shell: sudo -u postgres psql -c "create user {{ db_user }};" + +- name: Make db user a superuser + shell: sudo -u postgres psql -c "alter user {{ db_user }} with superuser;" + +- name: Set password for db user + shell: sudo -u postgres psql -c "alter user {{ db_user }} with encrypted password '{{ db_user_password }}';" + +- name: Create db + shell: cd {{ home }}/blockscout && mix do ecto.create, ecto.migrate + +- name: Install node dependensies in the apps/block_scout_web + shell: cd {{ home }}/blockscout/apps/block_scout_web/assets && npm install; cd - + +- name: Install node-sass + shell: cd {{ home }}/blockscout/apps/block_scout_web/assets && npm install node-sass --unsafe-perm; cd - + +- name: Install node dependensies in the apps/explorer + shell: cd {{ home }}/blockscout/apps/explorer && npm install; cd - + +- name: Start server + shell: cd {{ home }}/blockscout && mix phx.server diff --git a/roles/blockscout/templates/dev.secret.j2 b/roles/blockscout/templates/dev.secret.j2 new file mode 100644 index 0000000..69de1ec --- /dev/null +++ b/roles/blockscout/templates/dev.secret.j2 @@ -0,0 +1,6 @@ +use Mix.Config + +config :explorer, Explorer.Repo, + username: "{{ db_user }}", + password: "{{ db_user_password }}" + diff --git a/site.yml b/site.yml index ef373b7..cf06bea 100644 --- a/site.yml +++ b/site.yml @@ -17,3 +17,7 @@ - name: Validator deployment import_playbook: validator.yml tags: validator + +- name: Blockscout deployment + import_playbook: blockscout.yml + tags: blockscout diff --git a/tests/blockscout.sh b/tests/blockscout.sh new file mode 100755 index 0000000..a96f3ea --- /dev/null +++ b/tests/blockscout.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +echo "This is a stub for blockscout integration tests" \ No newline at end of file