Skip to content

Latest commit

 

History

History
188 lines (124 loc) · 5.61 KB

INSTALL.linux.rst

File metadata and controls

188 lines (124 loc) · 5.61 KB

Local development environment setup

This section describes how to setup development environment for Debian-based distributions (tested on Linux Mint 20.2 specifically)

Initial setup

Once initial setup is done only corresponding Update section should be performed to get the latest version for development.

  1. Install prerequisites ( as prescribed at https://github.com/pyenv/pyenv/wiki/Common-build-problems and some other):

    # TODO(dmu) MEDIUM: Remove dependencies that are not really needed
    # TODO(dmu) MEDIUM: These dependencies seem to be candidates for removal: tk-dev wget curl llvm
    sudo apt update && \
    apt install git make build-essential libssl-dev zlib1g-dev libbz2-dev \
                libreadline-dev libsqlite3-dev libncurses5-dev \
                libncursesw5-dev xz-utils libffi-dev liblzma-dev \
                python-openssl
    
  2. Install Docker according to https://docs.docker.com/engine/install/ (known working: Docker version 20.10.1, build 831ebea)

  3. Add your user to docker group:

    sudo usermod -aG docker $USER
    exit  # you may actually need to reboot for group membership to take effect
    
  4. Install Docker Compose according to https://docs.docker.com/compose/install/ (known working: docker-compose version 1.27.4, build 40524192)

  5. Clone the repository:

    git clone [email protected]:thenewboston-developers/Node.git
    
  6. [if you have not configured it globally] Configure git:

    git config user.name 'Firstname Lastname'
    git config user.email 'youremail@youremail_domain.com'
    
  7. Ensure you have Python 3.9.x installed and it will be used for running the project (you can do it with optional steps below)

  8. [Optional] Install Python 3.9.x with pyenv

    1. Install and configure pyenv according to https://github.com/pyenv/pyenv#basic-github-checkout

    2. Install Python 3.9.9:

      pyenv install 3.9.9
      pyenv local 3.9.9 # run from the root of this repo (`.python-version` file should appear)
      
  9. Install Poetry:

    export PIP_REQUIRED_VERSION=22.0.2
    pip install pip==${PIP_REQUIRED_VERSION} && \
    pip install virtualenvwrapper && \
    pip install poetry==1.1.12 && \
    poetry config virtualenvs.path ${HOME}/.virtualenvs && \
    poetry run pip install pip==${PIP_REQUIRED_VERSION}
    
  10. Setup local configuration for running code on host:

    mkdir -p local && \
    cp node/config/settings/templates/settings.dev.py ./local/settings.dev.py && \
    cp node/config/settings/templates/settings.unittests.py ./local/settings.unittests.py
    
    # Edit files if needed
    vim ./local/settings.dev.py
    vim ./local/settings.unittests.py
    
  11. Configure settings for running dockerized node:

    make dot-env
    
  12. Install dependencies, run migrations, etc by doing Update section steps

  13. Create superuser:

    make superuser
    

Update

  1. (in a separate terminal) Run dependency services:

    make up-dependencies-only
    
  2. Update:

    make update
    

Run quality assurance tools

  1. Lint:

    make lint
    
  2. Test:

    make test
    
  3. Lint then test:

    make lint-and-test
    

Run

  1. (in a separate terminal) Run only dependency services with Docker:

    make up-dependencies-only
    
  2. (in a separate terminal) Run node:

    # TODO(dmu) HIGH: We need to be able initialize blockchain with known signing keys for testing
    #                 https://thenewboston.atlassian.net/browse/BC-153
    make genesis
    make run-server
    
  3. [Optional] (in a separate terminal) Run another Node for testing and debugging communications between nodes:

    cp node/config/settings/templates/settings.dev.py ./local/settings.dev.node2.py
    # Add `DATABASES['default']['NAME'] = 'node2'` to ./local/settings.dev.node2.py
    export TNB_LOCAL_SETTINGS_PATH=./local/settings.dev.node2.py
    make migrate
    make superuser
    # TODO(dmu) LOW: Parametrize `make run-server` with port number and use it instead
    poetry run python -m node.manage runserver 127.0.0.1:8556
    
  4. [Optional] (in a separate terminal) Run Node for local development purposes with Docker

    make up-dev

Development tools

  1. Make migrations:

    make migrations
    

Run production Node

Common configuration

  1. Install Docker on target machine according to https://docs.docker.com/engine/install/ (known working: Docker version 20.10.7, build f0df350)

  2. Add your user to docker group:

    sudo usermod -aG docker $USER
    exit
    
  3. Install Docker Compose on target machine according to https://docs.docker.com/compose/install/ (known working: docker-compose version 1.29.2, build 5becea4c)

Manual deployment

  1. Prepare github personal access token aka PAT (not github password) - it will be needed to access the node docker image

  2. Run deploy.sh:

    bash <(wget -qO- https://raw.githubusercontent.com/thenewboston-developers/Node/master/scripts/deploy.sh)
    
  3. Add optional configuration:

    echo 'TNB_SENTRY_DSN=<replace with Sentry DSN>' >> .env
    

Configure continuous deployment

  1. Create deploy ssh key on target machine:

    # Use empty pass phrase
    ssh-keygen -f ~/.ssh/github
    cat ~/.ssh/github.pub >> ~/.ssh/authorized_keys
    
  2. Create github repository secrets:

    NODE_CONTINUOUS_DEPLOYMENT_ENABLED=True
    NODE_DEPLOY_SSH_KEY=<content of ~/.ssh/github>
    NODE_DEPLOY_SSH_HOST=<IP-address or domain name of target machine>
    NODE_DEPLOY_SSH_USER=<username that has the corresponding public in ~/authorized_keys>
    NODE_RUN_GENESIS=True  # change to False after first deploy or when needed