SilentNotaryEcosystem / Cil-core

Network repository.
18 stars 18 forks source link

Master Node Setup Automation #27

Open adamjk-dev opened 3 years ago

adamjk-dev commented 3 years ago

Should we consider building a Vagrantfile/vagrant box to have the setup and pre-configuration done. So, someone can run the vagrant box and then add their keystore information and run the docker image then?

That way, the master node could be run on Windows/Linux via Vagrant and the configuration would be handled?

Let me know.

trueshura commented 3 years ago

If you see a reason to use Vagrant - you can create Vagrantfile and other related stuff. And we'll add it to repo, after tests. I have no experience with it at all.

adamjk-dev commented 3 years ago

Vagrant is a CLI tool for talking to hypervisors (like VirtualBox, VMWare Fusion, among many others). The idea would be that you could use a Vagrantfile and have a user stand up a master node on Linux/Windows/etc. from the same base box.

I have a sample Vagrantfile that gets you to step 13 (minus swap space) on the following: https://ubix.wiki/index.php/Launch_a_Masternode

Then, the user would just copy in their Keystore info etc. and run the Docker container.

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  # The box to start from
  config.vm.box = "generic/ubuntu2004"
  config.vm.define "ubixmaster"
  config.vm.hostname = "ubixmaster"

  # Port forwarding section
  # config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a forwarded port mapping
  # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"

  # Create a private network, which allows host-only access to the machine
  # config.vm.network "private_network", ip: "192.168.33.10"

  # Create a public network, which generally matched to bridged network.
  # config.vm.network "public_network"

  # Share an additional folder to the guest VM.
  # config.vm.synced_folder "../data", "/vagrant_data"

  # VirtualBox specific configs
  config.vm.provider "virtualbox" do |vb|
      # Display the VirtualBox GUI when booting the machine
      vb.gui = true

      # Machine name
      vb.name = "ubixmaster"

      # Customize the amount of memory and CPU on the VM:
      vb.memory = "4096"
      vb.cpus = 2
  end

  # Provision the machine and configure it
  config.vm.provision "shell", inline: <<-SHELL
      # Update
      sudo apt-get update

      # Dependent packages
      sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common

      # Repo def
      sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
      sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"

      # Update
      sudo apt-get update

      # Install Docker Community Edition
      sudo apt-get -y install docker-ce

      # Pull master node Docker image
      sudo docker pull trueshura/cil-core-prod

      # Pull helper scripts and untar
      wget -t0 -c https://github.com/SilentNotaryEcosystem/Cil-core/releases/download/v0.7.0-staging/docker-scripts.tgz
      tar fxz docker-scripts.tgz

      # Firewall
      sudo ufw status
      sudo ufw allow 8223
      sudo ufw status
  SHELL
end
  1. You install Vagrant
  2. You install VirtualBox
  3. You drop the Vagrantfile in a directory
  4. You type "vagrant up", let it provision from the Ubuntu 20.04 box, do provisioning customizations, etc.
  5. You type "vagrant ssh" and get into the box and move on from step 13

If you would like to test it out have at it, or I can submit a PR with the Vagrantfile. I think we should also consider a test script to ensure the node will join the concilium as well (so one can validate their master node before joining). The easier it is to stand up a master node and validate it, the more people will. I am happy to help with these items, but we would need a test "keystore" to put in the sample.pk to test with before dropping in the user's info.

adamjk-dev commented 3 years ago

Or another option, to use a bash starter to install Ansible, then use an Ansible playbook to configure the master node:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  # The box to start from
  config.vm.box = "generic/ubuntu2004"
  config.vm.define "ubixmaster"
  config.vm.hostname = "ubixmaster"

  # Port forwarding section
  # config.vm.network "forwarded_port", guest: 8222, host: 8222
  # Create a forwarded port mapping
  # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
  # Create a private network, which allows host-only access to the machine
  # config.vm.network "private_network", ip: "192.168.33.10"
  # Create a public network, which generally matched to bridged network.
  # config.vm.network "public_network"
  # Share an additional folder to the guest VM.
  # config.vm.synced_folder "../data", "/vagrant_data"

  # VirtualBox specific configs
  config.vm.provider "virtualbox" do |vb|
    # Display the VirtualBox GUI when booting the machine
    vb.gui = true

    # Machine name
    vb.name = "ubixmaster"

    # Customize the amount of memory and CPU on the VM:
    vb.memory = "4096"
    vb.cpus = 2
  end

  # Sync local folder to /vagrant so Ansible playbook can be found to run locally
  config.vm.synced_folder ".", "/vagrant"

  # Shell provisioner updates and installs Ansible
  config.vm.provision "shell", before: "ansible_local", inline: <<-SHELL
    sudo apt update
    sudo apt-get -y install software-properties-common
    sudo apt-add-repository --yes --update ppa:ansible/ansible
    sudo apt-get -y install ansible
  SHELL

  # Run ansible locally to provision the machine
  config.vm.provision "ansible_local" do |ansible|
    ansible.become = true
    ansible.playbook = "ubix-master-dependencies.yml"
  end
end
---
- hosts: all
  name: Master Node Customizations

  tasks:
  - name: Install required packages
    apt:
      pkg:
      - apt-transport-https 
      - ca-certificates 
      - curl 
      - gnupg-agent
      - software-properties-common

  - name: Add Docker GPG key
    apt_key:
      url: https://download.docker.com/linux/ubuntu/gpg

  - name: Add Docker Ubuntu Apt Repo
    apt_repository:
      repo: "deb [arch=amd64] https://download.docker.com/linux/{{ ansible_distribution|lower }} {{ ansible_distribution_release }} stable"
      update_cache: no

  - name: Update all packages to their latest version
    apt:
      name: "*"
      state: latest

  # NOTE: Hit bug using apt pkg play: https://github.com/ansible/ansible/issues/69414
  #       Workaround is to use shell install of packages below
  #- name: Install docker-ce, docker-ce-cli, and containerd packages
  #  apt:
  #    pkg: 
  #    - docker-ce
  #    - docker-ce-cli
  #    - containerd.io
  - name: Install docker-ce
    shell: apt-get install -y docker-ce docker-ce-cli containerd.io
    args:
      warn: false # Ignore warning since this is a workaround to using apt pkg play
    become: true

  - name: Start and enable Docker daemon
    service:
      name: docker
      state: started
      enabled: yes

  - name: Pull CIL Core Docker Image
    shell: docker pull trueshura/cil-core-prod

  - name: Download helper scripts
    get_url:
      url: https://github.com/SilentNotaryEcosystem/Cil-core/releases/download/v0.7.0-staging/docker-scripts.tgz
      dest: /tmp
      mode: 0644

  - name: Untar helper scripts
    unarchive:
      src: /tmp/docker-scripts.tgz
      dest: /home/vagrant

  - name: Allow all access to port 8223
    ufw:
      rule: allow
      port: "8223"
      proto: any
Vornado10 commented 3 years ago

Hello, I am interested in running a masternode as I am a current ubx holder as well. The process for a non tech guy like myself does seem very intimidating from the instructions on the new website. I want to help and run one, but I don't want to screw anything up or do it wrong. If there is anyway to dumb it down even more, I'm in! Ha ha.

I will add, that I am going to start learning java from scratch this week, so I'm sure that will help.